Searching...
No Matches
SEG Class Reference

`#include <seg.h>`

Public Types

using ecoord = VECTOR2I::extended_type

Public Member Functions

SEG ()
Create an empty (0, 0) segment.

SEG (int aX1, int aY1, int aX2, int aY2)
Create a segment between (aX1, aY1) and (aX2, aY2).

SEG (const VECTOR2I &aA, const VECTOR2I &aB)
Create a segment between (aA) and (aB).

SEG (const VECTOR2I &aA, const VECTOR2I &aB, int aIndex)
Create a segment between (aA) and (aB), referenced to a multi-segment shape.

SEG (const SEG &aSeg)
Copy constructor.

SEGoperator= (const SEG &aSeg)

bool operator== (const SEG &aSeg) const

bool operator!= (const SEG &aSeg) const

VECTOR2I LineProject (const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.

int Side (const VECTOR2I &aP) const
Determine on which side of directed line passing via segment ends point aP lies.

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 (this).

EDA_ANGLE Angle (const SEG &aOther) const
Determine the smallest angle between two segments.

const VECTOR2I NearestPoint (const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.

const VECTOR2I NearestPoint (const SEG &aSeg) const
Compute a point on the segment (this) that is closest to any point on aSeg.

bool NearestPoints (const SEG &aSeg, VECTOR2I &aPtA, VECTOR2I &aPtB, int64_t &aDistSq) const
Compute closest points between this segment and aSeg.

const VECTOR2I ReflectPoint (const VECTOR2I &aP) const
Reflect a point using this segment as axis.

OPT_VECTOR2I Intersect (const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.

bool Intersects (const SEG &aSeg) const

OPT_VECTOR2I IntersectLines (const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.

SEG PerpendicularSeg (const VECTOR2I &aP) const
Compute a segment perpendicular to this one, passing through point aP.

SEG ParallelSeg (const VECTOR2I &aP) const
Compute a segment parallel to this one, passing through point aP.

bool Collide (const SEG &aSeg, int aClearance, int *aActual=nullptr) const

ecoord SquaredDistance (const SEG &aSeg) const

int Distance (const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.

ecoord SquaredDistance (const VECTOR2I &aP) const

int Distance (const VECTOR2I &aP) const
Compute minimum Euclidean distance to point aP.

void CanonicalCoefs (ecoord &qA, ecoord &qB, ecoord &qC) const

bool Collinear (const SEG &aSeg) const
Check if segment aSeg lies on the same line as (this).

bool ApproxCollinear (const SEG &aSeg, int aDistanceThreshold=1) const

bool ApproxParallel (const SEG &aSeg, int aDistanceThreshold=1) const

bool ApproxPerpendicular (const SEG &aSeg) const

bool Overlaps (const SEG &aSeg) const

bool Contains (const SEG &aSeg) const

int Length () const
Return the length (this).

ecoord SquaredLength () const

ecoord TCoef (const VECTOR2I &aP) const

int Index () const
Return the index of this segment in its parent shape (applicable only to non-local segments).

bool Contains (const VECTOR2I &aP) const

void Reverse ()

SEG Reversed () const
Returns the center point of the line.

VECTOR2I Center () const

bool operator< (const SEG &aSeg) const

Static Public Member Functions

static SEG::ecoord Square (int a)

VECTOR2I A

VECTOR2I B

Private Member Functions

bool ccw (const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const

bool intersects (const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false, VECTOR2I *aPt=nullptr) const

Private Attributes

int m_index
< index within the parent shape (used when m_is_local == false)

Friends

std::ostream & operator<< (std::ostream &aStream, const SEG &aSeg)

Detailed Description

Definition at line 41 of file seg.h.

◆ ecoord

 using SEG::ecoord = VECTOR2I::extended_type

Definition at line 44 of file seg.h.

◆ SEG() [1/5]

 SEG::SEG ( )
inline

Create an empty (0, 0) segment.

Definition at line 55 of file seg.h.

References m_index.

Referenced by ParallelSeg(), PerpendicularSeg(), and Reversed().

◆ SEG() [2/5]

 SEG::SEG ( int aX1, int aY1, int aX2, int aY2 )
inline

Create a segment between (aX1, aY1) and (aX2, aY2).

Definition at line 63 of file seg.h.

References m_index.

◆ SEG() [3/5]

 SEG::SEG ( const VECTOR2I & aA, const VECTOR2I & aB )
inline

Create a segment between (aA) and (aB).

Definition at line 73 of file seg.h.

References m_index.

◆ SEG() [4/5]

 SEG::SEG ( const VECTOR2I & aA, const VECTOR2I & aB, int aIndex )
inline

Create a segment between (aA) and (aB), referenced to a multi-segment shape.

Parameters
 aA reference to the start point in the parent shape aB reference to the end point in the parent shape aIndex index of the segment within the parent shape

Definition at line 87 of file seg.h.

References m_index.

◆ SEG() [5/5]

 SEG::SEG ( const SEG & aSeg )
inline

Copy constructor.

Definition at line 97 of file seg.h.

◆ Angle()

 EDA_ANGLE SEG::Angle ( const SEG & aOther ) const

Determine the smallest angle between two segments.

Parameters
 aOther point to determine the orientation wrs to self
Returns
smallest angle between this and aOther

Definition at line 97 of file seg.cpp.

References A, std::abs(), ANGLE_180, B, and EDA_ANGLE::Normalize180().

◆ ApproxCollinear()

 bool SEG::ApproxCollinear ( const SEG & aSeg, int aDistanceThreshold = `1` ) const

Definition at line 468 of file seg.cpp.

References std::abs(), mutualDistanceSquared(), and Square().

Referenced by PCB_TRACK::ApproxCollinear(), and EDIT_TOOL::FilletTracks().

◆ ApproxParallel()

 bool SEG::ApproxParallel ( const SEG & aSeg, int aDistanceThreshold = `1` ) const

◆ ApproxPerpendicular()

 bool SEG::ApproxPerpendicular ( const SEG & aSeg ) const

Definition at line 492 of file seg.cpp.

References ApproxParallel(), and PerpendicularSeg().

Referenced by SegPerpendicularCorrect().

◆ CanonicalCoefs()

 void SEG::CanonicalCoefs ( ecoord & qA, ecoord & qB, ecoord & qC ) const
inline

Definition at line 263 of file seg.h.

Referenced by Collinear().

◆ ccw()

 bool SEG::ccw ( const VECTOR2I & aA, const VECTOR2I & aB, const VECTOR2I & aC ) const
private

Definition at line 283 of file seg.cpp.

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Collide().

◆ Center()

 VECTOR2I SEG::Center ( ) const
inline

Definition at line 369 of file seg.h.

References A.

◆ Collide()

 bool SEG::Collide ( const SEG & aSeg, int aClearance, int * aActual = `nullptr` ) const

Definition at line 289 of file seg.cpp.

References A, B, ccw(), VECTOR2< int32_t >::ECOORD_MAX, isqrt(), and SquaredDistance().

◆ Collinear()

 bool SEG::Collinear ( const SEG & aSeg ) const
inline

Check if segment aSeg lies on the same line as (this).

Parameters
 aSeg the segment to check colinearity with
Returns
true, when segments are collinear.

Definition at line 276 of file seg.h.

References A, std::abs(), B, CanonicalCoefs(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ Contains() [1/2]

 bool SEG::Contains ( const SEG & aSeg ) const
inline

◆ Contains() [2/2]

 bool SEG::Contains ( const VECTOR2I & aP ) const

Definition at line 321 of file seg.cpp.

References Distance().

◆ Distance() [1/2]

 int SEG::Distance ( const SEG & aSeg ) const

Compute minimum Euclidean distance to segment aSeg.

Parameters
 aSeg other segment
Returns
minimum distance

Definition at line 388 of file seg.cpp.

References isqrt(), and SquaredDistance().

◆ Distance() [2/2]

 int SEG::Distance ( const VECTOR2I & aP ) const

Compute minimum Euclidean distance to point aP.

Parameters
 aP the point
Returns
minimum distance

Definition at line 394 of file seg.cpp.

References isqrt(), and SquaredDistance().

◆ Index()

 int SEG::Index ( ) const
inline

Return the index of this segment in its parent shape (applicable only to non-local segments).

Returns
index value

Definition at line 351 of file seg.h.

References m_index.

◆ Intersect()

 OPT_VECTOR2I SEG::Intersect ( const SEG & aSeg, bool aIgnoreEndpoints = `false`, bool aLines = `false` ) const

Compute intersection point of segment (this) with segment aSeg.

Parameters
 aSeg segment to intersect with aIgnoreEndpoints don't treat corner cases (i.e. end of one segment touching the other) as intersections. aLines treat segments as infinite lines
Returns
intersection point, if exists

Definition at line 254 of file seg.cpp.

References intersects().

◆ IntersectLines()

 OPT_VECTOR2I SEG::IntersectLines ( const SEG & aSeg ) const
inline

Compute the intersection point of lines passing through ends of (this) and aSeg.

Parameters
 aSeg segment defining the line to intersect with
Returns
intersection point, if exists

Definition at line 220 of file seg.h.

References Intersect().

◆ Intersects()

 bool SEG::Intersects ( const SEG & aSeg ) const

Definition at line 248 of file seg.cpp.

References intersects().

Referenced by ConnectBoardShapes(), LINE_EXTENSION_ROUTINE::ProcessLinePair(), and SquaredDistance().

◆ intersects()

 bool SEG::intersects ( const SEG & aSeg, bool aIgnoreEndpoints = `false`, bool aLines = `false`, VECTOR2I * aPt = `nullptr` ) const
private

Definition at line 208 of file seg.cpp.

References A, B, VECTOR2< T >::Cross(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Intersect(), and Intersects().

◆ LineDistance()

 int SEG::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 (this).

Parameters
 aP the point to test aDetermineSide when true, the sign of the returned value indicates the side of the line at which we are (negative = left)
Returns
the distance

Definition at line 419 of file seg.cpp.

References std::abs(), isqrt(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ LineProject()

 VECTOR2I SEG::LineProject ( const VECTOR2I & aP ) const

Compute the perpendicular projection point of aP on a line passing through ends of the segment.

Parameters
 aP point to project
Returns
projected point

Definition at line 371 of file seg.cpp.

References A, VECTOR2< T >::Dot(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ mutualDistanceSquared()

 bool SEG::mutualDistanceSquared ( const SEG & aSeg, ecoord & aD1, ecoord & aD2 ) const
private

Definition at line 439 of file seg.cpp.

References A, B, rescale(), sgn(), SquaredLength(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by ApproxCollinear(), and ApproxParallel().

◆ NearestPoint() [1/2]

 const VECTOR2I SEG::NearestPoint ( const SEG & aSeg ) const

Compute a point on the segment (this) that is closest to any point on aSeg.

Returns
the nearest point

Definition at line 108 of file seg.cpp.

References A, B, Intersect(), and NearestPoint().

◆ NearestPoint() [2/2]

 const VECTOR2I SEG::NearestPoint ( const VECTOR2I & aP ) const

Compute a point on the segment (this) that is closest to point aP.

Returns
the nearest point

Definition at line 327 of file seg.cpp.

References A, B, VECTOR2< T >::Dot(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ NearestPoints()

 bool SEG::NearestPoints ( const SEG & aSeg, VECTOR2I & aPtA, VECTOR2I & aPtB, int64_t & aDistSq ) const

Compute closest points between this segment and aSeg.

Parameters
 aPtA point on this segment (output) aPtB point on the other segment (output) aDistSq squared distance between points (output)
Returns
true if the operation was successful

Definition at line 150 of file seg.cpp.

References A, B, Intersect(), and NearestPoint().

Referenced by SHAPE_LINE_CHAIN::ClosestSegments().

◆ operator!=()

 bool SEG::operator!= ( const SEG & aSeg ) const
inline

Definition at line 118 of file seg.h.

References A, and B.

◆ operator<()

 bool SEG::operator< ( const SEG & aSeg ) const
inline

Definition at line 374 of file seg.h.

References A, and B.

◆ operator=()

 SEG & SEG::operator= ( const SEG & aSeg )
inline

Definition at line 104 of file seg.h.

References A, B, and m_index.

◆ operator==()

 bool SEG::operator== ( const SEG & aSeg ) const
inline

Definition at line 113 of file seg.h.

References A, and B.

◆ Overlaps()

 bool SEG::Overlaps ( const SEG & aSeg ) const
inline

Definition at line 291 of file seg.h.

References A, B, Collinear(), and Contains().

◆ ParallelSeg()

 SEG SEG::ParallelSeg ( const VECTOR2I & aP ) const

Compute a segment parallel to this one, passing through point aP.

Parameters
 aP Point through which the new segment will pass
Returns
SEG parallel to this passing through point aP

Definition at line 274 of file seg.cpp.

References SEG().

Referenced by BOOST_AUTO_TEST_CASE(), and CIRCLE::ConstructFromTanTanPt().

◆ PerpendicularSeg()

 SEG SEG::PerpendicularSeg ( const VECTOR2I & aP ) const

Compute a segment perpendicular to this one, passing through point aP.

Parameters
 aP Point through which the new segment will pass
Returns
SEG perpendicular to this passing through point aP

Definition at line 265 of file seg.cpp.

References VECTOR2< T >::Perpendicular(), and SEG().

◆ ReflectPoint()

 const VECTOR2I SEG::ReflectPoint ( const VECTOR2I & aP ) const

Reflect a point using this segment as axis.

Returns
the reflected point

Definition at line 350 of file seg.cpp.

References A, VECTOR2< T >::Dot(), rescale(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CornerListToPolygon(), SHAPE_ARC::Mirror(), and SHAPE_LINE_CHAIN::Mirror().

◆ Reverse()

 void SEG::Reverse ( )
inline

Definition at line 358 of file seg.h.

◆ Reversed()

 SEG SEG::Reversed ( ) const
inline

Returns the center point of the line.

Definition at line 363 of file seg.h.

References SEG().

Referenced by PNS::LINE_PLACER::Start().

◆ Side()

 int SEG::Side ( const VECTOR2I & aP ) const
inline

Determine on which side of directed line passing via segment ends point aP lies.

Parameters
 aP point to determine the orientation wrs to self
Returns
: < 0: left, 0 : on the line, > 0 : right

Definition at line 143 of file seg.h.

References A.

◆ SquaredDistance() [1/2]

 SEG::ecoord SEG::SquaredDistance ( const SEG & aSeg ) const

◆ SquaredDistance() [2/2]

 SEG::ecoord SEG::SquaredDistance ( const VECTOR2I & aP ) const

Definition at line 400 of file seg.cpp.

◆ SquaredLength()

 ecoord SEG::SquaredLength ( ) const
inline

◆ TCoef()

 SEG::ecoord SEG::TCoef ( const VECTOR2I & aP ) const
inline

Definition at line 395 of file seg.h.

References A, and VECTOR2< T >::Dot().

Referenced by commonParallelProjection(), and PNS::commonParallelProjection().

◆ operator<<

 std::ostream & operator<< ( std::ostream & aStream, const SEG & aSeg )
friend

Definition at line 401 of file seg.h.

◆ m_index

 int SEG::m_index
private

< index within the parent shape (used when m_is_local == false)

Definition at line 392 of file seg.h.

Referenced by Index(), operator=(), and SEG().

The documentation for this class was generated from the following files: