33 #include <type_traits> 45 friend inline std::ostream&
operator<<( std::ostream& aStream,
const SEG& aSeg );
63 SEG(
int aX1,
int aY1,
int aX2,
int aY2 ) :
115 return (
A == aSeg.
A &&
B == aSeg.
B) ;
120 return (
A != aSeg.
A ||
B != aSeg.
B);
145 const ecoord det = (
B -
A ).Cross( aP -
A );
147 return det < 0 ? -1 : ( det > 0 ? 1 : 0 );
185 bool aLines =
false )
const;
214 bool Collide(
const SEG& aSeg,
int aClearance,
int* aActual =
nullptr )
const;
231 return (
NearestPoint( aP ) - aP ).SquaredEuclideanNorm();
249 qC = -qA *
A.x - qB *
A.y;
263 ecoord d1 = std::abs( aSeg.
A.
x * qa + aSeg.
A.
y * qb + qc );
264 ecoord d2 = std::abs( aSeg.
B.
x * qa + aSeg.
B.
y * qb + qc );
266 return ( d1 <= 1 && d2 <= 1 );
274 ecoord dist1 = ( p * aSeg.
A.
x + q * aSeg.
A.
y + r ) / sqrt( p * p + q * q );
275 ecoord dist2 = ( p * aSeg.
B.
x + q * aSeg.
B.
y + r ) / sqrt( p * p + q * q );
277 return std::abs( dist1 ) <= 1 && std::abs( dist2 ) <= 1;
285 ecoord dist1 = ( p * aSeg.
A.
x + q * aSeg.
A.
y + r ) / sqrt( p * p + q * q );
286 ecoord dist2 = ( p * aSeg.
B.
x + q * aSeg.
B.
y + r ) / sqrt( p * p + q * q );
288 return std::abs( dist1 - dist2 ) <= 1;
300 if( aSeg.
A == aSeg.
B )
302 if(
A == aSeg.
A ||
B == aSeg.
A )
323 if( aSeg.
A == aSeg.
B )
342 return (
A -
B ).EuclideanNorm();
347 return (
A -
B ).SquaredEuclideanNorm();
378 return A + (
B -
A ) / 2;
411 ecoord dist = ( p * aP.
x + q * aP.
y + r ) / sqrt( p * p + q * q );
413 return aDetermineSide ? dist : std::abs( dist );
419 return d.
Dot( aP -
A);
434 else if( t > l_squared )
445 aStream <<
"[ " << aSeg.
A <<
" - " << aSeg.
B <<
" ]";
int Length() const
Return the length (this).
VECTOR2_TRAITS< T >::extended_type extended_type
int Index() const
Return the index of this segment in its parent shape (applicable only to non-local segments).
bool Overlaps(const SEG &aSeg) const
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
ecoord SquaredLength() const
bool ApproxPerpendicular(const SEG &aSeg) const
SEG PerpendicularSeg(const VECTOR2I &aP) const
Compute a segment perpendicular to this one, passing through point aP.
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
SEG()
Create an empty (0, 0) segment.
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
bool Collide(const SEG &aSeg, int aClearance, int *aActual=nullptr) const
std::ostream & operator<<(std::ostream &aStream, const SEG &aSeg)
VECTOR2I::extended_type ecoord
bool operator!=(const SEG &aSeg) const
ecoord SquaredDistance(const SEG &aSeg) const
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
int LineDistance(const VECTOR2I &aP, bool aDetermineSide=false) const
Return the closest Euclidean distance between point aP and the line defined by the ends of segment (t...
friend std::ostream & operator<<(std::ostream &aStream, const SEG &aSeg)
static SEG::ecoord Square(int a)
SEG ParallelSeg(const VECTOR2I &aP) const
Compute a segment parallel to this one, passing through point aP.
SEG & operator=(const SEG &aSeg)
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
ecoord TCoef(const VECTOR2I &aP) const
OPT< VECTOR2I > OPT_VECTOR2I
bool ApproxParallel(const SEG &aSeg) const
VECTOR2I::extended_type ecoord
SEG(const VECTOR2I &aA, const VECTOR2I &aB)
Create a segment between (aA) and (aB).
SEG(int aX1, int aY1, int aX2, int aY2)
Create a segment between (aX1, aY1) and (aX2, aY2).
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
bool ApproxCollinear(const SEG &aSeg) const
SEG(const SEG &aSeg)
Copy constructor.
int Distance(const VECTOR2I &aP) const
Compute minimum Euclidean distance to point aP.
SEG Reversed() const
Returns the center point of the line.
bool Collinear(const SEG &aSeg) const
Check if segment aSeg lies on the same line as (this).
bool operator==(const SEG &aSeg) const
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
ecoord SquaredDistance(const VECTOR2I &aP) const
int m_index
< index withing the parent shape (used when m_is_local == false)
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
SEG(const VECTOR2I &aA, const VECTOR2I &aB, int aIndex)
Create a segment between (aA) and (aB), referenced to a multi-segment shape.
int Side(const VECTOR2I &aP) const
Determine on which side of directed line passing via segment ends point aP lies.
bool Contains(const SEG &aSeg) const