16 using T =
typename V::ValueType;
19 [[nodiscard]]
constexpr LineSegm() noexcept = default;
20 [[nodiscard]] constexpr
LineSegm( const V &
a, const V &
b ) noexcept :
a(
a ),
b(
b ) { }
24 [[nodiscard]] V
dir()
const {
return b -
a; }
28 [[nodiscard]]
T length()
const {
return dir().length(); }
30 [[nodiscard]] V
operator()(
T param )
const {
return ( 1 - param ) *
a + param *
b; }
36 return a.
a == b.
a && a.
b == b.
b;
43 auto dt =
dot( pt - l.
a, ab );
44 auto abLengthSq = ab.lengthSq();
47 if ( dt >= abLengthSq )
49 auto ratio = dt / abLengthSq;
50 return l.
a * ( 1 - ratio ) + l.
b * ratio;
57 typename V::ValueType * xPos =
nullptr,
typename V::ValueType * yPos =
nullptr )
60 const auto xvec = x.
b - x.
a;
61 const auto ya =
cross( xvec, y.
a - x.
a );
62 const auto yb =
cross( xvec, y.
b - x.
a );
67 const auto yvec = y.
b - y.
a;
68 const auto xa =
cross( yvec, x.
a - y.
a );
69 const auto xb =
cross( yvec, x.
b - y.
a );
74 if (
cross( xvec, yvec ) == 0 )
79 if (
dot( xvec, y.
a - x.
a ) *
dot( xvec, y.
b - x.
a ) > 0 &&
80 dot( -xvec, y.
a - x.
b ) *
dot( -xvec, y.
b - x.
b ) > 0 )
83 else if ( yvec != V() )
85 if (
dot( yvec, x.
a - y.
a ) *
dot( yvec, x.
b - y.
a ) > 0 &&
86 dot( -yvec, x.
a - y.
b ) *
dot( -yvec, x.
b - y.
b ) > 0 )
89 else if ( x.
a != y.
a )
96 const auto denom = xa - xb;
97 *xPos = denom == 0 ? 0 : xa / denom;
102 const auto denom = ya - yb;
103 *yPos = denom == 0 ? 0 : ya / denom;
112 typename V::ValueType * xPos =
nullptr,
typename V::ValueType * yPos =
nullptr )
115 const auto xa =
cross( y.
d, x.
a - y.
p );
116 const auto xb =
cross( y.
d, x.
b - y.
p );
120 if ( ( xa <= 0 ) == ( xb <= 0 ) )
126 const auto denom = xa - xb;
127 *xPos = denom == 0 ? 0 : xa / denom;
132 const auto xvec = x.
b - x.
a;
133 const auto ya =
cross( xvec, y.
p - x.
a );
134 const auto yb =
cross( xvec, y.
p + y.
d - x.
a );
136 const auto denom = ya - yb;
137 *yPos = denom == 0 ? 0 : ya / denom;
bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
constexpr LineSegm() noexcept=default
T length() const
returns the length of this line segment
Definition MRLineSegm.h:28
typename V::ValueType T
Definition MRLineSegm.h:16
V closestPointOnLineSegm(const V &pt, const LineSegm< V > &l)
Definition MRLineSegm.h:40
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:142
Vector3< T > a
Definition MRLineSegm.h:17
constexpr LineSegm(const LineSegm< U > &p) noexcept
Definition MRLineSegm.h:22
Line
Definition MRMeshFwd.h:337
LineSegm
Definition MRMeshFwd.h:346
MRMESH_CLASS Vector2
Definition MRMeshFwd.h:204
V d
Definition MRLine.h:19
T lengthSq() const
returns squared length of this line segment
Definition MRLineSegm.h:26
V operator()(T param) const
returns point on the line, where param=0 returns a and param=1 returns b
Definition MRLineSegm.h:30
bool doSegmentLineIntersect(const LineSegm< V > &x, const Line< V > &y, typename V::ValueType *xPos=nullptr, typename V::ValueType *yPos=nullptr)
Definition MRLineSegm.h:111
bool doSegmentsIntersect(const LineSegm< V > &x, const LineSegm< V > &y, typename V::ValueType *xPos=nullptr, typename V::ValueType *yPos=nullptr)
Definition MRLineSegm.h:56
V dir() const
returns directional vector of the line
Definition MRLineSegm.h:24
V p
Definition MRLine.h:19
Vector3< T > b
Definition MRLineSegm.h:17
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
a segment of straight dimensional line
Definition MRLineSegm.h:15
T cross(const Vector2< T > &a, const Vector2< T > &b)
cross product
Definition MRVector2.h:160