57 const int dist =
delta.EuclideanNorm();
93 aPtB.
x = std::max( p0.
x, std::min( c.
x, p0.
x + size.
x ) );
94 aPtB.
y = std::max( p0.
y, std::min( c.
y, p0.
y + size.
y ) );
100 int distToLeft = c.
x - p0.
x;
101 int distToRight = p0.
x + size.
x - c.
x;
102 int distToTop = c.
y - p0.
y;
103 int distToBottom = p0.
y + size.
y - c.
y;
105 int minDist = std::min( { distToLeft, distToRight, distToTop, distToBottom } );
107 if( minDist == distToLeft )
112 else if( minDist == distToRight )
117 else if( minDist == distToTop )
175 int64_t minDistSq = std::numeric_limits<int64_t>::max();
185 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
186 if( distSq < minDistSq )
198 for(
size_t j = 0; j <
chain->ArcCount(); j++ )
208 if( distSq < minDistSq )
218 return minDistSq < std::numeric_limits<int64_t>::max();
280 int64_t minDistSq = std::numeric_limits<int64_t>::max();
291 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
292 if( distSq < minDistSq )
304 for(
size_t j = 0; j <
chain->ArcCount(); j++ )
314 if( distSq < minDistSq )
324 return minDistSq < std::numeric_limits<int64_t>::max();
336 int64_t minDistSq = std::numeric_limits<int64_t>::max();
352 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
353 if( distSq < minDistSq )
366 for(
size_t i = 0; i < chainA->
ArcCount(); i++ )
373 for(
size_t j = 0; j < chainB->
ArcCount(); j++ )
379 if( distSq < minDistSq )
396 if( distSq < minDistSq )
407 if( chainB && !chainA )
410 for(
size_t j = 0; j < chainB->
ArcCount(); j++ )
420 if( distSq < minDistSq )
431 return minDistSq < std::numeric_limits<int64_t>::max();
473 int64_t minDistSq = std::numeric_limits<int64_t>::max();
483 if( distSq < minDistSq )
495 for(
size_t j = 0; j <
chain->ArcCount(); j++ )
501 if( distSq < minDistSq )
553 dir = ( aPtA - aPtB ).Resize( aSegB.
GetWidth() / 2 );
579template<
class T_a,
class T_b>
582 return NearestPoints( *
static_cast<const T_a*
>( aA ), *
static_cast<const T_b*
>( aB ),
586template<
class T_a,
class T_b>
589 return NearestPoints( *
static_cast<const T_b*
>( aB ), *
static_cast<const T_a*
>( aA ),
662 int64_t minDistSq = std::numeric_limits<int64_t>::max();
665 for(
int i = 0; i <
chain->SegmentCount(); i++ )
673 if( distSq < minDistSq )
683 for(
size_t i = 0; i <
chain->ArcCount(); i++ )
687 if(
chain->Arc( i ).NearestPoints( *arc, ptA, ptB, distSq ) )
689 if( distSq < minDistSq )
698 return minDistSq < std::numeric_limits<int64_t>::max();
746 int64_t minDistSq = std::numeric_limits<int64_t>::max();
748 for(
size_t i = 0; i <
chain->GetSegmentCount(); i++ )
756 if( distSq < minDistSq )
765 return minDistSq < std::numeric_limits<int64_t>::max();
797 int64_t minDistSq = std::numeric_limits<int64_t>::max();
806 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
807 if( distSq < minDistSq )
816 return minDistSq < std::numeric_limits<int64_t>::max();
828 int64_t minDistSq = std::numeric_limits<int64_t>::max();
837 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
838 if( distSq < minDistSq )
847 return minDistSq < std::numeric_limits<int64_t>::max();
859 int64_t minDistSq = std::numeric_limits<int64_t>::max();
862 auto checkNearestPoints =
863 [&](
const SHAPE* shapeA,
const SHAPE* shapeB ) ->
bool
869 int64_t distSq = ( ptB - ptA ).SquaredEuclideanNorm();
871 if( distSq < minDistSq )
894 checkNearestPoints( elemA, elemB );
904 checkNearestPoints( elemA, aB );
913 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
bool IsArcSegment(size_t aSegment) const
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_LINE_CHAIN_BASE &aA, const SHAPE_LINE_CHAIN_BASE &aB, VECTOR2I &aPtA, VECTOR2I &aPtB)
Find the nearest points between two line chains.
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