MeshLib Documentation
Loading...
Searching...
No Matches
MRSegmPoint.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4
5#include <limits>
6
7namespace MR
8{
9
12template <typename T>
14{
15 T a = 0;
16
17 static constexpr auto eps = 10 * std::numeric_limits<T>::epsilon();
18
19 SegmPoint() = default;
20 SegmPoint( T a ) : a( a ) { }
21 operator T() const { return a; }
22 operator T&() { return a; }
23
25 template <typename U>
26 [[nodiscard]] U interpolate( const U & v0, const U & v1 ) const
27 {
28 return ( 1 - a ) * v0 + a * v1;
29 }
30
32 [[nodiscard]] int inVertex() const
33 {
34 if ( a <= eps )
35 return 0;
36 if ( 1 - a <= eps )
37 return 1;
38 return -1;
39 }
40
42 [[nodiscard]] SegmPoint sym() const { return { 1 - a }; }
44 [[nodiscard]] bool operator==( const SegmPoint& rhs ) const = default;
45 [[nodiscard]] bool operator==( T rhs ) const { return a == rhs; }
46};
47
48} // namespace MR
Definition MRCameraOrientationPlugin.h:8
encodes a point inside a line segment using relative distance in [0,1]
Definition MRSegmPoint.h:14
static constexpr auto eps
Definition MRSegmPoint.h:17
int inVertex() const
returns [0,1] if the point is in a vertex or -1 otherwise
Definition MRSegmPoint.h:32
T a
a in [0,1], a=0 => point is in v0, a=1 => point is in v1
Definition MRSegmPoint.h:15
bool operator==(const SegmPoint &rhs) const =default
returns true if two points have equal (a) representation
U interpolate(const U &v0, const U &v1) const
given values in two vertices, computes interpolated value at this point
Definition MRSegmPoint.h:26
bool operator==(T rhs) const
Definition MRSegmPoint.h:45
SegmPoint(T a)
Definition MRSegmPoint.h:20
SegmPoint sym() const
represents the same point relative to oppositely directed segment
Definition MRSegmPoint.h:42
SegmPoint()=default