13 using T =
typename V::ValueType;
16 [[nodiscard]]
constexpr LineSegm() noexcept = default;
17 [[nodiscard]] constexpr
LineSegm( const V &
a, const V &
b ) noexcept :
a(
a ),
b(
b ) { }
21 [[nodiscard]] V
dir()
const {
return b -
a; }
25 [[nodiscard]]
T length()
const {
return dir().length(); }
27 [[nodiscard]] V
operator()(
T param )
const {
return ( 1 - param ) *
a + param *
b; }
33 return a.
a == b.
a && a.
b == b.
b;
40 auto dt = dot( pt - l.
a, ab );
41 auto abLengthSq = ab.lengthSq();
44 if ( dt >= abLengthSq )
46 auto ratio = dt / abLengthSq;
47 return l.
a * ( 1 - ratio ) + l.
b * ratio;
54 typename V::ValueType * xPos =
nullptr,
typename V::ValueType * yPos =
nullptr )
57 const auto xvec = x.
b - x.
a;
58 const auto ya = cross( xvec, y.
a - x.
a );
59 const auto yb = cross( xvec, y.
b - x.
a );
64 const auto yvec = y.
b - y.
a;
65 const auto xa = cross( yvec, x.
a - y.
a );
66 const auto xb = cross( yvec, x.
b - y.
a );
71 if ( cross( xvec, yvec ) == 0 )
76 if ( dot( xvec, y.
a - x.
a ) * dot( xvec, y.
b - x.
a ) > 0 &&
77 dot( -xvec, y.
a - x.
b ) * dot( -xvec, y.
b - x.
b ) > 0 )
80 else if ( yvec != V() )
82 if ( dot( yvec, x.
a - y.
a ) * dot( yvec, x.
b - y.
a ) > 0 &&
83 dot( -yvec, x.
a - y.
b ) * dot( -yvec, x.
b - y.
b ) > 0 )
86 else if ( x.
a != y.
a )
93 const auto denom = xa - xb;
94 *xPos = denom == 0 ? 0 : xa / denom;
99 const auto denom = ya - yb;
100 *yPos = denom == 0 ? 0 : ya / denom;
109 typename V::ValueType * xPos =
nullptr,
typename V::ValueType * yPos =
nullptr )
112 const auto xa = cross( y.
d, x.
a - y.
p );
113 const auto xb = cross( y.
d, x.
b - y.
p );
117 if ( ( xa <= 0 ) == ( xb <= 0 ) )
123 const auto denom = xa - xb;
124 *xPos = denom == 0 ? 0 : xa / denom;
129 const auto xvec = x.
b - x.
a;
130 const auto ya = cross( xvec, y.
p - x.
a );
131 const auto yb = cross( xvec, y.
p + y.
d - x.
a );
133 const auto denom = ya - yb;
134 *yPos = denom == 0 ? 0 : ya / denom;
139MR_BIND_TEMPLATE(
bool doSegmentsIntersect(
const LineSegm<Vector2<float>>& x,
const LineSegm<Vector2<float>>& y,
float* xPos,
float* yPos ) )
140MR_BIND_TEMPLATE(
bool doSegmentsIntersect(
const LineSegm<Vector2<double>>& x,
const LineSegm<Vector2<double>>& y,
double* xPos,
double* yPos ) )
142MR_BIND_TEMPLATE(
bool doSegmentLineIntersect(
const LineSegm<Vector2<float>>& x,
const Line<Vector2<float>>& y,
float* xPos,
float* yPos ) )
143MR_BIND_TEMPLATE(
bool doSegmentLineIntersect(
const LineSegm<Vector2<double>>& x,
const Line<Vector2<double>>& y,
double* xPos,
double* yPos ) )
MRMESH_API 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...
Definition MRCameraOrientationPlugin.h:8
V closestPointOnLineSegm(const V &pt, const LineSegm< V > &l)
Definition MRLineSegm.h:37
bool doSegmentLineIntersect(const LineSegm< V > &x, const Line< V > &y, typename V::ValueType *xPos=nullptr, typename V::ValueType *yPos=nullptr)
Definition MRLineSegm.h:108
bool doSegmentsIntersect(const LineSegm< V > &x, const LineSegm< V > &y, typename V::ValueType *xPos=nullptr, typename V::ValueType *yPos=nullptr)
Definition MRLineSegm.h:53
Definition MRLineSegm.h:12
constexpr LineSegm() noexcept=default
T length() const
returns the length of this line segment
Definition MRLineSegm.h:25
typename V::ValueType T
Definition MRLineSegm.h:13
V a
Definition MRLineSegm.h:14
constexpr LineSegm(const LineSegm< U > &p) noexcept
Definition MRLineSegm.h:19
T lengthSq() const
returns squared length of this line segment
Definition MRLineSegm.h:23
V operator()(T param) const
returns point on the line, where param=0 returns a and param=1 returns b
Definition MRLineSegm.h:27
V dir() const
returns directional vector of the line
Definition MRLineSegm.h:21
V b
Definition MRLineSegm.h:14
V d
Definition MRLine.h:16
V p
Definition MRLine.h:16