MeshLib C++ Docs
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{
11
12
15template <typename T>
17{
18 T a = 0;
19
20 static constexpr auto eps = 10 * std::numeric_limits<T>::epsilon();
21
22 SegmPoint() = default;
23 SegmPoint( T a ) : a( a ) { }
24 operator T() const { return a; }
25 operator T&() { return a; }
26
28 template <typename U>
29 [[nodiscard]] U interpolate( const U & v0, const U & v1 ) const
30 {
31 return ( 1 - a ) * v0 + a * v1;
32 }
33
35 [[nodiscard]] int inVertex() const
36 {
37 if ( a <= eps )
38 return 0;
39 if ( 1 - a <= eps )
40 return 1;
41 return -1;
42 }
43
45 [[nodiscard]] SegmPoint sym() const { return { 1 - a }; }
47 [[nodiscard]] bool operator==( const SegmPoint& rhs ) const = default;
48 [[nodiscard]] bool operator==( T rhs ) const { return a == rhs; }
49};
50
51}
static constexpr auto eps
Definition MRSegmPoint.h:20
int inVertex() const
returns [0,1] if the point is in a vertex or -1 otherwise
Definition MRSegmPoint.h:35
T a
a in [0,1], a=0 => point is in v0, a=1 => point is in v1
Definition MRSegmPoint.h:18
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:29
bool operator==(T rhs) const
Definition MRSegmPoint.h:48
SegmPoint(T a)
Definition MRSegmPoint.h:23
SegmPoint sym() const
represents the same point relative to oppositely directed segment
Definition MRSegmPoint.h:45
SegmPoint()=default
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
encodes a point inside a line segment using relative distance in [0,1]
Definition MRSegmPoint.h:17