KiCad PCB EDA Suite
Loading...
Searching...
No Matches
shape_nearest_points.cpp File Reference
#include <cmath>
#include <limits>
#include <geometry/seg.h>
#include <geometry/shape.h>
#include <geometry/shape_arc.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_circle.h>
#include <geometry/shape_rect.h>
#include <geometry/shape_segment.h>
#include <geometry/shape_compound.h>
#include <geometry/shape_poly_set.h>
#include <geometry/shape_simple.h>
#include <math/vector2d.h>

Go to the source code of this file.

Functions

static bool NearestPoints (const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between two circles.
 
static bool NearestPoints (const SHAPE_CIRCLE &aCircle, const SHAPE_RECT &aRect, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a circle and a rectangle.
 
static bool NearestPoints (const SHAPE_CIRCLE &aCircle, const SEG &aSeg, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a circle and a line segment.
 
static bool NearestPoints (const SHAPE_CIRCLE &aCircle, const SHAPE_LINE_CHAIN_BASE &aChain, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a circle and a line chain.
 
static bool NearestPoints (const SHAPE_RECT &aA, const SHAPE_RECT &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between two rectangles.
 
static bool NearestPoints (const SHAPE_RECT &aRect, const SEG &aSeg, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a rectangle and a segment.
 
static bool NearestPoints (const SHAPE_RECT &aRect, const SHAPE_LINE_CHAIN_BASE &aChain, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a rectangle and a line chain.
 
static bool NearestPoints (const SEG &aA, const SEG &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between two segments.
 
static bool NearestPoints (const SEG &aSeg, const SHAPE_LINE_CHAIN_BASE &aChain, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between a segment and a line chain.
 
static bool NearestPoints (const SHAPE_LINE_CHAIN_BASE &aA, const SHAPE_LINE_CHAIN_BASE &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between two line chains.
 
static bool NearestPoints (const SHAPE_ARC &aArc, const SHAPE_CIRCLE &aCircle, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find the nearest points between an arc and other shapes.
 
static bool NearestPoints (const SHAPE_ARC &aArc, const SHAPE_RECT &aRect, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_ARC &aArc, const SHAPE_SEGMENT &aSeg, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_ARC &aArcA, const SHAPE_ARC &aArcB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_ARC &aArc, const SHAPE_LINE_CHAIN_BASE &aChain, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_SEGMENT &aSeg, const SHAPE_CIRCLE &aCircle, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Find nearest points between SHAPE_SEGMENT and other shapes.
 
static bool NearestPoints (const SHAPE_SEGMENT &aSeg, const SHAPE_RECT &aRect, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_SEGMENT &aSegA, const SHAPE_SEGMENT &aSegB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool NearestPoints (const SHAPE_SEGMENT &aSeg, const SHAPE_LINE_CHAIN_BASE &aChain, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
template<class T_a, class T_b>
bool NearestPointsCase (const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Template functions to handle shape conversions and reversals.
 
template<class T_a, class T_b>
bool NearestPointsCaseReversed (const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 
static bool nearestPointsSingleShapes (const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Main dispatcher for finding nearest points between arbitrary shapes.
 
static bool nearestPoints (const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
 Handle compound shapes by finding nearest points between all sub-shape pairs.
 

Function Documentation

◆ NearestPoints() [1/19]

static bool NearestPoints ( const SEG & aA,
const SEG & aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between two segments.

Definition at line 293 of file shape_nearest_points.cpp.

References SEG::NearestPoint().

◆ NearestPoints() [2/19]

static bool NearestPoints ( const SEG & aSeg,
const SHAPE_LINE_CHAIN_BASE & aChain,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between a segment and a line chain.

Definition at line 306 of file shape_nearest_points.cpp.

References SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), and NearestPoints().

◆ NearestPoints() [3/19]

static bool NearestPoints ( const SHAPE_ARC & aArc,
const SHAPE_CIRCLE & aCircle,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between an arc and other shapes.

Uses the arc's built-in NearestPoints methods.

Definition at line 438 of file shape_nearest_points.cpp.

References SHAPE_ARC::NearestPoints().

◆ NearestPoints() [4/19]

static bool NearestPoints ( const SHAPE_ARC & aArc,
const SHAPE_LINE_CHAIN_BASE & aChain,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [5/19]

static bool NearestPoints ( const SHAPE_ARC & aArc,
const SHAPE_RECT & aRect,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Definition at line 445 of file shape_nearest_points.cpp.

References SHAPE_ARC::NearestPoints().

◆ NearestPoints() [6/19]

static bool NearestPoints ( const SHAPE_ARC & aArc,
const SHAPE_SEGMENT & aSeg,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [7/19]

static bool NearestPoints ( const SHAPE_ARC & aArcA,
const SHAPE_ARC & aArcB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Definition at line 459 of file shape_nearest_points.cpp.

References SHAPE_ARC::NearestPoints().

◆ NearestPoints() [8/19]

static bool NearestPoints ( const SHAPE_CIRCLE & aA,
const SHAPE_CIRCLE & aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between two circles.

Parameters
aAfirst circle
aBsecond circle
aPtA[out] nearest point on first circle
aPtB[out] nearest point on second circle
Returns
true (circles always have nearest points)

Definition at line 51 of file shape_nearest_points.cpp.

References delta, SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), and VECTOR2< T >::Resize().

Referenced by NearestPoints(), NearestPoints(), NearestPoints(), NearestPoints(), NearestPoints(), NearestPoints(), NearestPoints(), NearestPointsCase(), and NearestPointsCaseReversed().

◆ NearestPoints() [9/19]

static bool NearestPoints ( const SHAPE_CIRCLE & aCircle,
const SEG & aSeg,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between a circle and a line segment.

Parameters
aCirclethe circle
aSegthe segment
aPtA[out] nearest point on circle
aPtB[out] nearest point on segment
Returns
true (always succeeds)

Definition at line 146 of file shape_nearest_points.cpp.

References SEG::A, SEG::B, SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), and SEG::NearestPoint().

◆ NearestPoints() [10/19]

static bool NearestPoints ( const SHAPE_CIRCLE & aCircle,
const SHAPE_LINE_CHAIN_BASE & aChain,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between a circle and a line chain.

Definition at line 170 of file shape_nearest_points.cpp.

References SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), and NearestPoints().

◆ NearestPoints() [11/19]

static bool NearestPoints ( const SHAPE_CIRCLE & aCircle,
const SHAPE_RECT & aRect,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between a circle and a rectangle.

Parameters
aCirclethe circle
aRectthe rectangle
aPtA[out] nearest point on circle
aPtB[out] nearest point on rectangle
Returns
true (always succeeds)

Definition at line 84 of file shape_nearest_points.cpp.

References SHAPE_CIRCLE::GetCenter(), SHAPE_RECT::GetPosition(), SHAPE_CIRCLE::GetRadius(), SHAPE_RECT::GetSize(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ NearestPoints() [12/19]

static bool NearestPoints ( const SHAPE_LINE_CHAIN_BASE & aA,
const SHAPE_LINE_CHAIN_BASE & aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [13/19]

static bool NearestPoints ( const SHAPE_RECT & aA,
const SHAPE_RECT & aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between two rectangles.

Definition at line 197 of file shape_nearest_points.cpp.

References SHAPE_LINE_CHAIN::CSegment(), SEG::NearestPoint(), SHAPE_RECT::Outline(), and SHAPE_LINE_CHAIN::SegmentCount().

◆ NearestPoints() [14/19]

static bool NearestPoints ( const SHAPE_RECT & aRect,
const SEG & aSeg,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find the nearest points between a rectangle and a segment.

Definition at line 233 of file shape_nearest_points.cpp.

References SHAPE_LINE_CHAIN::CSegment(), SEG::NearestPoint(), SHAPE_RECT::Outline(), and SHAPE_LINE_CHAIN::SegmentCount().

◆ NearestPoints() [15/19]

static bool NearestPoints ( const SHAPE_RECT & aRect,
const SHAPE_LINE_CHAIN_BASE & aChain,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [16/19]

static bool NearestPoints ( const SHAPE_SEGMENT & aSeg,
const SHAPE_CIRCLE & aCircle,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Find nearest points between SHAPE_SEGMENT and other shapes.

Definition at line 493 of file shape_nearest_points.cpp.

References SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), and NearestPoints().

◆ NearestPoints() [17/19]

static bool NearestPoints ( const SHAPE_SEGMENT & aSeg,
const SHAPE_LINE_CHAIN_BASE & aChain,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [18/19]

static bool NearestPoints ( const SHAPE_SEGMENT & aSeg,
const SHAPE_RECT & aRect,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ NearestPoints() [19/19]

static bool NearestPoints ( const SHAPE_SEGMENT & aSegA,
const SHAPE_SEGMENT & aSegB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

◆ nearestPoints()

static bool nearestPoints ( const SHAPE * aA,
const SHAPE * aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static

Handle compound shapes by finding nearest points between all sub-shape pairs.

Definition at line 837 of file shape_nearest_points.cpp.

References nearestPointsSingleShapes(), SH_COMPOUND, SHAPE_COMPOUND::Shapes(), and SHAPE_BASE::Type().

Referenced by SHAPE::NearestPoints().

◆ NearestPointsCase()

template<class T_a, class T_b>
bool NearestPointsCase ( const SHAPE * aA,
const SHAPE * aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
inline

Template functions to handle shape conversions and reversals.

Definition at line 559 of file shape_nearest_points.cpp.

References NearestPoints().

Referenced by nearestPointsSingleShapes().

◆ NearestPointsCaseReversed()

template<class T_a, class T_b>
bool NearestPointsCaseReversed ( const SHAPE * aA,
const SHAPE * aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
inline

Definition at line 568 of file shape_nearest_points.cpp.

References NearestPoints().

Referenced by nearestPointsSingleShapes().

◆ nearestPointsSingleShapes()

static bool nearestPointsSingleShapes ( const SHAPE * aA,
const SHAPE * aB,
VECTOR2I & aPtA,
VECTOR2I & aPtB )
static