55 const int dist =
delta.EuclideanNorm();
91 aPtB.
x = std::max( p0.
x, std::min( c.
x, p0.
x + size.
x ) );
92 aPtB.
y = std::max( p0.
y, std::min( c.
y, p0.
y + size.
y ) );
98 int distToLeft = c.
x - p0.
x;
99 int distToRight = p0.
x + size.
x - c.
x;
100 int distToTop = c.
y - p0.
y;
101 int distToBottom = p0.
y + size.
y - c.
y;
103 int minDist = std::min( { distToLeft, distToRight, distToTop, distToBottom } );
105 if( minDist == distToLeft )
110 else if( minDist == distToRight )
115 else if( minDist == distToTop )
172 int64_t minDistSq = std::numeric_limits<int64_t>::max();
179 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
180 if( distSq < minDistSq )
189 return minDistSq < std::numeric_limits<int64_t>::max();
203 int64_t minDistSq = std::numeric_limits<int64_t>::max();
215 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
216 if( distSq < minDistSq )
235 int64_t minDistSq = std::numeric_limits<int64_t>::max();
243 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
244 if( distSq < minDistSq )
263 int64_t minDistSq = std::numeric_limits<int64_t>::max();
275 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
276 if( distSq < minDistSq )
308 int64_t minDistSq = std::numeric_limits<int64_t>::max();
317 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
318 if( distSq < minDistSq )
327 return minDistSq < std::numeric_limits<int64_t>::max();
337 int64_t minDistSq = std::numeric_limits<int64_t>::max();
347 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
348 if( distSq < minDistSq )
364 for(
size_t i = 0; i < chainA->
ArcCount(); i++ )
371 for(
size_t j = 0; j < chainB->
ArcCount(); j++ )
377 if( distSq < minDistSq )
394 if( distSq < minDistSq )
405 if( chainB && !chainA )
408 for(
size_t j = 0; j < chainB->
ArcCount(); j++ )
418 if( distSq < minDistSq )
429 return minDistSq < std::numeric_limits<int64_t>::max();
470 int64_t minDistSq = std::numeric_limits<int64_t>::max();
477 if( distSq < minDistSq )
528 dir = ( aPtA - aPtB ).Resize( aSegB.
GetWidth() / 2 );
554template<
class T_a,
class T_b>
557 return NearestPoints( *
static_cast<const T_a*
>( aA ), *
static_cast<const T_b*
>( aB ),
561template<
class T_a,
class T_b>
564 return NearestPoints( *
static_cast<const T_b*
>( aB ), *
static_cast<const T_a*
>( aA ),
637 int64_t minDistSq = std::numeric_limits<int64_t>::max();
640 for(
int i = 0; i <
chain->SegmentCount(); i++ )
646 if( distSq < minDistSq )
656 for(
size_t i = 0; i <
chain->ArcCount(); i++ )
660 if(
chain->Arc( i ).NearestPoints( *arc, ptA, ptB, distSq ) )
662 if( distSq < minDistSq )
671 return minDistSq < std::numeric_limits<int64_t>::max();
719 int64_t minDistSq = std::numeric_limits<int64_t>::max();
721 for(
size_t i = 0; i <
chain->GetSegmentCount(); i++ )
727 if( distSq < minDistSq )
736 return minDistSq < std::numeric_limits<int64_t>::max();
768 int64_t minDistSq = std::numeric_limits<int64_t>::max();
777 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
778 if( distSq < minDistSq )
787 return minDistSq < std::numeric_limits<int64_t>::max();
799 int64_t minDistSq = std::numeric_limits<int64_t>::max();
808 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
809 if( distSq < minDistSq )
818 return minDistSq < std::numeric_limits<int64_t>::max();
830 int64_t minDistSq = std::numeric_limits<int64_t>::max();
833 auto checkNearestPoints =
834 [&](
const SHAPE* shapeA,
const SHAPE* shapeB ) ->
bool
840 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
842 if( distSq < minDistSq )
865 checkNearestPoints( elemA, elemB );
875 checkNearestPoints( elemA, aB );
884 checkNearestPoints( aA, elemB );
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
bool NearestPoints(const SHAPE_ARC &aArc, VECTOR2I &aPtA, VECTOR2I &aPtB, int64_t &aDistSq) const
Compute closest points between this arc and aArc.
SHAPE_TYPE Type() const
Return the type of the shape.
const VECTOR2I GetCenter() const
const std::vector< SHAPE * > & Shapes() const
virtual size_t GetSegmentCount() const =0
virtual const SEG GetSegment(int aIndex) const =0
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
Represent a set of closed polygons.
CONST_SEGMENT_ITERATOR CIterateSegmentsWithHoles() const
Return an iterator object, for the aOutline-th outline in the set (with holes).
CONST_SEGMENT_ITERATOR CIterateSegments(int aFirst, int aLast, bool aIterateHoles=false) const
Return an iterator object, for iterating between aFirst and aLast outline, with or without holes (def...
const SHAPE_LINE_CHAIN Outline() const
const VECTOR2I & GetPosition() const
const VECTOR2I GetSize() const
const SEG & GetSeg() const
int GetWidth() const override
An abstract shape on 2D plane.
SHAPE(SHAPE_TYPE aType)
Create an empty shape of type aType.
bool NearestPoints(const SHAPE *aOther, VECTOR2I &aPtThis, VECTOR2I &aPtOther) const
Return the two points that mark the closest distance between this shape and aOther.
VECTOR2_TRAITS< int32_t >::extended_type extended_type
@ SH_POLY_SET
set of polygons (with holes, etc.)
@ SH_RECT
axis-aligned rectangle
@ SH_SIMPLE
simple polygon
@ SH_POLY_SET_TRIANGLE
a single triangle belonging to a POLY_SET triangulation
@ SH_LINE_CHAIN
line chain (polyline)
@ SH_COMPOUND
compound shape, consisting of multiple simple shapes
VECTOR2I::extended_type ecoord
static bool NearestPoints(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
Find the nearest points between two circles.
bool NearestPointsCase(const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
Template functions to handle shape conversions and reversals.
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.
bool NearestPointsCaseReversed(const SHAPE *aA, const SHAPE *aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
const SHAPE_LINE_CHAIN chain
VECTOR2< int32_t > VECTOR2I