KiCad PCB EDA Suite
SEG Class Reference

#include <seg.h>

Public Types

using ecoord = VECTOR2I::extended_type
 

Public Member Functions

 SEG ()
 Default constructor Creates an empty (0, 0) segment. More...
 
 SEG (int aX1, int aY1, int aX2, int aY2)
 Constructor Creates a segment between (aX1, aY1) and (aX2, aY2) More...
 
 SEG (const VECTOR2I &aA, const VECTOR2I &aB)
 Constructor Creates a segment between (aA) and (aB) More...
 
 SEG (const VECTOR2I &aA, const VECTOR2I &aB, int aIndex)
 Constructor Creates a segment between (aA) and (aB), referenced to a multi-segment shape. More...
 
 SEG (const SEG &aSeg)
 Copy constructor. More...
 
SEGoperator= (const SEG &aSeg)
 
bool operator== (const SEG &aSeg) const
 
bool operator!= (const SEG &aSeg) const
 
VECTOR2I LineProject (const VECTOR2I &aP) const
 Function LineProject() More...
 
int Side (const VECTOR2I &aP) const
 Function Side() More...
 
int LineDistance (const VECTOR2I &aP, bool aDetermineSide=false) const
 Function LineDistance() More...
 
const VECTOR2I NearestPoint (const VECTOR2I &aP) const
 Function NearestPoint() More...
 
const VECTOR2I NearestPoint (const SEG &aSeg) const
 Computes a point on the segment (this) that is closest to any point on aSeg. More...
 
OPT_VECTOR2I Intersect (const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
 Function Intersect() More...
 
OPT_VECTOR2I IntersectLines (const SEG &aSeg) const
 Function IntersectLines() More...
 
bool Collide (const SEG &aSeg, int aClearance, int *aActual=nullptr) const
 
ecoord SquaredDistance (const SEG &aSeg) const
 
int Distance (const SEG &aSeg) const
 Function Distance() More...
 
ecoord SquaredDistance (const VECTOR2I &aP) const
 
int Distance (const VECTOR2I &aP) const
 Function Distance() More...
 
void CanonicalCoefs (ecoord &qA, ecoord &qB, ecoord &qC) const
 
bool Collinear (const SEG &aSeg) const
 Function Collinear() More...
 
bool ApproxCollinear (const SEG &aSeg) const
 
bool ApproxParallel (const SEG &aSeg) const
 
bool Overlaps (const SEG &aSeg) const
 
bool Contains (const SEG &aSeg) const
 
int Length () const
 Function Length() More...
 
ecoord SquaredLength () const
 
ecoord TCoef (const VECTOR2I &aP) const
 
int Index () const
 Function Index() More...
 
bool Contains (const VECTOR2I &aP) const
 
void Reverse ()
 
VECTOR2I Center () const
 

Returns the center point of the line

More...
 

Static Public Member Functions

static SEG::ecoord Square (int a)
 

Public Attributes

VECTOR2I A
 
VECTOR2I B
 

Private Member Functions

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

Private Attributes

int m_index
 

index withing the parent shape (used when m_is_local == false)

More...
 

Friends

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

Detailed Description

Definition at line 39 of file seg.h.

Member Typedef Documentation

◆ ecoord

Definition at line 42 of file seg.h.

Constructor & Destructor Documentation

◆ SEG() [1/5]

SEG::SEG ( )
inline

Default constructor Creates an empty (0, 0) segment.

Definition at line 53 of file seg.h.

54  {
55  m_index = -1;
56  }
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359

References m_index.

◆ SEG() [2/5]

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

Constructor Creates a segment between (aX1, aY1) and (aX2, aY2)

Definition at line 62 of file seg.h.

62  :
63  A ( VECTOR2I( aX1, aY1 ) ),
64  B ( VECTOR2I( aX2, aY2 ) )
65  {
66  m_index = -1;
67  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359
VECTOR2I B
Definition: seg.h:48

References m_index.

◆ SEG() [3/5]

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

Constructor Creates a segment between (aA) and (aB)

Definition at line 73 of file seg.h.

73  : A( aA ), B( aB )
74  {
75  m_index = -1;
76  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359
VECTOR2I B
Definition: seg.h:48

References m_index.

◆ SEG() [4/5]

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

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

Parameters
aAreference to the start point in the parent shape
aBreference to the end point in the parent shape
aIndexindex of the segment within the parent shape

Definition at line 85 of file seg.h.

85  : A( aA ), B( aB )
86  {
87  m_index = aIndex;
88  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359
VECTOR2I B
Definition: seg.h:48

References m_index.

◆ SEG() [5/5]

SEG::SEG ( const SEG aSeg)
inline

Copy constructor.

Definition at line 93 of file seg.h.

93  : A( aSeg.A ), B( aSeg.B ), m_index( aSeg.m_index )
94  {
95  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359
VECTOR2I B
Definition: seg.h:48

Member Function Documentation

◆ ApproxCollinear()

bool SEG::ApproxCollinear ( const SEG aSeg) const
inline

Definition at line 254 of file seg.h.

255  {
256  ecoord p, q, r;
257  CanonicalCoefs( p, q, r );
258 
259  ecoord dist1 = ( p * aSeg.A.x + q * aSeg.A.y + r ) / sqrt( p * p + q * q );
260  ecoord dist2 = ( p * aSeg.B.x + q * aSeg.B.y + r ) / sqrt( p * p + q * q );
261 
262  return std::abs( dist1 ) <= 1 && std::abs( dist2 ) <= 1;
263  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:229
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

Referenced by TRACK::ApproxCollinear().

◆ ApproxParallel()

bool SEG::ApproxParallel ( const SEG aSeg) const
inline

Definition at line 265 of file seg.h.

266  {
267  ecoord p, q, r;
268  CanonicalCoefs( p, q, r );
269 
270  ecoord dist1 = ( p * aSeg.A.x + q * aSeg.A.y + r ) / sqrt( p * p + q * q );
271  ecoord dist2 = ( p * aSeg.B.x + q * aSeg.B.y + r ) / sqrt( p * p + q * q );
272 
273  return std::abs( dist1 - dist2 ) <= 1;
274  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:229
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

Referenced by PNS::MEANDERED_LINE::CheckSelfIntersections(), PNS::DIFF_PAIR::CoupledLength(), PNS::DIFF_PAIR::CoupledSegmentPairs(), and PNS::findCoupledVertices().

◆ CanonicalCoefs()

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

Definition at line 229 of file seg.h.

230  {
231  qA = A.y - B.y;
232  qB = B.x - A.x;
233  qC = -qA * A.x - qB * A.y;
234  }

Referenced by ApproxCollinear(), ApproxParallel(), and Collinear().

◆ ccw()

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

Definition at line 122 of file seg.cpp.

123 {
124  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) > (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
125 }
VECTOR2I::extended_type ecoord
Definition: seg.h:42
VECTOR2I::extended_type ecoord

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

Referenced by Collide().

◆ Center()

VECTOR2I SEG::Center ( ) const
inline

Returns the center point of the line

Definition at line 350 of file seg.h.

351  {
352  return A + ( B - A ) / 2;
353  }
VECTOR2I A
Definition: seg.h:47

References A.

Referenced by SCH_EAGLE_PLUGIN::findNearestLinePoint().

◆ Collide()

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

Definition at line 128 of file seg.cpp.

129 {
130  // check for intersection
131  // fixme: move to a method
132  if( ccw( A, aSeg.A, aSeg.B ) != ccw( B, aSeg.A, aSeg.B ) &&
133  ccw( A, B, aSeg.A ) != ccw( A, B, aSeg.B ) )
134  {
135  if( aActual )
136  *aActual = 0;
137 
138  return true;
139  }
140 
141  ecoord dist_sq = VECTOR2I::ECOORD_MAX;
142 
143  dist_sq = std::min( dist_sq, SquaredDistance( aSeg.A ) );
144  dist_sq = std::min( dist_sq, SquaredDistance( aSeg.B ) );
145  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( A ) );
146  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( B ) );
147 
148  if( dist_sq == 0 || dist_sq < (ecoord) aClearance * aClearance )
149  {
150  if( aActual )
151  *aActual = sqrt( dist_sq );
152 
153  return true;
154  }
155 
156  return false;
157 }
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: seg.cpp:122
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

Referenced by SHAPE_POLY_SET::IsPolygonSelfIntersecting(), SegCollideCorrect(), and BOARD::TestAreaIntersection().

◆ Collinear()

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

Function Collinear()

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

Parameters
aSegthe segment to chech colinearity with
Returns
true, when segments are collinear.

Definition at line 243 of file seg.h.

244  {
245  ecoord qa, qb, qc;
246  CanonicalCoefs( qa, qb, qc );
247 
248  ecoord d1 = std::abs( aSeg.A.x * qa + aSeg.A.y * qb + qc );
249  ecoord d2 = std::abs( aSeg.B.x * qa + aSeg.B.y * qb + qc );
250 
251  return ( d1 <= 1 && d2 <= 1 );
252  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:229
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

Referenced by PNS::DP_GATEWAYS::BuildGeneric(), Contains(), SHAPE_LINE_CHAIN::Intersect(), Overlaps(), and SegCollinearCorrect().

◆ Contains() [1/2]

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

Definition at line 299 of file seg.h.

300  {
301  if( aSeg.A == aSeg.B ) // single point corner case
302  return Contains( aSeg.A );
303 
304  if( !Collinear( aSeg ) )
305  return false;
306 
307  if( Contains( aSeg.A ) && Contains( aSeg.B ) )
308  return true;
309 
310  return false;
311  }
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:243
VECTOR2I A
Definition: seg.h:47
bool Contains(const SEG &aSeg) const
Definition: seg.h:299
VECTOR2I B
Definition: seg.h:48

References A, B, and Collinear().

Referenced by GRID_HELPER::AlignToSegment(), EE_GRID_HELPER::AlignToWire(), PNS::LINE::ChangedArea(), SHAPE_LINE_CHAIN::Intersect(), PNS::MEANDERED_LINE::MeanderSegment(), Overlaps(), and PNS::LINE::Walkaround().

◆ Contains() [2/2]

bool SEG::Contains ( const VECTOR2I aP) const

Definition at line 160 of file seg.cpp.

161 {
162  return SquaredDistance( aP ) < 1; // 1 * 1 to be pedantic
163 }
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37

References SquaredDistance().

◆ Distance() [1/2]

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

◆ Distance() [2/2]

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

Function Distance()

Computes minimum Euclidean distance to point aP.

Parameters
aPthe point
Returns
minimum distance

Definition at line 224 of file seg.h.

225  {
226  return sqrt( SquaredDistance( aP ) );
227  }
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37

References SquaredDistance().

◆ Index()

int SEG::Index ( ) const
inline

Function Index()

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

Returns
index value

Definition at line 337 of file seg.h.

338  {
339  return m_index;
340  }
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359

References m_index.

Referenced by addIntersection(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), and PNS::LINE::Walkaround().

◆ Intersect()

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

Function Intersect()

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

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

Definition at line 93 of file seg.cpp.

94 {
95  const VECTOR2I e( B - A );
96  const VECTOR2I f( aSeg.B - aSeg.A );
97  const VECTOR2I ac( aSeg.A - A );
98 
99  ecoord d = f.Cross( e );
100  ecoord p = f.Cross( ac );
101  ecoord q = e.Cross( ac );
102 
103  if( d == 0 )
104  return OPT_VECTOR2I();
105 
106  if( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) )
107  return OPT_VECTOR2I();
108 
109  if( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) )
110  return OPT_VECTOR2I();
111 
112  if( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) )
113  return OPT_VECTOR2I();
114 
115  VECTOR2I ip( aSeg.A.x + rescale( q, (ecoord) f.x, d ),
116  aSeg.A.y + rescale( q, (ecoord) f.y, d ) );
117 
118  return ip;
119 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95
VECTOR2I B
Definition: seg.h:48

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

Referenced by EC_CONVERGING::Apply(), PNS::LINE::dragSegment45(), ALTIUM_PCB::HelperParseDimensions6Linear(), SHAPE_LINE_CHAIN::Intersect(), IntersectLines(), SCH_EAGLE_PLUGIN::loadSegments(), NearestPoint(), SHAPE_LINE_CHAIN::SelfIntersecting(), SquaredDistance(), and PNS::LINE::Walkaround().

◆ IntersectLines()

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

Function IntersectLines()

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

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

Definition at line 191 of file seg.h.

192  {
193  return Intersect( aSeg, false, true );
194  }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93

References Intersect().

Referenced by GRID_HELPER::AlignToSegment(), EE_GRID_HELPER::AlignToWire(), PNS::DP_GATEWAYS::BuildGeneric(), PNS::ConvexHull(), PNS::OPTIMIZER::mergeObtuse(), and PNS::LINE::snapDraggedCorner().

◆ Length()

◆ LineDistance()

int SEG::LineDistance ( const VECTOR2I aP,
bool  aDetermineSide = false 
) const
inline

Function LineDistance()

Returns the closest Euclidean distance between point aP and the line defined by the ends of segment (this).

Parameters
aPthe point to test
aDetermineSidewhen 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 378 of file seg.h.

379 {
380  ecoord p = A.y - B.y;
381  ecoord q = B.x - A.x;
382  ecoord r = -p * A.x - q * A.y;
383 
384  ecoord dist = ( p * aP.x + q * aP.y + r ) / sqrt( p * p + q * q );
385 
386  return aDetermineSide ? dist : std::abs( dist );
387 }
VECTOR2I::extended_type ecoord

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

Referenced by SHAPE_LINE_CHAIN::NearestPoint(), and PNS::LINE::snapToNeighbourSegments().

◆ LineProject()

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

Function LineProject()

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

Parameters
aPpoint to project
Returns
projected point

Definition at line 362 of file seg.h.

363 {
364  VECTOR2I d = B - A;
365  ecoord l_squared = d.Dot( d );
366 
367  if( l_squared == 0 )
368  return A;
369 
370  ecoord t = d.Dot( aP - A );
371 
372  int xp = rescale( t, (ecoord)d.x, l_squared );
373  int yp = rescale( t, (ecoord)d.y, l_squared );
374 
375  return A + VECTOR2I( xp, yp );
376 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:492
VECTOR2I A
Definition: seg.h:47
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95

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

Referenced by PNS::LINE_PLACER::buildInitialLine(), PNS::DP_GATEWAYS::BuildOrthoProjections(), PNS::commonParallelProjection(), PNS::findCoupledVertices(), PNS::LINE_PLACER::rhStopAtNearestObstacle(), PNS::DIFF_PAIR_PLACER::routeHead(), and PNS::MEANDER_SHAPE::updateBaseSegment().

◆ NearestPoint() [1/2]

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

Function NearestPoint()

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

Returns
the nearest point

Definition at line 395 of file seg.h.

396 {
397  VECTOR2I d = B - A;
398  ecoord l_squared = d.Dot( d );
399 
400  if( l_squared == 0 )
401  return A;
402 
403  ecoord t = d.Dot( aP - A );
404 
405  if( t < 0 )
406  return A;
407  else if( t > l_squared )
408  return B;
409 
410  int xp = rescale( t, (ecoord)d.x, l_squared );
411  int yp = rescale( t, (ecoord)d.y, l_squared );
412 
413  return A + VECTOR2I( xp, yp );
414 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:492
VECTOR2I A
Definition: seg.h:47
T rescale(T aNumerator, T aValue, T aDenominator)
Function rescale()
Definition: util.h:95
VECTOR2I B
Definition: seg.h:48

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

Referenced by POINT_EDITOR::addCorner(), PNS::closestProjectedPoint(), Collide(), NearestPoint(), SHAPE_LINE_CHAIN::NearestPoint(), pushoutForce(), PNS::WALKAROUND::Route(), SquaredDistance(), PNS::MEANDER_SKEW_PLACER::Start(), PNS::MEANDER_PLACER::Start(), and PNS::DP_MEANDER_PLACER::Start().

◆ NearestPoint() [2/2]

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

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

Returns
the nearest point

Definition at line 60 of file seg.cpp.

61 {
62  if( auto p = Intersect( aSeg ) )
63  return *p;
64 
65  const VECTOR2I pts_origin[4] =
66  {
67  aSeg.NearestPoint( A ),
68  aSeg.NearestPoint( B ),
69  NearestPoint( aSeg.A ),
70  NearestPoint( aSeg.B )
71  };
72 
73  const ecoord pts_dist[4] =
74  {
75  ( pts_origin[0] - A ).SquaredEuclideanNorm(),
76  ( pts_origin[1] - B ).SquaredEuclideanNorm(),
77  ( pts_origin[2] - aSeg.A ).SquaredEuclideanNorm(),
78  ( pts_origin[3] - aSeg.B ).SquaredEuclideanNorm()
79  };
80 
81  int min_i = 0;
82 
83  for( int i = 0; i < 4; i++ )
84  {
85  if( pts_dist[i] < pts_dist[min_i] )
86  min_i = i;
87  }
88 
89  return pts_origin[min_i];
90 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:395
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

◆ operator!=()

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

Definition at line 111 of file seg.h.

112  {
113  return (A != aSeg.A || B != aSeg.B);
114  }
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References A, and B.

◆ operator=()

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

Definition at line 97 of file seg.h.

98  {
99  A = aSeg.A;
100  B = aSeg.B;
101  m_index = aSeg.m_index;
102 
103  return *this;
104  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:359
VECTOR2I B
Definition: seg.h:48

References A, B, and m_index.

◆ operator==()

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

Definition at line 106 of file seg.h.

107  {
108  return (A == aSeg.A && B == aSeg.B) ;
109  }
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References A, and B.

◆ Overlaps()

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

Definition at line 277 of file seg.h.

278  {
279  if( aSeg.A == aSeg.B ) // single point corner case
280  {
281  if( A == aSeg.A || B == aSeg.A )
282  return false;
283 
284  return Contains( aSeg.A );
285  }
286 
287  if( !Collinear( aSeg ) )
288  return false;
289 
290  if( Contains( aSeg.A ) || Contains( aSeg.B ) )
291  return true;
292  if( aSeg.Contains( A ) || aSeg.Contains( B ) )
293  return true;
294 
295  return false;
296  }
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:243
VECTOR2I A
Definition: seg.h:47
bool Contains(const SEG &aSeg) const
Definition: seg.h:299
VECTOR2I B
Definition: seg.h:48

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

◆ Reverse()

void SEG::Reverse ( )
inline

Definition at line 344 of file seg.h.

345  {
346  std::swap( A, B );
347  }

◆ Side()

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

Function Side()

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

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

Definition at line 138 of file seg.h.

139  {
140  const ecoord det = ( B - A ).Cross( aP - A );
141 
142  return det < 0 ? -1 : ( det > 0 ? 1 : 0 );
143  }
VECTOR2I::extended_type ecoord
VECTOR2I A
Definition: seg.h:47

References A.

Referenced by PNS::ArcHull(), PNS::DP_GATEWAYS::buildDpContinuation(), PNS::DP_MEANDER_PLACER::pairOrientation(), and PNS::SegmentHull().

◆ Square()

static SEG::ecoord SEG::Square ( int  a)
inlinestatic

Definition at line 116 of file seg.h.

117  {
118  return ecoord( a ) * a;
119  }
VECTOR2I::extended_type ecoord
Definition: seg.h:42

Referenced by SHAPE_LINE_CHAIN_BASE::Collide(), D_PAD::HitTest(), and TestSegmentHit().

◆ SquaredDistance() [1/2]

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

Definition at line 37 of file seg.cpp.

38 {
39  // fixme: rather inefficient....
40  if( Intersect( aSeg ) )
41  return 0;
42 
43  const VECTOR2I pts[4] =
44  {
45  aSeg.NearestPoint( A ) - A,
46  aSeg.NearestPoint( B ) - B,
47  NearestPoint( aSeg.A ) - aSeg.A,
48  NearestPoint( aSeg.B ) - aSeg.B
49  };
50 
52 
53  for( int i = 0; i < 4; i++ )
54  m = std::min( m, pts[i].SquaredEuclideanNorm() );
55 
56  return m;
57 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:93
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:80
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:395
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References A, B, VECTOR2< T >::ECOORD_MAX, Intersect(), and NearestPoint().

Referenced by SHAPE_CIRCLE::Collide(), SHAPE_SEGMENT::Collide(), SHAPE_ARC::Collide(), SHAPE_RECT::Collide(), Collide(), SHAPE_LINE_CHAIN_BASE::Collide(), Contains(), Distance(), DRC_TEST_PROVIDER_CLEARANCE_BASE::getLocation(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), and TestSegmentHit().

◆ SquaredDistance() [2/2]

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

Definition at line 212 of file seg.h.

213  {
214  return ( NearestPoint( aP ) - aP ).SquaredEuclideanNorm();
215  }
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:395

References NearestPoint().

◆ SquaredLength()

ecoord SEG::SquaredLength ( ) const
inline

Definition at line 324 of file seg.h.

325  {
326  return ( A - B ).SquaredEuclideanNorm();
327  }

Referenced by PNS::commonParallelProjection().

◆ TCoef()

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

Definition at line 389 of file seg.h.

390 {
391  VECTOR2I d = B - A;
392  return d.Dot( aP - A);
393 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:492
VECTOR2I A
Definition: seg.h:47

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

Referenced by PNS::commonParallelProjection().

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 416 of file seg.h.

417 {
418  aStream << "[ " << aSeg.A << " - " << aSeg.B << " ]";
419 
420  return aStream;
421 }
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

Member Data Documentation

◆ A

VECTOR2I SEG::A

Definition at line 47 of file seg.h.

Referenced by PNS::NODE::Add(), PNS_KICAD_IFACE::AddItem(), PNS::NODE::addSegment(), PNS_PCBNEW_DEBUG_DECORATOR::AddSegment(), BOARD_ADAPTER::AddShapeWithClearanceToContainer(), GRID_HELPER::AlignToSegment(), EE_GRID_HELPER::AlignToWire(), PNS::SEGMENT::Anchor(), ApproxCollinear(), PNS::ApproximateSegmentAsRect(), ApproxParallel(), PNS::DP_MEANDER_PLACER::baselineSegment(), SHAPE_SEGMENT::BBox(), BOOST_AUTO_TEST_CASE(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), Center(), SHAPE_LINE_CHAIN::CheckClearance(), PNS::SEGMENT::CLine(), SHAPE_ARC::Collide(), SHAPE_RECT::Collide(), Collide(), Collinear(), PNS::commonParallelProjection(), PNS::TOPOLOGY::ConnectedJoints(), Contains(), BOARD_ADAPTER::createNewPadDrill(), BOARD_ADAPTER::createNewPadWithClearance(), PNS::DP_PRIMITIVE_PAIR::CursorOrientation(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), DIRECTION_45::DIRECTION_45(), PNS::MEANDER_PLACER::doMove(), PNS::LINE::dragSegment45(), KIGFX::PCB_PAINTER::draw(), ROUTER_PREVIEW_ITEM::drawLineChain(), KI_TEST::DrawSegment(), SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint(), PNS::NODE::findRedundantSegment(), PNS::MEANDER_SHAPE::Fit(), PNS::DIFF_PAIR_PLACER::getDanglingAnchor(), DRC_TEST_PROVIDER_CLEARANCE_BASE::getLocation(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), ZONE_CONTAINER::HatchBorder(), Intersect(), SHAPE_LINE_CHAIN::Intersect(), PNS::LINE::Is45Degree(), KIGFX::VIEW_OVERLAY::Line(), LineProject(), PNS::MEANDER_SHAPE::MakeCorner(), DRAWSEGMENT::MakeEffectiveShapes(), PNS::MEANDER_SHAPE::MakeEmpty(), PNS::MEANDERED_LINE::MeanderSegment(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), ZONE_CONTAINER::Mirror(), SHAPE_SEGMENT::Move(), ZONE_CONTAINER::Move(), PNS::MoveDiagonal(), NearestPoint(), operator!=(), POLY_GRID_PARTITION::segsEqual::operator()(), POLY_GRID_PARTITION::segHash::operator()(), operator<<(), operator=(), operator==(), Overlaps(), PNS::DP_MEANDER_PLACER::pairOrientation(), SHAPE_LINE_CHAIN::PathLength(), BRDITEMS_PLOTTER::PlotDimension(), PlotLayerOutlines(), SHAPE_LINE_CHAIN::PointAlong(), PNS::MEANDER_SHAPE::Recalculate(), PNS::LINE_PLACER::reduceTail(), PNS::MEANDER_SHAPE::reflect(), PNS::NODE::removeSegmentIndex(), ZONE_CONTAINER::Rotate(), PNS::WALKAROUND::Route(), POLY_GRID_PARTITION::scanCell(), GEOM_TEST::SegmentCompletelyInQuadrant(), GEOM_TEST::SegmentCompletelyWithinRadius(), GEOM_TEST::SegmentEndsInQuadrant(), PNS::SegmentHull(), DIMENSION::segPolyIntersection(), SHAPE_LINE_CHAIN::SelfIntersecting(), Side(), PNS::LINE::snapToNeighbourSegments(), SHAPE_LINE_CHAIN::Split(), PNS::LINE_PLACER::SplitAdjacentSegments(), SquaredDistance(), SHAPE_POLY_SET::SquaredDistanceToPolygon(), PNS::DRAGGER::startDragSegment(), PNS::SEGMENT::SwapEnds(), TCoef(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones(), PNS::tightenSegment(), D_PAD::TransformHoleWithClearanceToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), ALIGNED_DIMENSION::updateGeometry(), ORTHOGONAL_DIMENSION::updateGeometry(), ROUTER_PREVIEW_ITEM::ViewDraw(), and PNS::LINE::Walkaround().

◆ B

VECTOR2I SEG::B

Definition at line 48 of file seg.h.

Referenced by PNS::NODE::Add(), PNS_KICAD_IFACE::AddItem(), PNS::MEANDERED_LINE::AddMeander(), PNS::NODE::addSegment(), PNS_PCBNEW_DEBUG_DECORATOR::AddSegment(), BOARD_ADAPTER::AddShapeWithClearanceToContainer(), GRID_HELPER::AlignToSegment(), EE_GRID_HELPER::AlignToWire(), PNS::SEGMENT::Anchor(), ApproxCollinear(), PNS::ApproximateSegmentAsRect(), ApproxParallel(), PNS::DP_MEANDER_PLACER::baselineSegment(), SHAPE_SEGMENT::BBox(), BOOST_AUTO_TEST_CASE(), POLY_GRID_PARTITION::build(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), SHAPE_LINE_CHAIN::CheckClearance(), PNS::SEGMENT::CLine(), SHAPE_ARC::Collide(), SHAPE_RECT::Collide(), Collide(), Collinear(), PNS::commonParallelProjection(), PNS::TOPOLOGY::ConnectedJoints(), Contains(), BOARD_ADAPTER::createNewPadDrill(), BOARD_ADAPTER::createNewPadWithClearance(), PNS::DP_PRIMITIVE_PAIR::CursorOrientation(), PNS::MEANDER_PLACER_BASE::cutTunedLine(), DIRECTION_45::DIRECTION_45(), PNS::MEANDER_PLACER::doMove(), PNS::LINE::dragSegment45(), KIGFX::PCB_PAINTER::draw(), ROUTER_PREVIEW_ITEM::drawLineChain(), KI_TEST::DrawSegment(), SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint(), PNS::MEANDER_SHAPE::End(), SCH_EAGLE_PLUGIN::findNearestLinePoint(), PNS::NODE::findRedundantSegment(), PNS::MEANDER_SHAPE::Fit(), PNS::DIFF_PAIR_PLACER::getDanglingAnchor(), DRC_TEST_PROVIDER_CLEARANCE_BASE::getLocation(), ZONE_CONTAINER::HatchBorder(), Intersect(), SHAPE_LINE_CHAIN::Intersect(), PNS::LINE::Is45Degree(), KIGFX::VIEW_OVERLAY::Line(), PNS::MEANDER_SHAPE::MakeCorner(), DRAWSEGMENT::MakeEffectiveShapes(), PNS::MEANDER_SHAPE::MakeEmpty(), PNS::MEANDERED_LINE::MeanderSegment(), PNS::OPTIMIZER::mergeDpStep(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), ZONE_CONTAINER::Mirror(), SHAPE_SEGMENT::Move(), ZONE_CONTAINER::Move(), PNS::MoveDiagonal(), NearestPoint(), operator!=(), POLY_GRID_PARTITION::segsEqual::operator()(), POLY_GRID_PARTITION::segHash::operator()(), operator<<(), operator=(), operator==(), Overlaps(), BRDITEMS_PLOTTER::PlotDimension(), PlotLayerOutlines(), SHAPE_LINE_CHAIN::PointAlong(), PNS::MEANDER_SHAPE::Recalculate(), PNS::MEANDER_SHAPE::reflect(), PNS::NODE::removeSegmentIndex(), ZONE_CONTAINER::Rotate(), PNS::WALKAROUND::Route(), POLY_GRID_PARTITION::scanCell(), GEOM_TEST::SegmentCompletelyInQuadrant(), GEOM_TEST::SegmentCompletelyWithinRadius(), GEOM_TEST::SegmentEndsInQuadrant(), PNS::SegmentHull(), DIMENSION::segPolyIntersection(), SHAPE_LINE_CHAIN::SelfIntersecting(), SHAPE_LINE_CHAIN::Split(), PNS::LINE_PLACER::SplitAdjacentSegments(), SquaredDistance(), PNS::DRAGGER::startDragSegment(), PNS::SEGMENT::SwapEnds(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones(), PNS::tightenSegment(), D_PAD::TransformHoleWithClearanceToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), ALIGNED_DIMENSION::updateGeometry(), ORTHOGONAL_DIMENSION::updateGeometry(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), ROUTER_PREVIEW_ITEM::ViewDraw(), and PNS::LINE::Walkaround().

◆ m_index

int SEG::m_index
private

index withing the parent shape (used when m_is_local == false)

Definition at line 359 of file seg.h.

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


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