KiCad PCB EDA Suite
trigo.h File Reference
#include <cmath>
#include <math/vector2d.h>
#include <geometry/eda_angle.h>

Go to the source code of this file.

Functions

bool IsPointOnSegment (const VECTOR2I &aSegStart, const VECTOR2I &aSegEnd, const VECTOR2I &aTestPoint)
 Test if aTestPoint is on line defined by aSegStart and aSegEnd. More...
 
bool SegmentIntersectsSegment (const VECTOR2I &a_p1_l1, const VECTOR2I &a_p2_l1, const VECTOR2I &a_p1_l2, const VECTOR2I &a_p2_l2, VECTOR2I *aIntersectionPoint=nullptr)
 Test if two lines intersect. More...
 
void RotatePoint (int *pX, int *pY, const EDA_ANGLE &aAngle)
 
void RotatePoint (VECTOR2I &point, const EDA_ANGLE &aAngle)
 
void RotatePoint (int *pX, int *pY, int cx, int cy, const EDA_ANGLE &aAngle)
 
void RotatePoint (VECTOR2I &point, const VECTOR2I &centre, const EDA_ANGLE &aAngle)
 
void RotatePoint (double *pX, double *pY, const EDA_ANGLE &aAngle)
 
void RotatePoint (VECTOR2D &point, const EDA_ANGLE &aAngle)
 
void RotatePoint (double *pX, double *pY, double cx, double cy, const EDA_ANGLE &aAngle)
 
void RotatePoint (VECTOR2D &point, const VECTOR2D &aCenter, const EDA_ANGLE &aAngle)
 
const VECTOR2I CalcArcCenter (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
 Determine the center of an arc or circle given three points on its circumference. More...
 
const VECTOR2D CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd)
 
const VECTOR2D CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aEnd, const EDA_ANGLE &aAngle)
 
const VECTOR2I CalcArcMid (const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle=true)
 Return the middle point of an arc, half-way between aStart and aEnd. More...
 
double EuclideanNorm (const VECTOR2I &vector)
 
double DistanceLinePoint (const VECTOR2I &linePointA, const VECTOR2I &linePointB, const VECTOR2I &referencePoint)
 Compute the distance between a line and a reference point Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html. More...
 
bool HitTestPoints (const VECTOR2I &pointA, const VECTOR2I &pointB, double threshold)
 Test, if two points are near each other. More...
 
bool TestSegmentHit (const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
 Test if aRefPoint is with aDistance on the line defined by aStart and aEnd. More...
 
double GetLineLength (const VECTOR2I &aPointA, const VECTOR2I &aPointB)
 Return the length of a line segment defined by aPointA and aPointB. More...
 
double DEG2RAD (double deg)
 
double RAD2DEG (double rad)
 
double RAD2DECIDEG (double rad)
 
template<class T >
NormalizeAnglePos (T Angle)
 Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees. More...
 
template<class T >
void NORMALIZE_ANGLE_POS (T &Angle)
 
template<class T >
NormalizeAngle180 (T Angle)
 Normalize angle to be in the -180.0 .. 180.0 range. More...
 
bool InterceptsPositiveX (double aStartAngle, double aEndAngle)
 Test if an arc from aStartAngle to aEndAngle crosses the positive X axis (0 degrees). More...
 
bool InterceptsNegativeX (double aStartAngle, double aEndAngle)
 Test if an arc from aStartAngle to aEndAngle crosses the negative X axis (180 degrees). More...
 

Function Documentation

◆ CalcArcCenter() [1/3]

const VECTOR2D CalcArcCenter ( const VECTOR2D aStart,
const VECTOR2D aEnd,
const EDA_ANGLE aAngle 
)

Definition at line 301 of file trigo.cpp.

303{
304 EDA_ANGLE angle( aAngle );
305 VECTOR2I start = aStart;
306 VECTOR2I end = aEnd;
307
308 if( angle < ANGLE_0 )
309 {
310 std::swap( start, end );
311 angle = -angle;
312 }
313
314 if( angle > ANGLE_180 )
315 {
316 std::swap( start, end );
318 }
319
320 double chord = ( start - end ).EuclideanNorm();
321 double r = ( chord / 2.0 ) / ( angle / 2.0 ).Sin();
322 double d_squared = r * r - chord* chord / 4.0;
323 double d = 0.0;
324
325 if( d_squared > 0.0 )
326 d = sqrt( d_squared );
327
328 VECTOR2D vec2 = (end - start).Resize( d );
329 VECTOR2D vc = (end - start).Resize( chord / 2 );
330
331 RotatePoint( vec2, -ANGLE_90 );
332
333 return VECTOR2D( start + vc + vec2 );
334}
static constexpr EDA_ANGLE & ANGLE_180
Definition: eda_angle.h:416
static constexpr EDA_ANGLE & ANGLE_360
Definition: eda_angle.h:418
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:414
static constexpr EDA_ANGLE & ANGLE_0
Definition: eda_angle.h:412
E_SERIE r
Definition: eserie.cpp:41
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617

References PNS::angle(), ANGLE_0, ANGLE_180, ANGLE_360, ANGLE_90, EuclideanNorm(), r, and RotatePoint().

Referenced by CalcArcCenter().

◆ CalcArcCenter() [2/3]

const VECTOR2D CalcArcCenter ( const VECTOR2D aStart,
const VECTOR2D aMid,
const VECTOR2D aEnd 
)

Definition at line 337 of file trigo.cpp.

338{
339 VECTOR2D center;
340 double yDelta_21 = aMid.y - aStart.y;
341 double xDelta_21 = aMid.x - aStart.x;
342 double yDelta_32 = aEnd.y - aMid.y;
343 double xDelta_32 = aEnd.x - aMid.x;
344
345 // This is a special case for aMid as the half-way point when aSlope = 0 and bSlope = inf
346 // or the other way around. In that case, the center lies in a straight line between
347 // aStart and aEnd
348 if( ( ( xDelta_21 == 0.0 ) && ( yDelta_32 == 0.0 ) ) ||
349 ( ( yDelta_21 == 0.0 ) && ( xDelta_32 == 0.0 ) ) )
350 {
351 center.x = ( aStart.x + aEnd.x ) / 2.0;
352 center.y = ( aStart.y + aEnd.y ) / 2.0 ;
353 return center;
354 }
355
356 // Prevent div=0 errors
357 if( xDelta_21 == 0.0 )
358 xDelta_21 = std::numeric_limits<double>::epsilon();
359
360 if( xDelta_32 == 0.0 )
361 xDelta_32 = -std::numeric_limits<double>::epsilon();
362
363 double aSlope = yDelta_21 / xDelta_21;
364 double bSlope = yDelta_32 / xDelta_32;
365
366 double daSlope = aSlope * VECTOR2D( 0.5 / yDelta_21, 0.5 / xDelta_21 ).EuclideanNorm();
367 double dbSlope = bSlope * VECTOR2D( 0.5 / yDelta_32, 0.5 / xDelta_32 ).EuclideanNorm();
368
369 if( aSlope == bSlope )
370 {
371 if( aStart == aEnd )
372 {
373 // This is a special case for a 360 degrees arc. In this case, the center is halfway between
374 // the midpoint and either end point
375 center.x = ( aStart.x + aMid.x ) / 2.0;
376 center.y = ( aStart.y + aMid.y ) / 2.0 ;
377 return center;
378 }
379 else
380 {
381 // If the points are colinear, the center is at infinity, so offset
382 // the slope by a minimal amount
383 // Warning: This will induce a small error in the center location
384 aSlope += std::numeric_limits<double>::epsilon();
385 bSlope -= std::numeric_limits<double>::epsilon();
386 }
387 }
388
389 // Prevent divide by zero error
390 if( aSlope == 0.0 )
391 aSlope = std::numeric_limits<double>::epsilon();
392
393 // What follows is the calculation of the center using the slope of the two lines as well as
394 // the propagated error that occurs when rounding to the nearest nanometer. The error can be
395 // ±0.5 units but can add up to multiple nanometers after the full calculation is performed.
396 // All variables starting with `d` are the delta of that variable. This is approximately equal
397 // to the standard deviation.
398 // We ignore the possible covariance between variables. We also truncate our series expansion
399 // at the first term. These are reasonable assumptions as the worst-case scenario is that we
400 // underestimate the potential uncertainty, which would potentially put us back at the status quo
401 double abSlopeStartEndY = aSlope * bSlope * ( aStart.y - aEnd.y );
402 double dabSlopeStartEndY = abSlopeStartEndY * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
403 + ( dbSlope / bSlope * dbSlope / bSlope )
404 + ( M_SQRT1_2 / ( aStart.y - aEnd.y )
405 * M_SQRT1_2 / ( aStart.y - aEnd.y ) ) );
406
407 double bSlopeStartMidX = bSlope * ( aStart.x + aMid.x );
408 double dbSlopeStartMidX = bSlopeStartMidX * std::sqrt( ( dbSlope / bSlope * dbSlope / bSlope )
409 + ( M_SQRT1_2 / ( aStart.x + aMid.x )
410 * M_SQRT1_2 / ( aStart.x + aMid.x ) ) );
411
412 double aSlopeMidEndX = aSlope * ( aMid.x + aEnd.x );
413 double daSlopeMidEndX = aSlopeMidEndX * std::sqrt( ( daSlope / aSlope * daSlope / aSlope )
414 + ( M_SQRT1_2 / ( aMid.x + aEnd.x )
415 * M_SQRT1_2 / ( aMid.x + aEnd.x ) ) );
416
417 double twiceBASlopeDiff = 2 * ( bSlope - aSlope );
418 double dtwiceBASlopeDiff = 2 * std::sqrt( dbSlope * dbSlope + daSlope * daSlope );
419
420 double centerNumeratorX = abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX;
421 double dCenterNumeratorX = std::sqrt( dabSlopeStartEndY * dabSlopeStartEndY
422 + dbSlopeStartMidX * dbSlopeStartMidX
423 + daSlopeMidEndX * daSlopeMidEndX );
424
425 double centerX = ( abSlopeStartEndY + bSlopeStartMidX - aSlopeMidEndX ) / twiceBASlopeDiff;
426
427 double dCenterX = centerX * std::sqrt( ( dCenterNumeratorX / centerNumeratorX * dCenterNumeratorX / centerNumeratorX )
428 + ( dtwiceBASlopeDiff / twiceBASlopeDiff * dtwiceBASlopeDiff / twiceBASlopeDiff ) );
429
430
431 double centerNumeratorY = ( ( aStart.x + aMid.x ) / 2.0 - centerX );
432 double dCenterNumeratorY = std::sqrt( 1.0 / 8.0 + dCenterX * dCenterX );
433
434 double centerFirstTerm = centerNumeratorY / aSlope;
435 double dcenterFirstTermY = centerFirstTerm * std::sqrt(
436 ( dCenterNumeratorY/ centerNumeratorY * dCenterNumeratorY / centerNumeratorY )
437 + ( daSlope / aSlope * daSlope / aSlope ) );
438
439 double centerY = centerFirstTerm + ( aStart.y + aMid.y ) / 2.0;
440 double dCenterY = std::sqrt( dcenterFirstTermY * dcenterFirstTermY + 1.0 / 8.0 );
441
442 double rounded100CenterX = std::floor( ( centerX + 50.0 ) / 100.0 ) * 100.0;
443 double rounded100CenterY = std::floor( ( centerY + 50.0 ) / 100.0 ) * 100.0;
444 double rounded10CenterX = std::floor( ( centerX + 5.0 ) / 10.0 ) * 10.0;
445 double rounded10CenterY = std::floor( ( centerY + 5.0 ) / 10.0 ) * 10.0;
446
447 // The last step is to find the nice, round numbers near our baseline estimate and see if they are within our uncertainty
448 // range. If they are, then we use this round value as the true value. This is justified because ALL values within the
449 // uncertainty range are equally true. Using a round number will make sure that we are on a multiple of 1mil or 100nm
450 // when calculating centers.
451 if( std::abs( rounded100CenterX - centerX ) < dCenterX && std::abs( rounded100CenterY - centerY ) < dCenterY )
452 {
453 center.x = rounded100CenterX;
454 center.y = rounded100CenterY;
455 }
456 else if( std::abs( rounded10CenterX - centerX ) < dCenterX && std::abs( rounded10CenterY - centerY ) < dCenterY )
457 {
458 center.x = rounded10CenterX;
459 center.y = rounded10CenterY;
460 }
461 else
462 {
463 center.x = centerX;
464 center.y = centerY;
465 }
466
467
468 return center;
469}
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401

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

◆ CalcArcCenter() [3/3]

const VECTOR2I CalcArcCenter ( const VECTOR2I aStart,
const VECTOR2I aMid,
const VECTOR2I aEnd 
)

Determine the center of an arc or circle given three points on its circumference.

Parameters
aStartThe starting point of the circle (equivalent to aEnd)
aMidThe point on the arc, half-way between aStart and aEnd
aEndThe ending point of the circle (equivalent to aStart)
Returns
The center of the circle

Definition at line 472 of file trigo.cpp.

473{
474 VECTOR2D dStart( static_cast<double>( aStart.x ), static_cast<double>( aStart.y ) );
475 VECTOR2D dMid( static_cast<double>( aMid.x ), static_cast<double>( aMid.y ) );
476 VECTOR2D dEnd( static_cast<double>( aEnd.x ), static_cast<double>( aEnd.y ) );
477 VECTOR2D dCenter = CalcArcCenter( dStart, dMid, dEnd );
478
479 VECTOR2I iCenter;
480
481 iCenter.x = KiROUND( Clamp<double>( double( std::numeric_limits<int>::min() / 2.0 ),
482 dCenter.x,
483 double( std::numeric_limits<int>::max() / 2.0 ) ) );
484
485 iCenter.y = KiROUND( Clamp<double>( double( std::numeric_limits<int>::min() / 2.0 ),
486 dCenter.y,
487 double( std::numeric_limits<int>::max() / 2.0 ) ) );
488
489 return iCenter;
490}
const VECTOR2D CalcArcCenter(const VECTOR2D &aStart, const VECTOR2D &aEnd, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:301
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80

References CalcArcCenter(), KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SHAPE_ARC::ConstructFromStartEndAngle(), SHAPE_ARC::GetCenter(), PCB_ARC::GetPosition(), PCB_ARC::GetRadius(), SCH_LEGACY_PLUGIN_CACHE::loadArc(), SCH_SEXPR_PARSER::parseArc(), EDA_SHAPE::SetArcGeometry(), FP_SHAPE::SetArcGeometry0(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().

◆ CalcArcMid()

const VECTOR2I CalcArcMid ( const VECTOR2I aStart,
const VECTOR2I aEnd,
const VECTOR2I aCenter,
bool  aMinArcAngle = true 
)

Return the middle point of an arc, half-way between aStart and aEnd.

There are two possible solutions which can be found by toggling aMinArcAngle. The behaviour is undefined for semicircles (i.e. 180 degree arcs).

Parameters
aStartThe starting point of the arc (for calculating the radius)
aEndThe end point of the arc (for determining the arc angle)
aCenterThe center point of the arc
aMinArcAngleIf true, returns the point that results in the smallest arc angle.
Returns
The middle point of the arc

Definition at line 163 of file trigo.cpp.

165{
166 VECTOR2I startVector = aStart - aCenter;
167 VECTOR2I endVector = aEnd - aCenter;
168
169 EDA_ANGLE startAngle( startVector );
170 EDA_ANGLE endAngle( endVector );
171 EDA_ANGLE midPointRotAngle = ( startAngle - endAngle ).Normalize180() / 2;
172
173 if( !aMinArcAngle )
174 midPointRotAngle += ANGLE_180;
175
176 VECTOR2I newMid = aStart;
177 RotatePoint( newMid, aCenter, midPointRotAngle );
178
179 return newMid;
180}

References ANGLE_180, and RotatePoint().

Referenced by CIRCLE::ConstructFromTanTanPt(), EDIT_TOOL::DragArcTrack(), and SCH_EAGLE_PLUGIN::loadSymbolWire().

◆ DEG2RAD()

◆ DistanceLinePoint()

double DistanceLinePoint ( const VECTOR2I linePointA,
const VECTOR2I linePointB,
const VECTOR2I referencePoint 
)
inline

Compute the distance between a line and a reference point Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html.

Parameters
linePointAPoint on line
linePointBPoint on line
referencePointReference point

Definition at line 140 of file trigo.h.

142{
143 // Some of the multiple double casts are redundant. However in the previous definition
144 // the cast was (implicitly) done too late, just before the division (EuclideanNorm gives
145 // a double so from int it would be promoted); that means that the whole expression were
146 // vulnerable to overflow during int multiplications
147 return fabs( ( static_cast<double>( linePointB.x - linePointA.x ) *
148 static_cast<double>( linePointA.y - referencePoint.y ) -
149 static_cast<double>( linePointA.x - referencePoint.x ) *
150 static_cast<double>( linePointB.y - linePointA.y) )
151 / EuclideanNorm( linePointB - linePointA ) );
152}

References EuclideanNorm(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EE_POINT_EDITOR::addCorner(), and EE_SELECTION_TOOL::GuessSelectionCandidates().

◆ EuclideanNorm()

double EuclideanNorm ( const VECTOR2I vector)
inline

Definition at line 129 of file trigo.h.

130{
131 // this is working with doubles
132 return hypot( vector.x, vector.y );
133}

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

Referenced by PCB_GRID_HELPER::AlignToArc(), PCB_GRID_HELPER::AlignToSegment(), PLOTTER::Arc(), HPGL_PLOTTER::Arc(), PS_PLOTTER::Arc(), PDF_PLOTTER::Arc(), EE_GRID_HELPER::BestSnapAnchor(), BOOST_AUTO_TEST_CASE(), BuildCornersList_S_Shape(), PNS::DP_GATEWAYS::buildDpContinuation(), PNS::DP_GATEWAYS::BuildFromPrimitivePair(), PNS::DP_GATEWAYS::BuildGeneric(), PNS::DP_GATEWAYS::BuildOrthoProjections(), CalcArcCenter(), PNS::DRAGGER::checkVirtualVia(), EE_SELECTION_TOOL::CollectHits(), SHAPE_ARC::Collide(), collideArc2Arc(), PCB_GRID_HELPER::computeAnchors(), CIRCLE::ConstructFromTanTanPt(), CIRCLE::Contains(), AM_PRIMITIVE::ConvertShapeToPolygon(), MICROWAVE_TOOL::createMicrowaveInductor(), PNS::cursorDistMinimum(), DistanceLinePoint(), EDIT_TOOL::DragArcTrack(), KIGFX::SCH_PAINTER::draw(), KIGFX::CAIRO_GAL_BASE::DrawSegment(), DRAWING_TOOL::DrawVia(), PCB_POINT_EDITOR::editArcMidKeepEndpoints(), PAD_TOOL::EnumeratePads(), extractDiffPairCoupledItems(), PNS::findCoupledVertices(), PNS::DIFF_PAIR_PLACER::FindDpPrimitivePair(), gen_arc(), PAD::GetBestAnchorPosition(), EE_SELECTION_TOOL::GetNode(), SCH_LINE::GetSelectMenuText(), DS_DRAW_ITEM_LINE::GetSelectMenuText(), FP_TEXTBOX::GetShownText(), PCB_TEXTBOX::GetShownText(), BOARD::GetTrackLength(), EE_SELECTION_TOOL::GuessSelectionCandidates(), ALTIUM_PCB::HelperParseDimensions6Leader(), ALTIUM_PCB::HelperParseDimensions6Linear(), EDA_SHAPE::hitTest(), PCB_ARC::HitTest(), SHAPE_LINE_CHAIN::Intersect(), CIRCLE::IntersectLine(), GEOM_TEST::IsPointAtDistance(), PNS::makeGapVector(), PNS::MEANDERED_LINE::MeanderSegment(), LABEL_MANAGER::nearestBoxCorner(), AR_AUTOPLACER::nearestPad(), PNS::TOPOLOGY::NearestUnconnectedItem(), VECTOR3< T >::Normalize(), SHAPE_LINE_CHAIN::compareOriginDistance::operator()(), compareOriginDistance::operator()(), GPCB_FPL_CACHE::parseFOOTPRINT(), SHAPE_LINE_CHAIN::PathLength(), pushoutForce(), PNS::LINE_PLACER::rhMarkObstacles(), PNS::DIFF_PAIR_PLACER::routeHead(), DRC_TEST_PROVIDER_CONNECTION_WIDTH::Run(), PLOTTER::segmentAsOval(), GEOM_TEST::SegmentCompletelyWithinRadius(), PNS::LINE::snapDraggedCorner(), PNS::DRAGGER::startDragSegment(), DRC_TEST_PROVIDER_HOLE_TO_HOLE::testHoleAgainstHole(), DRC_TEST_PROVIDER_PHYSICAL_CLEARANCE::testShapeLineChain(), PLOTTER::ThickArc(), GERBER_PLOTTER::ThickArc(), TransformOvalToPolygon(), PCB_POINT_EDITOR::updateItem(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::Validate().

◆ GetLineLength()

double GetLineLength ( const VECTOR2I aPointA,
const VECTOR2I aPointB 
)
inline

Return the length of a line segment defined by aPointA and aPointB.

See also EuclideanNorm and Distance for the single vector or four scalar versions.

Returns
Length of a line (as double)

Definition at line 188 of file trigo.h.

189{
190 // Implicitly casted to double
191 return hypot( aPointA.x - aPointB.x, aPointA.y - aPointB.y );
192}

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

Referenced by EDA_SHAPE::calcEdit(), EDIT_TOOL::DragArcTrack(), KIGFX::GERBVIEW_PAINTER::draw(), FootprintWriteShape(), GERBER_DRAW_ITEM::GetBoundingBox(), SCH_LINE::GetLength(), EDA_SHAPE::GetLength(), PCB_TRACK::GetLength(), getMinDist(), EDA_SHAPE::GetRadius(), PCB_ARC::GetRadius(), HelperShapeLineChainFromAltiumVertices(), GERBER_DRAW_ITEM::HitTest(), PCB_TRACK::IsPointOnEnds(), EAGLE_PLUGIN::loadPlain(), BRDITEMS_PLOTTER::PlotFootprintShape(), GERBER_DRAW_ITEM::Print(), EDA_SHAPE::ShapeGetMsgPanelInfo(), and GERBER_DRAW_ITEM::ViewGetLOD().

◆ HitTestPoints()

bool HitTestPoints ( const VECTOR2I pointA,
const VECTOR2I pointB,
double  threshold 
)
inline

Test, if two points are near each other.

Parameters
pointAFirst point
pointBSecond point
thresholdThe maximum distance
Returns
True or false

Definition at line 159 of file trigo.h.

160{
161 VECTOR2I vectorAB = pointB - pointA;
162
163 // Compare the distances squared. The double is needed to avoid overflow during int
164 // multiplication
165 double sqdistance = (double)vectorAB.x * vectorAB.x + (double)vectorAB.y * vectorAB.y;
166
167 return sqdistance < threshold * threshold;
168}

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

Referenced by GERBER_DRAW_ITEM::HitTest(), and EE_SELECTION_TOOL::selectPoint().

◆ InterceptsNegativeX()

bool InterceptsNegativeX ( double  aStartAngle,
double  aEndAngle 
)
inline

Test if an arc from aStartAngle to aEndAngle crosses the negative X axis (180 degrees).

Testing is performed in the quadrant 1 to quadrant 4 direction (counter-clockwise).

Parameters
aStartAngleThe arc start angle in degrees.
aEndAngleThe arc end angle in degrees.

Definition at line 258 of file trigo.h.

259{
260 double end = aEndAngle;
261
262 if( aStartAngle > aEndAngle )
263 end += 360.0;
264
265 return aStartAngle < 180.0 && end > 180.0;
266}

Referenced by BOOST_AUTO_TEST_CASE().

◆ InterceptsPositiveX()

bool InterceptsPositiveX ( double  aStartAngle,
double  aEndAngle 
)
inline

Test if an arc from aStartAngle to aEndAngle crosses the positive X axis (0 degrees).

Testing is performed in the quadrant 1 to quadrant 4 direction (counter-clockwise).

Parameters
aStartAngleThe arc start angle in degrees.
aEndAngleThe arc end angle in degrees.

Definition at line 240 of file trigo.h.

241{
242 double end = aEndAngle;
243
244 if( aStartAngle > aEndAngle )
245 end += 360.0;
246
247 return aStartAngle < 360.0 && end > 360.0;
248}

Referenced by BOOST_AUTO_TEST_CASE().

◆ IsPointOnSegment()

bool IsPointOnSegment ( const VECTOR2I aSegStart,
const VECTOR2I aSegEnd,
const VECTOR2I aTestPoint 
)

Test if aTestPoint is on line defined by aSegStart and aSegEnd.

This function is faster than TestSegmentHit() because aTestPoint should be exactly on the line. This works fine only for H, V and 45 degree line segments.

Parameters
aSegStartThe first point of the line segment.
aSegEndThe second point of the line segment.
aTestPointThe point to test.
Returns
true if the point is on the line segment.

Definition at line 42 of file trigo.cpp.

44{
45 VECTOR2I vectSeg = aSegEnd - aSegStart; // Vector from S1 to S2
46 VECTOR2I vectPoint = aTestPoint - aSegStart; // Vector from S1 to P
47
48 // Use long long here to avoid overflow in calculations
49 if( (long long) vectSeg.x * vectPoint.y - (long long) vectSeg.y * vectPoint.x )
50 return false; /* Cross product non-zero, vectors not parallel */
51
52 if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
53 ( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
54 return false; /* Point not on segment */
55
56 return true;
57}

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

Referenced by SCH_LINE_WIRE_BUS_TOOL::AddJunctionsIfNeeded(), SCH_EDIT_FRAME::BreakSegments(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires(), SCH_EDIT_FRAME::TrimWire(), SCH_BUS_WIRE_ENTRY::UpdateDanglingState(), and SCH_BUS_BUS_ENTRY::UpdateDanglingState().

◆ NORMALIZE_ANGLE_POS()

template<class T >
void NORMALIZE_ANGLE_POS ( T &  Angle)
inline

Definition at line 214 of file trigo.h.

215{
216 Angle = NormalizeAnglePos( Angle );
217}
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:205

References NormalizeAnglePos().

◆ NormalizeAngle180()

template<class T >
T NormalizeAngle180 ( Angle)
inline

Normalize angle to be in the -180.0 .. 180.0 range.

Definition at line 221 of file trigo.h.

222{
223 while( Angle <= -1800 )
224 Angle += 3600;
225
226 while( Angle > 1800 )
227 Angle -= 3600;
228
229 return Angle;
230}

Referenced by DIALOG_COPPER_ZONE::AcceptOptions().

◆ NormalizeAnglePos()

template<class T >
T NormalizeAnglePos ( Angle)
inline

Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.

Definition at line 205 of file trigo.h.

206{
207 while( Angle < 0 )
208 Angle += 3600;
209 while( Angle >= 3600 )
210 Angle -= 3600;
211 return Angle;
212}

Referenced by PCB_PLUGIN::format(), and NORMALIZE_ANGLE_POS().

◆ RAD2DECIDEG()

double RAD2DECIDEG ( double  rad)
inline

Definition at line 199 of file trigo.h.

199{ return rad * 1800.0 / M_PI; }

◆ RAD2DEG()

double RAD2DEG ( double  rad)
inline

Definition at line 196 of file trigo.h.

196{ return rad * 180.0 / M_PI; }

Referenced by GBR_TO_PCB_EXPORTER::export_non_copper_item(), and PCB_BASE_FRAME::UpdateStatusBar().

◆ RotatePoint() [1/8]

void RotatePoint ( double *  pX,
double *  pY,
const EDA_ANGLE aAngle 
)

Definition at line 263 of file trigo.cpp.

264{
265 EDA_ANGLE angle = aAngle;
266 VECTOR2D pt;
267
268 angle.Normalize();
269
270 // Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
271 if( angle == ANGLE_0 )
272 {
273 pt = VECTOR2D( *pX, *pY );
274 }
275 else if( angle == ANGLE_90 ) /* sin = 1, cos = 0 */
276 {
277 pt = VECTOR2D( *pY, -*pX );
278 }
279 else if( angle == ANGLE_180 ) /* sin = 0, cos = -1 */
280 {
281 pt = VECTOR2D( -*pX, -*pY );
282 }
283 else if( angle == ANGLE_270 ) /* sin = -1, cos = 0 */
284 {
285 pt = VECTOR2D( -*pY, *pX );
286 }
287 else
288 {
289 double sinus = angle.Sin();
290 double cosinus = angle.Cos();
291
292 pt.x = ( *pY * sinus ) + ( *pX * cosinus );
293 pt.y = ( *pY * cosinus ) - ( *pX * sinus );
294 }
295
296 *pX = pt.x;
297 *pY = pt.y;
298}
static constexpr EDA_ANGLE & ANGLE_270
Definition: eda_angle.h:417

References PNS::angle(), ANGLE_0, ANGLE_180, ANGLE_270, ANGLE_90, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ RotatePoint() [2/8]

void RotatePoint ( double *  pX,
double *  pY,
double  cx,
double  cy,
const EDA_ANGLE aAngle 
)

Definition at line 249 of file trigo.cpp.

250{
251 double ox, oy;
252
253 ox = *pX - cx;
254 oy = *pY - cy;
255
256 RotatePoint( &ox, &oy, angle );
257
258 *pX = ox + cx;
259 *pY = oy + cy;
260}

References PNS::angle(), and RotatePoint().

◆ RotatePoint() [3/8]

void RotatePoint ( int *  pX,
int *  pY,
const EDA_ANGLE aAngle 
)

Definition at line 183 of file trigo.cpp.

184{
185 VECTOR2I pt;
186 EDA_ANGLE angle = aAngle;
187
188 angle.Normalize();
189
190 // Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
191 if( angle == ANGLE_0 )
192 {
193 pt = VECTOR2I( *pX, *pY );
194 }
195 else if( angle == ANGLE_90 ) /* sin = 1, cos = 0 */
196 {
197 pt = VECTOR2I( *pY, -*pX );
198 }
199 else if( angle == ANGLE_180 ) /* sin = 0, cos = -1 */
200 {
201 pt = VECTOR2I( -*pX, -*pY );
202 }
203 else if( angle == ANGLE_270 ) /* sin = -1, cos = 0 */
204 {
205 pt = VECTOR2I( -*pY, *pX );
206 }
207 else
208 {
209 double sinus = angle.Sin();
210 double cosinus = angle.Cos();
211
212 pt.x = KiROUND( ( *pY * sinus ) + ( *pX * cosinus ) );
213 pt.y = KiROUND( ( *pY * cosinus ) - ( *pX * sinus ) );
214 }
215
216 *pX = pt.x;
217 *pY = pt.y;
218}
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References PNS::angle(), ANGLE_0, ANGLE_180, ANGLE_270, ANGLE_90, KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by DXF_IMPORT_PLUGIN::addArc(), GRAPHICS_IMPORTER_PCBNEW::AddArc(), CADSTAR_PCB_ARCHIVE_LOADER::addAttribute(), PCAD2KICAD::PCB_FOOTPRINT::AddToBoard(), PCAD2KICAD::PCB_PAD::AddToFootprint(), EC_CIRCLE::Apply(), CADSTAR_SCH_ARCHIVE_LOADER::applyTransform(), SVG_PLOTTER::Arc(), PDF_PLOTTER::Arc(), BuildConvexHull(), BuildCornersList_S_Shape(), PAD::BuildEffectiveShapes(), DIRECTION_45::BuildInitialTrace(), CalcArcCenter(), CalcArcMid(), EDA_SHAPE::calcEdit(), PNS::OPTIMIZER::circleBreakouts(), PCB_GRID_HELPER::computeAnchors(), computeCenter(), PSLIKE_PLOTTER::computeTextParameters(), SHAPE_ARC::ConstructFromStartEndAngle(), SHAPE_ARC::ConstructFromStartEndCenter(), ConvertOutlineToPolygon(), D_CODE::ConvertShapeToPolygon(), AM_PRIMITIVE::ConvertShapeToPolygon(), CornerListToPolygon(), PCAD2KICAD::CorrectTextPosition(), EXCELLON_WRITER::createDrillFile(), MICROWAVE_TOOL::createFootprint(), SCH_GLOBALLABEL::CreateGraphicShape(), SCH_DIRECTIVE_LABEL::CreateGraphicShape(), PNS::OPTIMIZER::customBreakouts(), KIGFX::SCH_PAINTER::draw(), KIGFX::CAIRO_GAL_BASE::DrawArcSegment(), drawBacksideTicks(), AM_PRIMITIVE::DrawBasicShape(), CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText(), DrawHalfOpenCylinder(), AR_MATRIX::drawSegmentQcq(), drawTicksAlongLine(), GBR_TO_PCB_EXPORTER::export_segarc_copper_item(), EXPORTER_PCB_VRML::ExportVrmlFootprint(), fillArcPOLY(), CADSTAR_ARCHIVE_PARSER::FixTextPositionNoAlignment(), GERBER_PLOTTER::FlashPadChamferRoundRect(), GERBER_PLOTTER::FlashPadCustom(), HPGL_PLOTTER::FlashPadOval(), PSLIKE_PLOTTER::FlashPadOval(), HPGL_PLOTTER::FlashPadRect(), PSLIKE_PLOTTER::FlashPadRect(), DXF_PLOTTER::FlashPadRect(), DXF_PLOTTER::FlashPadTrapez(), GERBER_PLOTTER::FlashPadTrapez(), HPGL_PLOTTER::FlashPadTrapez(), PSLIKE_PLOTTER::FlashPadTrapez(), GERBER_PLOTTER::FlashRegularPolygon(), GERBER_DRAW_ITEM::GetABPosition(), EDA_SHAPE::GetArcMid(), FP_SHAPE::GetArcMid0(), SCH_LABEL::GetBodyBoundingBox(), EDA_SHAPE::getBoundingBox(), LIB_FIELD::GetBoundingBox(), LIB_TEXT::GetBoundingBox(), SCH_FIELD::GetBoundingBox(), SCH_TEXT::GetBoundingBox(), LIB_PIN::GetBoundingBox(), BOX2< Vec >::GetBoundingBoxRotated(), DS_DATA_ITEM_POLYGONS::GetCornerPosition(), FP_TEXTBOX::GetDrawPos(), PCB_TEXTBOX::GetDrawPos(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetEndRadiusEnd(), CADSTAR_PCB_ARCHIVE_LOADER::getKiCadPad(), EDA_TEXT::GetLinePositions(), CADSTAR_SCH_ARCHIVE_LOADER::getLocationOfNetElement(), getRectangleAlongCentreLine(), EDA_SHAPE::GetRectCorners(), KIGFX::PREVIEW::ARC_GEOM_MANAGER::GetStartRadiusEnd(), KIFONT::OUTLINE_FONT::getTextAsGlyphs(), ARRAY_CIRCULAR_OPTIONS::GetTransform(), GERBER_DRAW_ITEM::GetXYPosition(), GRCSegm(), ALTIUM_PCB::HelperParseDimensions6Center(), ALTIUM_PCB::HelperParseDimensions6Leader(), idf_export_footprint(), ROUTER_TOOL::InlineDrag(), RENDER_3D_RAYTRACE::insertHole(), CIRCLE::Intersect(), BOX2< Vec >::Intersects(), LEGACY_PLUGIN::loadPAD(), EAGLE_PLUGIN::loadPlain(), CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances(), SCH_EAGLE_PLUGIN::loadSymbolRectangle(), CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary(), FOOTPRINT::MoveAnchorPosition(), EAGLE_PLUGIN::packageCircle(), SCH_ALTIUM_PLUGIN::ParseArc(), ALTIUM_PCB::ParseComponentsBodies6Data(), GPCB_FPL_CACHE::parseFOOTPRINT(), PCB_PARSER::parseFOOTPRINT_unchecked(), SCH_TEXT::Plot(), BRDITEMS_PLOTTER::PlotFootprintShape(), GERBER_PLOTTER::plotRoundRectAsRegion(), SCH_TEXT::Print(), FABMASTER::processArc(), SHAPE_ARC::Rotate(), SHAPE_LINE_CHAIN::Rotate(), EDIT_TOOL::Rotate(), SCH_BITMAP::Rotate(), SCH_BUS_ENTRY_BASE::Rotate(), SCH_FIELD::Rotate(), SCH_JUNCTION::Rotate(), SCH_LABEL_BASE::Rotate(), SCH_LINE::Rotate(), SCH_NO_CONNECT::Rotate(), SCH_SHEET::Rotate(), SCH_SHEET_PIN::Rotate(), SCH_SYMBOL::Rotate(), SCH_TEXT::Rotate(), LIB_FIELD::Rotate(), LIB_PIN::Rotate(), LIB_TEXT::Rotate(), PCB_BITMAP::Rotate(), FP_TEXT::Rotate(), EDA_SHAPE::rotate(), FOOTPRINT::Rotate(), PAD::Rotate(), PCB_DIMENSION_BASE::Rotate(), PCB_TARGET::Rotate(), PCB_TEXT::Rotate(), PCB_TRACK::Rotate(), PCB_ARC::Rotate(), SCH_LABEL_BASE::Rotate90(), SCH_LINE::RotateEnd(), RotatePoint(), SCH_LINE::RotateStart(), EDA_SHAPE::SetArcAngleAndEnd(), FP_SHAPE::SetArcAngleAndEnd0(), DS_DATA_ITEM_POLYGONS::SetBoundingBox(), FP_SHAPE::SetDrawCoord(), FP_TEXT::SetDrawCoord(), PAD::SetDrawCoord(), FP_SHAPE::SetLocalCoord(), FP_TEXT::SetLocalCoord(), PAD::SetLocalCoord(), SHAPE_ARC::SHAPE_ARC(), PAD::ShapePos(), PLOTTER::sketchOval(), PNS_KICAD_IFACE_BASE::syncPad(), EDA_TEXT::TextHitTest(), FP_TEXT::TextHitTest(), AR_MATRIX::TraceFilledRectangle(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), EAGLE_PLUGIN::transferPad(), KIFONT::STROKE_GLYPH::Transform(), BOARD_ADAPTER::transformArcToSegments(), EDA_TEXT::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), TransformOvalToPolygon(), EDA_SHAPE::TransformShapeWithClearanceToPolygon(), PAD::TransformShapeWithClearanceToPolygon(), PNS::MEANDER_SHAPE::turn(), PCB_DIM_ALIGNED::updateGeometry(), PCB_DIM_ORTHOGONAL::updateGeometry(), PCB_DIM_RADIAL::updateGeometry(), PCB_DIM_LEADER::updateGeometry(), PCB_DIM_CENTER::updateGeometry(), PCB_POINT_EDITOR::updateItem(), PCB_DIM_ALIGNED::updateText(), and GERBER_PLOTTER::writeApertureList().

◆ RotatePoint() [4/8]

void RotatePoint ( int *  pX,
int *  pY,
int  cx,
int  cy,
const EDA_ANGLE aAngle 
)

Definition at line 221 of file trigo.cpp.

222{
223 int ox, oy;
224
225 ox = *pX - cx;
226 oy = *pY - cy;
227
228 RotatePoint( &ox, &oy, angle );
229
230 *pX = ox + cx;
231 *pY = oy + cy;
232}

References PNS::angle(), and RotatePoint().

◆ RotatePoint() [5/8]

void RotatePoint ( VECTOR2D point,
const EDA_ANGLE aAngle 
)
inline

Definition at line 89 of file trigo.h.

90{
91 RotatePoint( &point.x, &point.y, aAngle );
92}
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Definition: trigo.cpp:183

References RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ RotatePoint() [6/8]

void RotatePoint ( VECTOR2D point,
const VECTOR2D aCenter,
const EDA_ANGLE aAngle 
)
inline

Definition at line 97 of file trigo.h.

98{
99 RotatePoint( &point.x, &point.y, aCenter.x, aCenter.y, aAngle );
100}

References RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ RotatePoint() [7/8]

void RotatePoint ( VECTOR2I point,
const EDA_ANGLE aAngle 
)
inline

Definition at line 66 of file trigo.h.

67{
68 RotatePoint( &point.x, &point.y, aAngle );
69}

References RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ RotatePoint() [8/8]

void RotatePoint ( VECTOR2I point,
const VECTOR2I centre,
const EDA_ANGLE aAngle 
)
inline

Definition at line 77 of file trigo.h.

78{
79 RotatePoint( &point.x, &point.y, centre.x, centre.y, aAngle );
80}

References RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ SegmentIntersectsSegment()

bool SegmentIntersectsSegment ( const VECTOR2I a_p1_l1,
const VECTOR2I a_p2_l1,
const VECTOR2I a_p1_l2,
const VECTOR2I a_p2_l2,
VECTOR2I aIntersectionPoint = nullptr 
)

Test if two lines intersect.

Parameters
a_p1_l1The first point of the first line.
a_p2_l1The second point of the first line.
a_p1_l2The first point of the second line.
a_p2_l2The second point of the second line.
aIntersectionPointis filled with the intersection point if it exists
Returns
bool - true if the two segments defined by four points intersect. (i.e. if the 2 segments have at least a common point)

Definition at line 61 of file trigo.cpp.

64{
65
66 //We are forced to use 64bit ints because the internal units can overflow 32bit ints when
67 // multiplied with each other, the alternative would be to scale the units down (i.e. divide
68 // by a fixed number).
69 int64_t dX_a, dY_a, dX_b, dY_b, dX_ab, dY_ab;
70 int64_t num_a, num_b, den;
71
72 //Test for intersection within the bounds of both line segments using line equations of the
73 // form:
74 // x_k(u_k) = u_k * dX_k + x_k(0)
75 // y_k(u_k) = u_k * dY_k + y_k(0)
76 // with 0 <= u_k <= 1 and k = [ a, b ]
77
78 dX_a = int64_t{ a_p2_l1.x } - a_p1_l1.x;
79 dY_a = int64_t{ a_p2_l1.y } - a_p1_l1.y;
80 dX_b = int64_t{ a_p2_l2.x } - a_p1_l2.x;
81 dY_b = int64_t{ a_p2_l2.y } - a_p1_l2.y;
82 dX_ab = int64_t{ a_p1_l2.x } - a_p1_l1.x;
83 dY_ab = int64_t{ a_p1_l2.y } - a_p1_l1.y;
84
85 den = dY_a * dX_b - dY_b * dX_a ;
86
87 //Check if lines are parallel
88 if( den == 0 )
89 return false;
90
91 num_a = dY_ab * dX_b - dY_b * dX_ab;
92 num_b = dY_ab * dX_a - dY_a * dX_ab;
93
94 // Only compute the intersection point if requested
95 if( aIntersectionPoint )
96 {
97 *aIntersectionPoint = a_p1_l1;
98 aIntersectionPoint->x += KiROUND( dX_a * ( double )num_a / ( double )den );
99 aIntersectionPoint->y += KiROUND( dY_a * ( double )num_b / ( double )den );
100 }
101
102 if( den < 0 )
103 {
104 den = -den;
105 num_a = -num_a;
106 num_b = -num_b;
107 }
108
109 //Test sign( u_a ) and return false if negative
110 if( num_a < 0 )
111 return false;
112
113 //Test sign( u_b ) and return false if negative
114 if( num_b < 0 )
115 return false;
116
117 //Test to ensure (u_a <= 1)
118 if( num_a > den )
119 return false;
120
121 //Test to ensure (u_b <= 1)
122 if( num_b > den )
123 return false;
124
125 return true;
126}

References KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOX2< Vec >::Intersects().

◆ TestSegmentHit()

bool TestSegmentHit ( const VECTOR2I aRefPoint,
const VECTOR2I aStart,
const VECTOR2I aEnd,
int  aDist 
)

Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.

Parameters
aRefPoint= reference point to test
aStartis the first end-point of the line segment
aEndis the second end-point of the line segment
aDist= maximum distance for hit

Definition at line 129 of file trigo.cpp.

131{
132 int xmin = aStart.x;
133 int xmax = aEnd.x;
134 int ymin = aStart.y;
135 int ymax = aEnd.y;
136 VECTOR2I delta = aStart - aRefPoint;
137
138 if( xmax < xmin )
139 std::swap( xmax, xmin );
140
141 if( ymax < ymin )
142 std::swap( ymax, ymin );
143
144 // First, check if we are outside of the bounding box
145 if( ( ymin - aRefPoint.y > aDist ) || ( aRefPoint.y - ymax > aDist ) )
146 return false;
147
148 if( ( xmin - aRefPoint.x > aDist ) || ( aRefPoint.x - xmax > aDist ) )
149 return false;
150
151 // Next, eliminate easy cases
152 if( aStart.x == aEnd.x && aRefPoint.y > ymin && aRefPoint.y < ymax )
153 return std::abs( delta.x ) <= aDist;
154
155 if( aStart.y == aEnd.y && aRefPoint.x > xmin && aRefPoint.x < xmax )
156 return std::abs( delta.y ) <= aDist;
157
158 SEG segment( aStart, aEnd );
159 return segment.SquaredDistance( aRefPoint ) < SEG::Square( aDist + 1 );
160}
Definition: seg.h:42
static SEG::ecoord Square(int a)
Definition: seg.h:123
constexpr int delta

References std::abs(), delta, SEG::Square(), SEG::SquaredDistance(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SCH_EAGLE_PLUGIN::addBusEntries(), EE_GRID_HELPER::computeAnchors(), DRAWING_TOOL::DrawVia(), EDA_SHAPE::hitTest(), SCH_BUS_ENTRY_BASE::HitTest(), SCH_LINE::HitTest(), DS_DRAW_ITEM_LINE::HitTest(), DS_DRAW_ITEM_RECT::HitTest(), PCB_TRACK::HitTest(), GERBER_DRAW_ITEM::HitTest(), SCH_EAGLE_PLUGIN::moveLabels(), and SCH_LABEL_BASE::UpdateDanglingState().