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 ()
 
SEG Reversed () const
 
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:373

References m_index.

Referenced by Reversed().

◆ 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:628
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:373
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  :
74  A( aA ),
75  B( aB )
76  {
77  m_index = -1;
78  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:373
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 87 of file seg.h.

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

References m_index.

◆ SEG() [5/5]

SEG::SEG ( const SEG aSeg)
inline

Copy constructor.

Definition at line 97 of file seg.h.

97  :
98  A( aSeg.A ),
99  B( aSeg.B ),
100  m_index( aSeg.m_index )
101  {
102  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:373
VECTOR2I B
Definition: seg.h:48

Member Function Documentation

◆ ApproxCollinear()

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

Definition at line 261 of file seg.h.

262  {
263  ecoord p, q, r;
264  CanonicalCoefs( p, q, r );
265 
266  ecoord dist1 = ( p * aSeg.A.x + q * aSeg.A.y + r ) / sqrt( p * p + q * q );
267  ecoord dist2 = ( p * aSeg.B.x + q * aSeg.B.y + r ) / sqrt( p * p + q * q );
268 
269  return std::abs( dist1 ) <= 1 && std::abs( dist2 ) <= 1;
270  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:236
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 272 of file seg.h.

273  {
274  ecoord p, q, r;
275  CanonicalCoefs( p, q, r );
276 
277  ecoord dist1 = ( p * aSeg.A.x + q * aSeg.A.y + r ) / sqrt( p * p + q * q );
278  ecoord dist2 = ( p * aSeg.B.x + q * aSeg.B.y + r ) / sqrt( p * p + q * q );
279 
280  return std::abs( dist1 - dist2 ) <= 1;
281  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:236
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 236 of file seg.h.

237  {
238  qA = ecoord{ A.y } - B.y;
239  qB = ecoord{ B.x } - A.x;
240  qC = -qA * A.x - qB * A.y;
241  }
VECTOR2I::extended_type ecoord

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

◆ ccw()

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

Definition at line 133 of file seg.cpp.

134 {
135  return (ecoord) ( aC.y - aA.y ) * ( aB.x - aA.x ) > (ecoord) ( aB.y - aA.y ) * ( aC.x - aA.x );
136 }
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 363 of file seg.h.

364  {
365  return A + ( B - A ) / 2;
366  }
VECTOR2I A
Definition: seg.h:47

References A.

Referenced by PCB_GRID_HELPER::computeAnchors(), SCH_EAGLE_PLUGIN::findNearestLinePoint(), and SHAPE_ARC::SHAPE_ARC().

◆ Collide()

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

Definition at line 139 of file seg.cpp.

140 {
141  // check for intersection
142  // fixme: move to a method
143  if( ccw( A, aSeg.A, aSeg.B ) != ccw( B, aSeg.A, aSeg.B ) &&
144  ccw( A, B, aSeg.A ) != ccw( A, B, aSeg.B ) )
145  {
146  if( aActual )
147  *aActual = 0;
148 
149  return true;
150  }
151 
152  ecoord dist_sq = VECTOR2I::ECOORD_MAX;
153 
154  dist_sq = std::min( dist_sq, SquaredDistance( aSeg.A ) );
155  dist_sq = std::min( dist_sq, SquaredDistance( aSeg.B ) );
156  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( A ) );
157  dist_sq = std::min( dist_sq, aSeg.SquaredDistance( B ) );
158 
159  if( dist_sq == 0 || dist_sq < (ecoord) aClearance * aClearance )
160  {
161  if( aActual )
162  *aActual = sqrt( dist_sq );
163 
164  return true;
165  }
166 
167  return false;
168 }
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: seg.cpp:133
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:37
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:81
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::TestZoneIntersection().

◆ 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 250 of file seg.h.

251  {
252  ecoord qa, qb, qc;
253  CanonicalCoefs( qa, qb, qc );
254 
255  ecoord d1 = std::abs( aSeg.A.x * qa + aSeg.A.y * qb + qc );
256  ecoord d2 = std::abs( aSeg.B.x * qa + aSeg.B.y * qb + qc );
257 
258  return ( d1 <= 1 && d2 <= 1 );
259  }
void CanonicalCoefs(ecoord &qA, ecoord &qB, ecoord &qC) const
Definition: seg.h:236
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(), PNS::OPTIMIZER::mergeColinear(), Overlaps(), SegCollinearCorrect(), and POLYGON_GEOM_MANAGER::updateLeaderPoints().

◆ Contains() [1/2]

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

Definition at line 307 of file seg.h.

308  {
309  if( aSeg.A == aSeg.B ) // single point corner case
310  return Contains( aSeg.A );
311 
312  if( !Collinear( aSeg ) )
313  return false;
314 
315  if( Contains( aSeg.A ) && Contains( aSeg.B ) )
316  return true;
317 
318  return false;
319  }
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:250
VECTOR2I A
Definition: seg.h:47
bool Contains(const SEG &aSeg) const
Definition: seg.h:307
VECTOR2I B
Definition: seg.h:48

References A, B, and Collinear().

Referenced by PCB_GRID_HELPER::AlignToSegment(), BuildFootprintPolygonOutlines(), PNS::LINE::ChangedArea(), findEndSegments(), 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 171 of file seg.cpp.

172 {
173  return SquaredDistance( aP ) <= 1; // 1 * 1 to be pedantic
174 }
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 231 of file seg.h.

232  {
233  return sqrt( SquaredDistance( aP ) );
234  }
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 345 of file seg.h.

346  {
347  return m_index;
348  }
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:373

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 104 of file seg.cpp.

105 {
106  const VECTOR2I e( B - A );
107  const VECTOR2I f( aSeg.B - aSeg.A );
108  const VECTOR2I ac( aSeg.A - A );
109 
110  ecoord d = f.Cross( e );
111  ecoord p = f.Cross( ac );
112  ecoord q = e.Cross( ac );
113 
114  if( d == 0 )
115  return OPT_VECTOR2I();
116 
117  if( !aLines && d > 0 && ( q < 0 || q > d || p < 0 || p > d ) )
118  return OPT_VECTOR2I();
119 
120  if( !aLines && d < 0 && ( q < d || p < d || p > 0 || q > 0 ) )
121  return OPT_VECTOR2I();
122 
123  if( !aLines && aIgnoreEndpoints && ( q == 0 || q == d ) && ( p == 0 || p == d ) )
124  return OPT_VECTOR2I();
125 
126  VECTOR2I ip( aSeg.A.x + rescale( q, (ecoord) f.x, d ),
127  aSeg.A.y + rescale( q, (ecoord) f.y, d ) );
128 
129  return ip;
130 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
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(), SHAPE_ARC::SHAPE_ARC(), 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 198 of file seg.h.

199  {
200  return Intersect( aSeg, false, true );
201  }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:104

References Intersect().

Referenced by PCB_GRID_HELPER::AlignToSegment(), BuildFootprintPolygonOutlines(), 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 392 of file seg.h.

393 {
394  ecoord p = ecoord{ A.y } - B.y;
395  ecoord q = ecoord{ B.x } - A.x;
396  ecoord r = -p * A.x - q * A.y;
397 
398  ecoord dist = ( p * aP.x + q * aP.y + r ) / sqrt( p * p + q * q );
399 
400  return aDetermineSide ? dist : std::abs( dist );
401 }
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 376 of file seg.h.

377 {
378  VECTOR2I d = B - A;
379  ecoord l_squared = d.Dot( d );
380 
381  if( l_squared == 0 )
382  return A;
383 
384  ecoord t = d.Dot( aP - A );
385 
386  int xp = rescale( t, ecoord{ d.x }, l_squared );
387  int yp = rescale( t, ecoord{ d.y }, l_squared );
388 
389  return A + VECTOR2I( xp, yp );
390 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
VECTOR2< int > VECTOR2I
Definition: vector2d.h:628
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:526
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(), commonParallelProjection(), PNS::commonParallelProjection(), PNS::findCoupledVertices(), PNS::DIFF_PAIR_PLACER::routeHead(), SHAPE_ARC::SHAPE_ARC(), 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 409 of file seg.h.

410 {
411  VECTOR2I d = B - A;
412  ecoord l_squared = d.Dot( d );
413 
414  if( l_squared == 0 )
415  return A;
416 
417  ecoord t = d.Dot( aP - A );
418 
419  if( t < 0 )
420  return A;
421  else if( t > l_squared )
422  return B;
423 
424  int xp = rescale( t, (ecoord)d.x, l_squared );
425  int yp = rescale( t, (ecoord)d.y, l_squared );
426 
427  return A + VECTOR2I( xp, yp );
428 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
VECTOR2< int > VECTOR2I
Definition: vector2d.h:628
VECTOR2I::extended_type ecoord
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:526
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 PCB_POINT_EDITOR::addCorner(), PNS::closestProjectedPoint(), Collide(), SHAPE_CIRCLE::Collide(), SHAPE_SEGMENT::Collide(), SHAPE_RECT::Collide(), SHAPE_LINE_CHAIN_BASE::Collide(), NearestPoint(), SHAPE_LINE_CHAIN::NearestPoint(), pushoutForce(), PNS::WALKAROUND::Route(), and SquaredDistance().

◆ 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 62 of file seg.cpp.

63 {
64  if( OPT_VECTOR2I p = Intersect( aSeg ) )
65  return *p;
66 
67  const VECTOR2I pts_origin[4] =
68  {
69  aSeg.NearestPoint( A ),
70  aSeg.NearestPoint( B ),
71  NearestPoint( aSeg.A ),
72  NearestPoint( aSeg.B )
73  };
74 
75 
76  const VECTOR2I* pts_out[4] =
77  {
78  &A,
79  &B,
80  &pts_origin[2],
81  &pts_origin[3]
82  };
83 
84  const ecoord pts_dist[4] =
85  {
86  ( pts_origin[0] - A ).SquaredEuclideanNorm(),
87  ( pts_origin[1] - B ).SquaredEuclideanNorm(),
88  ( pts_origin[2] - aSeg.A ).SquaredEuclideanNorm(),
89  ( pts_origin[3] - aSeg.B ).SquaredEuclideanNorm()
90  };
91 
92  int min_i = 0;
93 
94  for( int i = 0; i < 4; i++ )
95  {
96  if( pts_dist[i] < pts_dist[min_i] )
97  min_i = i;
98  }
99 
100  return *pts_out[min_i];
101 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:104
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:37
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:409
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 118 of file seg.h.

119  {
120  return (A != aSeg.A || B != aSeg.B);
121  }
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 104 of file seg.h.

105  {
106  A = aSeg.A;
107  B = aSeg.B;
108  m_index = aSeg.m_index;
109 
110  return *this;
111  }
VECTOR2I A
Definition: seg.h:47
int m_index
index withing the parent shape (used when m_is_local == false)
Definition: seg.h:373
VECTOR2I B
Definition: seg.h:48

References A, B, and m_index.

◆ operator==()

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

Definition at line 113 of file seg.h.

114  {
115  return (A == aSeg.A && B == aSeg.B) ;
116  }
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 284 of file seg.h.

285  {
286  if( aSeg.A == aSeg.B ) // single point corner case
287  {
288  if( A == aSeg.A || B == aSeg.A )
289  return false;
290 
291  return Contains( aSeg.A );
292  }
293 
294  if( !Collinear( aSeg ) )
295  return false;
296 
297  if( Contains( aSeg.A ) || Contains( aSeg.B ) )
298  return true;
299 
300  if( aSeg.Contains( A ) || aSeg.Contains( B ) )
301  return true;
302 
303  return false;
304  }
bool Collinear(const SEG &aSeg) const
Function Collinear()
Definition: seg.h:250
VECTOR2I A
Definition: seg.h:47
bool Contains(const SEG &aSeg) const
Definition: seg.h:307
VECTOR2I B
Definition: seg.h:48

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

◆ Reverse()

void SEG::Reverse ( )
inline

Definition at line 352 of file seg.h.

353  {
354  std::swap( A, B );
355  }

◆ Reversed()

SEG SEG::Reversed ( ) const
inline

Definition at line 357 of file seg.h.

358  {
359  return SEG( B, A );
360  }
SEG()
Default constructor Creates an empty (0, 0) segment.
Definition: seg.h:53

References SEG().

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

◆ 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 145 of file seg.h.

146  {
147  const ecoord det = ( B - A ).Cross( aP - A );
148 
149  return det < 0 ? -1 : ( det > 0 ? 1 : 0 );
150  }
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()

◆ 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  {
55  m = std::min( m, pts[i].SquaredEuclideanNorm() );
56  }
57 
58  return m;
59 }
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Function Intersect()
Definition: seg.cpp:104
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:81
VECTOR2I::extended_type ecoord
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:409
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

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

Referenced by PNS::PRESERVE_VERTEX_CONSTRAINT::Check(), SHAPE_SEGMENT::Collide(), SHAPE_ARC::Collide(), SHAPE_RECT::Collide(), Collide(), SHAPE_LINE_CHAIN_BASE::Collide(), Contains(), Distance(), SHAPE_LINE_CHAIN_BASE::SquaredDistance(), and TestSegmentHit().

◆ SquaredDistance() [2/2]

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

Definition at line 219 of file seg.h.

220  {
221  return ( NearestPoint( aP ) - aP ).SquaredEuclideanNorm();
222  }
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:409

References NearestPoint().

◆ SquaredLength()

ecoord SEG::SquaredLength ( ) const
inline

Definition at line 332 of file seg.h.

333  {
334  return ( A - B ).SquaredEuclideanNorm();
335  }

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

◆ TCoef()

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

Definition at line 403 of file seg.h.

404 {
405  VECTOR2I d = B - A;
406  return d.Dot( aP - A);
407 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:62
extended_type Dot(const VECTOR2< T > &aVector) const
Function Dot() computes dot product of self with aVector.
Definition: vector2d.h:526
VECTOR2I A
Definition: seg.h:47

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

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

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 430 of file seg.h.

431 {
432  aStream << "[ " << aSeg.A << " - " << aSeg.B << " ]";
433 
434  return aStream;
435 }
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::addShapeWithClearance(), PCB_GRID_HELPER::AlignToSegment(), 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(), SHAPE_LINE_CHAIN_BASE::Collide(), Collinear(), commonParallelProjection(), PNS::commonParallelProjection(), PCB_GRID_HELPER::computeAnchors(), PNS::TOPOLOGY::ConnectedJoints(), Contains(), BOARD_ADAPTER::createPadWithClearance(), BOARD_ADAPTER::createPadWithDrill(), 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(), ROUTER_PREVIEW_ITEM::drawShape(), SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint(), extractDiffPairCoupledItems(), findEndSegments(), PNS::NODE::findRedundantSegment(), PNS::MEANDER_SHAPE::Fit(), SHAPE_SEGMENT::Format(), PNS::getDanglingAnchor(), PNS::LINE_PLACER::handlePullback(), PNS::LINE_PLACER::handleSelfIntersections(), ZONE::HatchBorder(), Intersect(), SHAPE_LINE_CHAIN::Intersect(), PNS::LINE::Is45Degree(), KIGFX::VIEW_OVERLAY::Line(), LineProject(), CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices(), PNS::MEANDER_SHAPE::MakeCorner(), PCB_SHAPE::MakeEffectiveShapes(), PNS::MEANDER_SHAPE::MakeEmpty(), PNS::MEANDERED_LINE::MeanderSegment(), PNS::OPTIMIZER::mergeColinear(), PNS::OPTIMIZER::mergeDpStep(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), ZONE::Mirror(), SHAPE_SEGMENT::Move(), ZONE::Move(), PNS::MoveDiagonal(), NearestPoint(), operator!=(), POLY_GRID_PARTITION::segsEqual::operator()(), POLY_GRID_PARTITION::segHash::operator()(), operator<<(), operator=(), operator==(), PNS::DRAGGER::optimizeAndUpdateDraggedLine(), Overlaps(), DIALOG_PAD_PROPERTIES::padValuesOK(), 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::Rotate(), PNS::WALKAROUND::Route(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), POLY_GRID_PARTITION::scanCell(), GEOM_TEST::SegmentCompletelyInQuadrant(), GEOM_TEST::SegmentCompletelyWithinRadius(), GEOM_TEST::SegmentEndsInQuadrant(), PNS::SegmentHull(), DIMENSION_BASE::segPolyIntersection(), SHAPE_LINE_CHAIN::SelfIntersecting(), SHAPE_ARC::SHAPE_ARC(), Side(), PNS::LINE::snapToNeighbourSegments(), SHAPE_LINE_CHAIN::Split(), PNS::LINE_PLACER::SplitAdjacentSegments(), SquaredDistance(), SHAPE_POLY_SET::SquaredDistanceToPolygon(), PNS::LINE_PLACER::Start(), PNS::DRAGGER::startDragSegment(), PNS::SEGMENT::SwapEnds(), TCoef(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones(), PNS::tightenSegment(), TransformArcToPolygon(), PAD::TransformHoleWithClearanceToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), ALIGNED_DIMENSION::updateGeometry(), ORTHOGONAL_DIMENSION::updateGeometry(), 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::addShapeWithClearance(), PCB_GRID_HELPER::AlignToSegment(), 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(), commonParallelProjection(), PNS::commonParallelProjection(), PCB_GRID_HELPER::computeAnchors(), PNS::TOPOLOGY::ConnectedJoints(), Contains(), BOARD_ADAPTER::createPadWithClearance(), BOARD_ADAPTER::createPadWithDrill(), 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(), ROUTER_PREVIEW_ITEM::drawShape(), SHAPE_LINE_CHAIN_BASE::EdgeContainingPoint(), PNS::MEANDER_SHAPE::End(), findEndSegments(), SCH_EAGLE_PLUGIN::findNearestLinePoint(), PNS::NODE::findRedundantSegment(), PNS::MEANDER_SHAPE::Fit(), SHAPE_SEGMENT::Format(), PNS::getDanglingAnchor(), ZONE::HatchBorder(), Intersect(), SHAPE_LINE_CHAIN::Intersect(), PNS::LINE::Is45Degree(), KIGFX::VIEW_OVERLAY::Line(), CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices(), PNS::MEANDER_SHAPE::MakeCorner(), PCB_SHAPE::MakeEffectiveShapes(), PNS::MEANDER_SHAPE::MakeEmpty(), PNS::MEANDERED_LINE::MeanderSegment(), PNS::OPTIMIZER::mergeDpStep(), PNS::LINE_PLACER::mergeHead(), PNS::OPTIMIZER::mergeObtuse(), PNS::OPTIMIZER::mergeStep(), ZONE::Mirror(), SHAPE_SEGMENT::Move(), ZONE::Move(), PNS::MoveDiagonal(), NearestPoint(), operator!=(), POLY_GRID_PARTITION::segsEqual::operator()(), POLY_GRID_PARTITION::segHash::operator()(), operator<<(), operator=(), operator==(), PNS::DRAGGER::optimizeAndUpdateDraggedLine(), Overlaps(), DIALOG_PAD_PROPERTIES::padValuesOK(), BRDITEMS_PLOTTER::PlotDimension(), PlotLayerOutlines(), SHAPE_LINE_CHAIN::PointAlong(), PNS::MEANDER_SHAPE::Recalculate(), PNS::MEANDER_SHAPE::reflect(), PNS::NODE::removeSegmentIndex(), ZONE::Rotate(), PNS::WALKAROUND::Route(), DRC_TEST_PROVIDER_EDGE_CLEARANCE::Run(), POLY_GRID_PARTITION::scanCell(), GEOM_TEST::SegmentCompletelyInQuadrant(), GEOM_TEST::SegmentCompletelyWithinRadius(), GEOM_TEST::SegmentEndsInQuadrant(), PNS::SegmentHull(), DIMENSION_BASE::segPolyIntersection(), SHAPE_LINE_CHAIN::SelfIntersecting(), SHAPE_ARC::SHAPE_ARC(), SHAPE_LINE_CHAIN::Split(), PNS::LINE_PLACER::SplitAdjacentSegments(), SquaredDistance(), SHAPE_POLY_SET::SquaredDistanceToPolygon(), PNS::LINE_PLACER::Start(), PNS::DRAGGER::startDragSegment(), PNS::SEGMENT::SwapEnds(), DRC_TEST_PROVIDER_COPPER_CLEARANCE::testZones(), PNS::tightenSegment(), TransformArcToPolygon(), PAD::TransformHoleWithClearanceToPolygon(), unfracture(), SHAPE_POLY_SET::unfractureSingle(), PNS::MEANDER_SHAPE::updateBaseSegment(), ALIGNED_DIMENSION::updateGeometry(), ORTHOGONAL_DIMENSION::updateGeometry(), POLYGON_GEOM_MANAGER::updateLeaderPoints(), 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 373 of file seg.h.

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


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