KiCad PCB EDA Suite
Loading...
Searching...
No Matches
shape_arc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2017 CERN
5 * Copyright (C) 2019-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <core/kicad_algo.h>
28#include <geometry/seg.h> // for SEG
29#include <geometry/shape_arc.h>
33#include <trigo.h>
34
35
36std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc )
37{
38 aStream << "Arc( P0=" << aArc.GetP0() << " P1=" << aArc.GetP1() << " Mid=" << aArc.GetArcMid()
39 << " Width=" << aArc.GetWidth() << " )";
40 return aStream;
41}
42
43
44SHAPE_ARC::SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
45 const EDA_ANGLE& aCenterAngle, int aWidth ) :
46 SHAPE( SH_ARC ),
47 m_width( aWidth )
48{
49 m_start = aArcStartPoint;
50
51 VECTOR2D mid = aArcStartPoint;
52 VECTOR2D end = aArcStartPoint;
53 VECTOR2D center = aArcCenter;
54
55 RotatePoint( mid, center, -aCenterAngle / 2.0 );
56 RotatePoint( end, center, -aCenterAngle );
57
58 m_mid = VECTOR2I( KiROUND( mid.x ), KiROUND( mid.y ) );
59 m_end = VECTOR2I( KiROUND( end.x ), KiROUND( end.y ) );
60
62}
63
64
65SHAPE_ARC::SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid,
66 const VECTOR2I& aArcEnd, int aWidth ) :
67 SHAPE( SH_ARC ),
68 m_start( aArcStart ),
69 m_mid( aArcMid ),
70 m_end( aArcEnd ),
71 m_width( aWidth )
72{
74}
75
76
77SHAPE_ARC::SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth ) :
78 SHAPE( SH_ARC )
79{
80 m_width = aWidth;
81
82 /*
83 * Construct an arc that is tangent to two segments with a given radius.
84 *
85 * p
86 * A
87 * A \
88 * / \
89 * / . . \ segB
90 * /. .\
91 * segA / c \
92 * / B
93 * /
94 * /
95 * B
96 *
97 *
98 * segA is the fist segment (with its points A and B)
99 * segB is the second segment (with its points A and B)
100 * p is the point at which segA and segB would intersect if they were projected
101 * c is the centre of the arc to be constructed
102 * rad is the radius of the arc to be constructed
103 *
104 * We can create two vectors, between point p and segA /segB
105 * pToA = p - segA.B //< note that segA.A would also be valid as it is colinear
106 * pToB = p - segB.B //< note that segB.A would also be valid as it is colinear
107 *
108 * Let the angle formed by segA and segB be called 'alpha':
109 * alpha = angle( pToA ) - angle( pToB )
110 *
111 * The distance PC can be computed as
112 * distPC = rad / abs( sin( alpha / 2 ) )
113 *
114 * The polar angle of the vector PC can be computed as:
115 * anglePC = angle( pToA ) + alpha / 2
116 *
117 * Therefore:
118 * C.x = P.x + distPC*cos( anglePC )
119 * C.y = P.y + distPC*sin( anglePC )
120 */
121
122 OPT_VECTOR2I p = aSegmentA.Intersect( aSegmentB, true, true );
123
124 if( !p || aSegmentA.Length() == 0 || aSegmentB.Length() == 0 )
125 {
126 // Catch bugs in debug
127 wxASSERT_MSG( false, "The input segments do not intersect or one is zero length." );
128
129 // Make a 180 degree arc around aSegmentA in case we end up here in release
130 m_start = aSegmentA.A;
131 m_end = aSegmentA.B;
132 m_mid = m_start;
133
134 VECTOR2I arcCenter = aSegmentA.Center();
135 RotatePoint( m_mid, arcCenter, ANGLE_90 ); // mid point at 90 degrees
136 }
137 else
138 {
139 VECTOR2I pToA = aSegmentA.B - *p;
140 VECTOR2I pToB = aSegmentB.B - *p;
141
142 if( pToA.EuclideanNorm() == 0 )
143 pToA = aSegmentA.A - *p;
144
145 if( pToB.EuclideanNorm() == 0 )
146 pToB = aSegmentB.A - *p;
147
148 EDA_ANGLE pToAangle( pToA );
149 EDA_ANGLE pToBangle( pToB );
150
151 EDA_ANGLE alpha = ( pToAangle - pToBangle ).Normalize180();
152
153 double distPC = (double) aRadius / abs( sin( alpha.AsRadians() / 2 ) );
154 EDA_ANGLE angPC = pToAangle - alpha / 2;
155 VECTOR2I arcCenter;
156
157 arcCenter.x = p->x + KiROUND( distPC * angPC.Cos() );
158 arcCenter.y = p->y + KiROUND( distPC * angPC.Sin() );
159
160 // The end points of the arc are the orthogonal projected lines from the line segments
161 // to the center of the arc
162 m_start = aSegmentA.LineProject( arcCenter );
163 m_end = aSegmentB.LineProject( arcCenter );
164
165 //The mid point is rotated start point around center, half the angle of the arc.
166 VECTOR2I startVector = m_start - arcCenter;
167 VECTOR2I endVector = m_end - arcCenter;
168
169 EDA_ANGLE startAngle( startVector );
170 EDA_ANGLE endAngle( endVector );
171 EDA_ANGLE midPointRotAngle = ( startAngle - endAngle ).Normalize180() / 2;
172
173 m_mid = m_start;
174 RotatePoint( m_mid, arcCenter, midPointRotAngle );
175 }
176
178}
179
180
182 : SHAPE( SH_ARC )
183{
184 m_start = aOther.m_start;
185 m_end = aOther.m_end;
186 m_mid = aOther.m_mid;
187 m_width = aOther.m_width;
188 m_bbox = aOther.m_bbox;
189 m_center = aOther.m_center;
190 m_radius = aOther.m_radius;
191}
192
193
195 const EDA_ANGLE& aAngle, double aWidth )
196{
197 m_start = aStart;
198 m_mid = aStart;
199 m_end = aEnd;
200 m_width = aWidth;
201
202 VECTOR2I center( CalcArcCenter( aStart, aEnd, aAngle ) );
203
204 RotatePoint( m_mid, center, -aAngle / 2.0 );
205
207
208 return *this;
209}
210
211
213 const VECTOR2I& aCenter, bool aClockwise,
214 double aWidth )
215{
216 VECTOR2I startLine = aStart - aCenter;
217 VECTOR2I endLine = aEnd - aCenter;
218
219 EDA_ANGLE startAngle( startLine );
220 EDA_ANGLE endAngle( endLine );
221
222 startAngle.Normalize();
223 endAngle.Normalize();
224
225 EDA_ANGLE angle = endAngle - startAngle;
226
227 if( aClockwise )
228 angle = angle.Normalize() - ANGLE_360;
229 else
230 angle = angle.Normalize();
231
232 m_start = aStart;
233 m_end = aEnd;
234 m_mid = aStart;
235
236 RotatePoint( m_mid, aCenter, -angle / 2.0 );
237
239
240 return *this;
241}
242
243
244bool SHAPE_ARC::Collide( const SEG& aSeg, int aClearance, int* aActual, VECTOR2I* aLocation ) const
245{
246 VECTOR2I center = GetCenter();
247 double radius = VECTOR2D( center - m_start ).EuclideanNorm();
248 SHAPE_CIRCLE circle( center, radius );
249 ecoord clearance_sq = SEG::Square( aClearance );
250
251 // Circle or at least an arc with less space remaining than the clearance
252 if( GetCentralAngle().AsDegrees() > 180.0
253 && ( m_start - m_end ).SquaredEuclideanNorm() < clearance_sq )
254 {
255 ecoord a_dist_sq = ( aSeg.A - center ).SquaredEuclideanNorm();
256 ecoord b_dist_sq = ( aSeg.B - center ).SquaredEuclideanNorm();
257 ecoord radius_sq = SEG::Square( radius - aClearance );
258
259 if( a_dist_sq < radius_sq && b_dist_sq < radius_sq )
260 return false;
261
262
263 return circle.Collide( aSeg, aClearance, aActual, aLocation );
264 }
265
266 // Possible points of the collision are:
267 // 1. Intersetion of the segment with the full circle
268 // 2. Closest point on the segment to the center of the circle
269 // 3. Closest point on the segment to the end points of the arc
270 // 4. End points of the segment
271
272 std::vector<VECTOR2I> candidatePts = circle.GetCircle().Intersect( aSeg );
273
274 candidatePts.push_back( aSeg.NearestPoint( center ) );
275 candidatePts.push_back( aSeg.NearestPoint( m_start ) );
276 candidatePts.push_back( aSeg.NearestPoint( m_end ) );
277 candidatePts.push_back( aSeg.A );
278 candidatePts.push_back( aSeg.B );
279
280 bool any_collides = false;
281
282 for( const VECTOR2I& candidate : candidatePts )
283 {
284 bool collides = Collide( candidate, aClearance, aActual, aLocation );
285 any_collides |= collides;
286
287 if( collides && ( !aActual || *aActual == 0 ) )
288 return true;
289 }
290
291 return any_collides;
292}
293
294
295int SHAPE_ARC::IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const
296{
297 if( aSeg.A == aSeg.B ) // One point does not define a line....
298 return 0;
299
300 CIRCLE circ( GetCenter(), GetRadius() );
301
302 std::vector<VECTOR2I> intersections = circ.IntersectLine( aSeg );
303
304 size_t originalSize = aIpsBuffer->size();
305
306 for( const VECTOR2I& intersection : intersections )
307 {
308 if( sliceContainsPoint( intersection ) )
309 aIpsBuffer->push_back( intersection );
310 }
311
312 return aIpsBuffer->size() - originalSize;
313}
314
315
316int SHAPE_ARC::Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const
317{
318 CIRCLE thiscirc( GetCenter(), GetRadius() );
319 CIRCLE othercirc( aArc.GetCenter(), aArc.GetRadius() );
320
321 std::vector<VECTOR2I> intersections = thiscirc.Intersect( othercirc );
322
323 size_t originalSize = aIpsBuffer->size();
324
325 for( const VECTOR2I& intersection : intersections )
326 {
327 if( sliceContainsPoint( intersection ) && aArc.sliceContainsPoint( intersection ) )
328 aIpsBuffer->push_back( intersection );
329 }
330
331 return aIpsBuffer->size() - originalSize;
332}
333
334
336{
338 m_radius = std::sqrt( ( VECTOR2D( m_start ) - m_center ).SquaredEuclideanNorm() );
339
340 std::vector<VECTOR2I> points;
341 // Put start and end points in the point list
342 points.push_back( m_start );
343 points.push_back( m_end );
344
345 EDA_ANGLE start_angle = GetStartAngle();
346 EDA_ANGLE end_angle = start_angle + GetCentralAngle();
347
348 // we always count quadrants clockwise (increasing angle)
349 if( start_angle > end_angle )
350 std::swap( start_angle, end_angle );
351
352 int quad_angle_start = std::ceil( start_angle.AsDegrees() / 90.0 );
353 int quad_angle_end = std::floor( end_angle.AsDegrees() / 90.0 );
354
355 // very large radius means the arc is similar to a segment
356 // so do not try to add more points, center cannot be handled
357 // Very large is here > INT_MAX/2
358 if( m_radius < (double)INT_MAX/2.0 )
359 {
360 const int radius = KiROUND( m_radius );
361
362 // count through quadrants included in arc
363 for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
364 {
365 VECTOR2I quad_pt = m_center;
366
367 switch( quad_angle % 4 )
368 {
369 case 0: quad_pt += { radius, 0 }; break;
370 case 1: case -3: quad_pt += { 0, radius }; break;
371 case 2: case -2: quad_pt += { -radius, 0 }; break;
372 case 3: case -1: quad_pt += { 0, -radius }; break;
373 default:
374 assert( false );
375 }
376
377 points.push_back( quad_pt );
378 }
379 }
380
381 m_bbox.Compute( points );
382}
383
384
385const BOX2I SHAPE_ARC::BBox( int aClearance ) const
386{
387 BOX2I bbox( m_bbox );
388
389 if( m_width != 0 )
390 bbox.Inflate( KiROUND( m_width / 2.0 ) + 1 );
391
392 if( aClearance != 0 )
393 bbox.Inflate( aClearance );
394
395 return bbox;
396}
397
398
400{
401 const static int s_epsilon = 8;
402
403 CIRCLE fullCircle( GetCenter(), GetRadius() );
404 VECTOR2I nearestPt = fullCircle.NearestPoint( aP );
405
406 if( ( nearestPt - m_start ).SquaredEuclideanNorm() <= s_epsilon )
407 return m_start;
408
409 if( ( nearestPt - m_end ).SquaredEuclideanNorm() <= s_epsilon )
410 return m_end;
411
412 if( sliceContainsPoint( nearestPt ) )
413 return nearestPt;
414
415 if( ( aP - m_start ).SquaredEuclideanNorm() <= ( aP - m_end ).SquaredEuclideanNorm() )
416 return m_start;
417 else
418 return m_end;
419}
420
421
422bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
423 VECTOR2I* aLocation ) const
424{
425 int minDist = aClearance + m_width / 2;
426 auto bbox = BBox( minDist );
427
428 // Fast check using bounding box:
429 if( !bbox.Contains( aP ) )
430 return false;
431
432 VECTOR2L center = GetCenter();
433 double radius = VECTOR2D( center - m_start ).EuclideanNorm();
434 CIRCLE fullCircle( center, radius );
435 VECTOR2D nearestPt = fullCircle.NearestPoint( VECTOR2D( aP ) );
436 int dist = KiROUND( nearestPt.Distance( aP ) );
437 EDA_ANGLE angleToPt( aP - fullCircle.Center ); // Angle from center to the point
438
439 if( !dist )
440 {
441 // Be sure to keep the sqrt of the squared distance instead of allowing a EuclideanNorm
442 // because this trucates the distance to an integer before subtracting
443 dist = KiROUND( radius - sqrt( ( aP - center ).SquaredEuclideanNorm() ) );
444 nearestPt = center + VECTOR2I( radius, 0 );
445 RotatePoint( nearestPt, center, angleToPt );
446 }
447
448 // If not a 360 degree arc, need to use arc angles to decide if point collides
449 if( m_start != m_end )
450 {
451 bool ccw = GetCentralAngle() > ANGLE_0;
452 EDA_ANGLE rotatedPtAngle = ( angleToPt.Normalize() - GetStartAngle() ).Normalize();
453 EDA_ANGLE rotatedEndAngle = ( GetEndAngle() - GetStartAngle() ).Normalize();
454
455 if( ( ccw && rotatedPtAngle > rotatedEndAngle )
456 || ( !ccw && rotatedPtAngle < rotatedEndAngle ) )
457 {
458 int distStartpt = ( aP - m_start ).EuclideanNorm();
459 int distEndpt = ( aP - m_end ).EuclideanNorm();
460
461 if( distStartpt < distEndpt )
462 {
463 dist = distStartpt;
464 nearestPt = m_start;
465 }
466 else
467 {
468 dist = distEndpt;
469 nearestPt = m_end;
470 }
471 }
472 }
473
474 if( dist <= minDist )
475 {
476 if( aLocation )
477 *aLocation = nearestPt;
478
479 if( aActual )
480 *aActual = std::max( 0, dist - m_width / 2 );
481
482 return true;
483 }
484
485 return false;
486}
487
488
490{
491 VECTOR2L center = GetCenter();
492 EDA_ANGLE angle( m_start - center );
493 return angle.Normalize();
494}
495
496
498{
499 VECTOR2L center = GetCenter();
500 EDA_ANGLE angle( m_end - center );
501 return angle.Normalize();
502}
503
504
506{
507 return m_center;
508}
509
510
512{
513 double radius = GetRadius();
514 EDA_ANGLE includedAngle = GetCentralAngle();
515
516 return std::abs( radius * includedAngle.AsRadians() );
517}
518
519
521{
522 // Arcs with same start and end points can be 0 deg or 360 deg arcs.
523 // However, they are expected to be circles.
524 // So return 360 degrees as central arc:
525 if( m_start == m_end )
526 return ANGLE_360;
527
528 VECTOR2L center = GetCenter();
529 EDA_ANGLE angle1 = EDA_ANGLE( m_mid - center ) - EDA_ANGLE( m_start - center );
530 EDA_ANGLE angle2 = EDA_ANGLE( m_end - center ) - EDA_ANGLE( m_mid - center );
531
532 return angle1.Normalize180() + angle2.Normalize180();
533}
534
535
537{
538 return m_radius;
539}
540
541
543 double* aEffectiveAccuracy ) const
544{
546 double r = GetRadius();
548 VECTOR2I c = GetCenter();
550
551 SEG startToEnd( GetP0(), GetP1() );
552 double halfAccuracy = std::max( 1.0, aAccuracy / 2 );
553
554 int n;
555
556 // To calculate the arc to segment count, use the external radius instead of the radius.
557 // for a arc with small radius and large width, the difference can be significant
558 double external_radius = r+(m_width/2);
559 double effectiveAccuracy;
560
561 if( external_radius < halfAccuracy
562 || startToEnd.Distance( GetArcMid() ) < halfAccuracy ) // Should be a very rare case
563 {
564 // In this case, the arc is approximated by one segment, with a effective error
565 // between -aAccuracy/2 and +aAccuracy/2, as expected.
566 n = 0;
567 effectiveAccuracy = external_radius;
568 }
569 else
570 {
571 n = GetArcToSegmentCount( external_radius, aAccuracy, ca );
572
573 // Recalculate the effective error of approximation, that can be < aAccuracy
574 int seg360 = n * 360.0 / fabs( ca.AsDegrees() );
575 effectiveAccuracy = CircleToEndSegmentDeltaRadius( external_radius, seg360 );
576 }
577
578 // Split the error on either side of the arc. Since we want the start and end points
579 // to be exactly on the arc, the first and last segments need to be shorter to stay within
580 // the error band (since segments normally start 1/2 the error band outside the arc).
581 r += effectiveAccuracy / 2;
582 n = n * 2;
583
584 rv.Append( m_start );
585
586 for( int i = 1; i < n ; i += 2 )
587 {
588 EDA_ANGLE a = sa;
589
590 if( n != 0 )
591 a += ( ca * i ) / n;
592
593 double x = c.x + r * a.Cos();
594 double y = c.y + r * a.Sin();
595
596 rv.Append( KiROUND( x ), KiROUND( y ) );
597 }
598
599 rv.Append( m_end );
600
601 if( aEffectiveAccuracy )
602 *aEffectiveAccuracy = effectiveAccuracy;
603
604 return rv;
605}
606
607
608void SHAPE_ARC::Move( const VECTOR2I& aVector )
609{
610 m_start += aVector;
611 m_end += aVector;
612 m_mid += aVector;
614}
615
616
617void SHAPE_ARC::Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter )
618{
619 RotatePoint( m_start, aCenter, aAngle );
620 RotatePoint( m_end, aCenter, aAngle );
621 RotatePoint( m_mid, aCenter, aAngle );
622
624}
625
626
627void SHAPE_ARC::Mirror( bool aX, bool aY, const VECTOR2I& aVector )
628{
629 if( aX )
630 {
631 m_start.x = -m_start.x + 2 * aVector.x;
632 m_end.x = -m_end.x + 2 * aVector.x;
633 m_mid.x = -m_mid.x + 2 * aVector.x;
634 }
635
636 if( aY )
637 {
638 m_start.y = -m_start.y + 2 * aVector.y;
639 m_end.y = -m_end.y + 2 * aVector.y;
640 m_mid.y = -m_mid.y + 2 * aVector.y;
641 }
642
644}
645
646
647void SHAPE_ARC::Mirror( const SEG& axis )
648{
649 m_start = axis.ReflectPoint( m_start );
650 m_end = axis.ReflectPoint( m_end );
651 m_mid = axis.ReflectPoint( m_mid );
652
654}
655
656
658{
659 std::swap( m_start, m_end );
660}
661
662
664{
665 return SHAPE_ARC( m_end, m_mid, m_start, m_width );
666}
667
668
670{
673 EDA_ANGLE ea = sa + ca;
674
675 EDA_ANGLE phi( p - GetCenter() ); // Angle from center to the point
676 phi.Normalize();
677
678 if( ca >= ANGLE_0 )
679 {
680 while( phi < sa )
681 phi += ANGLE_360;
682
683 return phi >= sa && phi <= ea;
684 }
685 else
686 {
687 while( phi > sa )
688 phi -= ANGLE_360;
689
690 return phi <= sa && phi >= ea;
691 }
692}
693
694
695void SHAPE_ARC::TransformToPolygon( SHAPE_POLY_SET& aBuffer, int aError, ERROR_LOC aErrorLoc ) const
696{
697 TransformArcToPolygon( aBuffer, m_start, m_mid, m_end, m_width, aError, aErrorLoc );
698}
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:99
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:33
VECTOR2I Center
Public to make access simpler.
Definition: circle.h:128
std::vector< VECTOR2I > Intersect(const CIRCLE &aCircle) const
Compute the intersection points between this circle and aCircle.
Definition: circle.cpp:221
std::vector< VECTOR2I > IntersectLine(const SEG &aLine) const
Compute the intersection points between this circle and aLine.
Definition: circle.cpp:300
VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute the point on the circumference of the circle that is the closest to aP.
Definition: circle.cpp:197
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
double Sin() const
Definition: eda_angle.h:170
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Normalize180()
Definition: eda_angle.h:260
double AsRadians() const
Definition: eda_angle.h:117
double Cos() const
Definition: eda_angle.h:189
Definition: seg.h:42
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition: seg.cpp:350
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.cpp:327
int Length() const
Return the length (this).
Definition: seg.h:336
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition: seg.cpp:254
static SEG::ecoord Square(int a)
Definition: seg.h:123
VECTOR2I Center() const
Definition: seg.h:372
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.cpp:388
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.cpp:371
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:520
double m_radius
Definition: shape_arc.h:278
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:115
void update_values()
Definition: shape_arc.cpp:335
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:608
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.
Definition: shape_arc.cpp:194
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition: shape_arc.cpp:385
EDA_ANGLE GetEndAngle() const
Definition: shape_arc.cpp:497
double GetLength() const
Definition: shape_arc.cpp:511
BOX2I m_bbox
Definition: shape_arc.h:276
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
Definition: shape_arc.cpp:617
bool sliceContainsPoint(const VECTOR2I &p) const
Definition: shape_arc.cpp:669
VECTOR2I NearestPoint(const VECTOR2I &aP) const
Definition: shape_arc.cpp:399
SHAPE_ARC()
Definition: shape_arc.h:40
int GetWidth() const
Definition: shape_arc.h:158
VECTOR2I m_mid
Definition: shape_arc.h:272
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.
Definition: shape_arc.cpp:212
SHAPE_ARC Reversed() const
Definition: shape_arc.cpp:663
VECTOR2I m_center
Definition: shape_arc.h:277
int m_width
Definition: shape_arc.h:274
const VECTOR2I & GetP1() const
Definition: shape_arc.h:114
int IntersectLine(const SEG &aSeg, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
Definition: shape_arc.cpp:295
VECTOR2I m_end
Definition: shape_arc.h:273
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,...
Definition: shape_arc.cpp:244
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=DefaultAccuracyForPCB(), double *aEffectiveAccuracy=nullptr) const
Construct a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:542
int Intersect(const SHAPE_ARC &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aArc.
Definition: shape_arc.cpp:316
double GetRadius() const
Definition: shape_arc.cpp:536
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:489
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.
Definition: shape_arc.cpp:695
void Reverse()
Definition: shape_arc.cpp:657
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:627
const VECTOR2I & GetP0() const
Definition: shape_arc.h:113
VECTOR2I m_start
Definition: shape_arc.h:271
const VECTOR2I & GetCenter() const
Definition: shape_arc.cpp:505
const CIRCLE GetCircle() const
Definition: shape_circle.h:128
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,...
Definition: shape_circle.h:77
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.
Represent a set of closed polygons.
An abstract shape on 2D plane.
Definition: shape.h:126
VECTOR2I::extended_type ecoord
Definition: shape.h:284
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:550
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:278
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
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:407
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
Definition: eda_text.cpp:1170
a few functions useful in geometry calculations.
int CircleToEndSegmentDeltaRadius(int aInnerCircleRadius, int aSegCount)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
int GetArcToSegmentCount(int aRadius, int aErrorMax, const EDA_ANGLE &aArcAngle)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
std::optional< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39
@ SH_ARC
circular arc
Definition: shape.h:54
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.
Definition: trigo.cpp:228
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.
Definition: trigo.cpp:520
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:121
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:673
VECTOR2< double > VECTOR2D
Definition: vector2d.h:672