MeshLib
 
Loading...
Searching...
No Matches
MRSegmPoint.h
Go to the documentation of this file.
1#pragma once
2
3#include <limits>
4
5namespace MR
6{
7
10template <typename T>
12{
13 T a = 0;
14
15 static constexpr auto eps = 10 * std::numeric_limits<T>::epsilon();
16
17 SegmPoint() = default;
18 SegmPoint( T a ) : a( a ) { }
19 operator T() const { return a; }
20 operator T&() { return a; }
21
23 template <typename U>
24 [[nodiscard]] U interpolate( const U & v0, const U & v1 ) const
25 {
26 return ( 1 - a ) * v0 + a * v1;
27 }
28
30 [[nodiscard]] int inVertex() const
31 {
32 if ( a <= eps )
33 return 0;
34 if ( 1 - a <= eps )
35 return 1;
36 return -1;
37 }
38
40 [[nodiscard]] SegmPoint sym() const { return { 1 - a }; }
42 [[nodiscard]] bool operator==( const SegmPoint& rhs ) const = default;
43 [[nodiscard]] bool operator==( T rhs ) const { return a == rhs; }
44};
45
46} // namespace MR
Definition MRCameraOrientationPlugin.h:7
encodes a point inside a line segment using relative distance in [0,1]
Definition MRSegmPoint.h:12
static constexpr auto eps
Definition MRSegmPoint.h:15
int inVertex() const
returns [0,1] if the point is in a vertex or -1 otherwise
Definition MRSegmPoint.h:30
T a
a in [0,1], a=0 => point is in v0, a=1 => point is in v1
Definition MRSegmPoint.h:13
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:24
bool operator==(T rhs) const
Definition MRSegmPoint.h:43
SegmPoint(T a)
Definition MRSegmPoint.h:18
SegmPoint sym() const
represents the same point relative to oppositely directed segment
Definition MRSegmPoint.h:40
SegmPoint()=default