39 aStream <<
"Arc( P0=" << aArc.
GetP0() <<
" P1=" << aArc.
GetP1() <<
" Mid=" << aArc.
GetArcMid()
40 <<
" Width=" << aArc.
GetWidth() <<
" )";
46 const EDA_ANGLE& aCenterAngle,
int aWidth ) :
67 const VECTOR2I& aArcEnd,
int aWidth ) :
125 if( !p || aSegmentA.
Length() == 0 || aSegmentB.
Length() == 0 )
128 wxASSERT_MSG(
false,
"The input segments do not intersect or one is zero length." );
144 pToA = aSegmentA.
A - *p;
147 pToB = aSegmentB.
A - *p;
152 EDA_ANGLE alpha = ( pToAangle - pToBangle ).Normalize180();
154 double distPC = (double) aRadius / abs( sin( alpha.
AsRadians() / 2 ) );
158 arcCenter.
x = p->x +
KiROUND( distPC * angPC.
Cos() );
159 arcCenter.
y = p->y +
KiROUND( distPC * angPC.
Sin() );
172 EDA_ANGLE midPointRotAngle = ( startAngle - endAngle ).Normalize180() / 2;
214 const VECTOR2I& aCenter,
bool aClockwise,
217 VECTOR2I startLine = aStart - aCenter;
250 return v1.ApproxCollinear(
v2 );
263 && (
m_start -
m_end ).SquaredEuclideanNorm() < clearance_sq )
265 ecoord a_dist_sq = ( aSeg.
A - center ).SquaredEuclideanNorm();
266 ecoord b_dist_sq = ( aSeg.
B - center ).SquaredEuclideanNorm();
269 if( a_dist_sq < radius_sq && b_dist_sq < radius_sq )
273 return circle.
Collide( aSeg, aClearance, aActual, aLocation );
287 candidatePts.push_back( aSeg.
A );
288 candidatePts.push_back( aSeg.
B );
290 bool any_collides =
false;
292 for(
const VECTOR2I& candidate : candidatePts )
294 bool collides =
Collide( candidate, aClearance, aActual, aLocation );
295 any_collides |= collides;
297 if( collides && ( !aActual || *aActual == 0 ) )
307 if( aSeg.
A == aSeg.
B )
312 std::vector<VECTOR2I> intersections = circ.
IntersectLine( aSeg );
314 const size_t originalSize = aIpsBuffer->size();
316 for(
const VECTOR2I& intersection : intersections )
319 aIpsBuffer->push_back( intersection );
322 return aIpsBuffer->size() - originalSize;
330 std::vector<VECTOR2I> intersections = thiscirc.
Intersect( aCircle );
332 const size_t originalSize = aIpsBuffer->size();
334 for(
const VECTOR2I& intersection : intersections )
337 aIpsBuffer->push_back( intersection );
340 return aIpsBuffer->size() - originalSize;
349 std::vector<VECTOR2I> intersections = thiscirc.
Intersect( othercirc );
351 const size_t originalSize = aIpsBuffer->size();
353 for(
const VECTOR2I& intersection : intersections )
356 aIpsBuffer->push_back( intersection );
359 return aIpsBuffer->size() - originalSize;
368 std::vector<VECTOR2I> points;
371 points.push_back(
m_end );
377 if( start_angle > end_angle )
378 std::swap( start_angle, end_angle );
380 int quad_angle_start = std::ceil( start_angle.
AsDegrees() / 90.0 );
381 int quad_angle_end = std::floor( end_angle.
AsDegrees() / 90.0 );
386 if(
m_radius < (
double)INT_MAX/2.0 )
391 for(
int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
395 switch( quad_angle % 4 )
397 case 0: quad_pt += { radius, 0 };
break;
398 case 1:
case -3: quad_pt += { 0, radius };
break;
399 case 2:
case -2: quad_pt += { -radius, 0 };
break;
400 case 3:
case -1: quad_pt += { 0, -radius };
break;
405 points.push_back( quad_pt );
420 if( aClearance != 0 )
429 const static int s_epsilon = 8;
434 if( ( nearestPt -
m_start ).SquaredEuclideanNorm() <= s_epsilon )
437 if( ( nearestPt -
m_end ).SquaredEuclideanNorm() <= s_epsilon )
443 if( ( aP -
m_start ).SquaredEuclideanNorm() <= ( aP -
m_end ).SquaredEuclideanNorm() )
451 int64_t& aDistSq )
const
455 aPtA = aPtB =
GetP0();
460 aDistSq = std::numeric_limits<int64_t>::max();
464 std::vector<VECTOR2I> intersections = circle1.
Intersect( circle2 );
466 for(
const VECTOR2I& pt : intersections )
485 if( distSq < aDistSq )
499 int64_t& aDistSq )
const
501 aDistSq = std::numeric_limits<int64_t>::max();
505 std::vector<VECTOR2I> intersections = circle.
Intersect( aSeg );
507 for(
const VECTOR2I& pt : intersections )
518 for(
const VECTOR2I& pt : { aSeg.
A, aSeg.
B } )
525 if( distSq < aDistSq )
540 if( distSq < aDistSq )
556 if( distSq < aDistSq )
560 aPtB = circleNearestPt;
569 int64_t& aDistSq )
const
573 aDistSq = std::numeric_limits<int64_t>::max();
578 for(
int i = 0; i < 4; ++i )
582 std::vector<VECTOR2I> intersections = circle.
Intersect( seg );
584 for(
const VECTOR2I& pt : intersections )
601 if( distSq < aDistSq )
617 if( distSq < aDistSq )
620 aPtA = rectNearestPt;
621 aPtB = circleNearestPt;
630 int64_t& aDistSq )
const
632 aDistSq = std::numeric_limits<int64_t>::max();
641 std::vector<VECTOR2I> pts2 = { aArc.
GetP0(), aArc.
GetP1() };
649 if( distSq < aDistSq )
670 if( center_dist_sq == 0 || aDistSq == 0 )
684 if( center_dist_sq == 0 || aDistSq == 0 )
690 if( center_dist_sq == 0 )
697 std::vector<VECTOR2I> intersections = circle1.
Intersect( circle2 );
699 for(
const VECTOR2I& pt : intersections )
716 if( pt1InSlice && pt2InSlice )
720 if( distSq < aDistSq )
737 if( distSq < aDistSq )
753 if( distSq < aDistSq )
769 int minDist = aClearance +
m_width / 2;
770 auto bbox =
BBox( minDist );
773 if( !bbox.Contains( aP ) )
778 CIRCLE fullCircle( center, radius );
787 dist =
KiROUND( radius - sqrt( ( aP - center ).SquaredEuclideanNorm() ) );
788 nearestPt = center +
VECTOR2I( radius, 0 );
799 if( ( ccw && rotatedPtAngle > rotatedEndAngle )
800 || ( !ccw && rotatedPtAngle < rotatedEndAngle ) )
802 int distStartpt = ( aP -
m_start ).EuclideanNorm();
803 int distEndpt = ( aP -
m_end ).EuclideanNorm();
805 if( distStartpt < distEndpt )
818 if( dist <= minDist )
821 *aLocation = nearestPt;
824 *aActual = std::max( 0, dist -
m_width / 2 );
887 double* aEffectiveAccuracy )
const
896 double halfAccuracy = std::max( 1.0, aAccuracy / 2 );
902 double external_radius = r+(
m_width/2);
903 double effectiveAccuracy;
905 if( external_radius < halfAccuracy
911 effectiveAccuracy = external_radius;
918 int seg360 = n * 360.0 / fabs( ca.
AsDegrees() );
925 r += effectiveAccuracy / 2;
930 for(
int i = 1; i < n ; i += 2 )
937 double x = c.
x + r * a.
Cos();
938 double y = c.
y + r * a.
Sin();
945 if( aEffectiveAccuracy )
946 *aEffectiveAccuracy = effectiveAccuracy;
973 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
1026 return phi >= sa && phi <= ea;
1033 return phi <= sa && phi >= ea;
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr Vec NearestPoint(const Vec &aPoint) const
Return the point in this rect that is closest to the provided point.
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Represent basic circle geometry with utility geometry functions.
VECTOR2I Center
Public to make access simpler.
std::vector< VECTOR2I > Intersect(const CIRCLE &aCircle) const
Compute the intersection points between this circle and aCircle.
std::vector< VECTOR2I > IntersectLine(const SEG &aLine) const
Compute the intersection points between this circle and aLine.
VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute the point on the circumference of the circle that is the closest to aP.
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
int Length() const
Return the length (this).
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
static SEG::ecoord Square(int a)
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
EDA_ANGLE GetCentralAngle() const
const VECTOR2I & GetArcMid() const
void Move(const VECTOR2I &aVector) override
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
EDA_ANGLE GetEndAngle() const
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
bool sliceContainsPoint(const VECTOR2I &p) const
VECTOR2I NearestPoint(const VECTOR2I &aP) const
int Intersect(const CIRCLE &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and a CIRCLE.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
SHAPE_ARC Reversed() const
const VECTOR2I & GetP1() const
int IntersectLine(const SEG &aSeg, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
EDA_ANGLE GetStartAngle() const
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
Fills a SHAPE_POLY_SET with a polygon representation of this shape.
bool IsEffectiveLine() const
bool NearestPoints(const SHAPE_ARC &aArc, VECTOR2I &aPtA, VECTOR2I &aPtB, int64_t &aDistSq) const
Compute closest points between this arc and aArc.
const VECTOR2I & GetP0() const
const VECTOR2I & GetCenter() const
const CIRCLE GetCircle() const
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
const VECTOR2I GetCenter() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
const SHAPE_LINE_CHAIN Outline() const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
An abstract shape on 2D plane.
VECTOR2I::extended_type ecoord
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
constexpr extended_type SquaredDistance(const VECTOR2< T > &aVector) const
Compute the squared distance between two vectors.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_360
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
a few functions useful in geometry calculations.
int CircleToEndSegmentDeltaRadius(int aInnerCircleRadius, int aSegCount)
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::optional< VECTOR2I > OPT_VECTOR2I
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
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.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D