KiCad PCB EDA Suite
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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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>
27 #include <geometry/circle.h>
29 #include <geometry/seg.h> // for SEG
30 #include <geometry/shape_arc.h>
32 #include <trigo.h>
33 
34 
35 std::ostream& operator<<( std::ostream& aStream, const SHAPE_ARC& aArc )
36 {
37  aStream << "Arc( P0=" << aArc.GetP0() << " P1=" << aArc.GetP1() << " Mid=" << aArc.GetArcMid()
38  << " Width=" << aArc.GetWidth() << " )";
39  return aStream;
40 }
41 
42 
43 SHAPE_ARC::SHAPE_ARC( const VECTOR2I& aArcCenter, const VECTOR2I& aArcStartPoint,
44  double aCenterAngle, int aWidth ) :
45  SHAPE( SH_ARC ), m_width( aWidth )
46 {
47  m_start = aArcStartPoint;
48  m_mid = aArcStartPoint;
49  m_end = aArcStartPoint;
50 
51  RotatePoint( m_mid, aArcCenter, -aCenterAngle * 10.0 / 2.0 );
52  RotatePoint( m_end, aArcCenter, -aCenterAngle * 10.0 );
53 
54  update_bbox();
55 }
56 
57 
58 SHAPE_ARC::SHAPE_ARC( const VECTOR2I& aArcStart, const VECTOR2I& aArcMid,
59  const VECTOR2I& aArcEnd, int aWidth ) :
60  SHAPE( SH_ARC ), m_start( aArcStart ), m_mid( aArcMid ), m_end( aArcEnd ),
61  m_width( aWidth )
62 {
63  update_bbox();
64 }
65 
66 
67 SHAPE_ARC::SHAPE_ARC( const SEG& aSegmentA, const SEG& aSegmentB, int aRadius, int aWidth )
68  : SHAPE( SH_ARC )
69 {
70  m_width = aWidth;
71 
72  /*
73  * Construct an arc that is tangent to two segments with a given radius.
74  *
75  * p
76  * A
77  * A \
78  * / \
79  * / . . \ segB
80  * /. .\
81  * segA / c \
82  * / B
83  * /
84  * /
85  * B
86  *
87  *
88  * segA is the fist segment (with its points A and B)
89  * segB is the second segment (with its points A and B)
90  * p is the point at which segA and segB would intersect if they were projected
91  * c is the centre of the arc to be constructed
92  * rad is the radius of the arc to be constructed
93  *
94  * We can create two vectors, between point p and segA /segB
95  * pToA = p - segA.B //< note that segA.A would also be valid as it is colinear
96  * pToB = p - segB.B //< note that segB.A would also be valid as it is colinear
97  *
98  * Let the angle formed by segA and segB be called 'alpha':
99  * alpha = angle( pToA ) - angle( pToB )
100  *
101  * The distance PC can be computed as
102  * distPC = rad / abs( sin( alpha / 2 ) )
103  *
104  * The polar angle of the vector PC can be computed as:
105  * anglePC = angle( pToA ) + alpha / 2
106  *
107  * Therefore:
108  * C.x = P.x + distPC*cos( anglePC )
109  * C.y = P.y + distPC*sin( anglePC )
110  */
111 
112  OPT_VECTOR2I p = aSegmentA.Intersect( aSegmentB, true, true );
113 
114  if( !p || aSegmentA.Length() == 0 || aSegmentB.Length() == 0 )
115  {
116  // Catch bugs in debug
117  wxASSERT_MSG( false, "The input segments do not intersect or one is zero length." );
118 
119  // Make a 180 degree arc around aSegmentA in case we end up here in release
120  m_start = aSegmentA.A;
121  m_end = aSegmentA.B;
122  m_mid = m_start;
123 
124  VECTOR2I arcCenter = aSegmentA.Center();
125  RotatePoint( m_mid, arcCenter, 900.0 ); // mid point at 90 degrees
126  }
127  else
128  {
129  VECTOR2I pToA = aSegmentA.B - p.get();
130  VECTOR2I pToB = aSegmentB.B - p.get();
131 
132  if( pToA.EuclideanNorm() == 0 )
133  pToA = aSegmentA.A - p.get();
134 
135  if( pToB.EuclideanNorm() == 0 )
136  pToB = aSegmentB.A - p.get();
137 
138  double pToAangle = ArcTangente( pToA.y, pToA.x );
139  double pToBangle = ArcTangente( pToB.y, pToB.x );
140 
141  double alpha = NormalizeAngle180( pToAangle - pToBangle );
142 
143  double distPC = (double) aRadius / abs( sin( DECIDEG2RAD( alpha / 2 ) ) );
144  double angPC = pToAangle - alpha / 2;
145 
146  VECTOR2I arcCenter;
147 
148  arcCenter.x = p.get().x + KiROUND( distPC * cos( DECIDEG2RAD( angPC ) ) );
149  arcCenter.y = p.get().y + KiROUND( distPC * sin( DECIDEG2RAD( angPC ) ) );
150 
151  // The end points of the arc are the orthogonal projected lines from the line segments
152  // to the center of the arc
153  m_start = aSegmentA.LineProject( arcCenter );
154  m_end = aSegmentB.LineProject( arcCenter );
155 
156  //The mid point is rotated start point around center, half the angle of the arc.
157  VECTOR2I startVector = m_start - arcCenter;
158  VECTOR2I endVector = m_end - arcCenter;
159 
160  double startAngle = ArcTangente( startVector.y, startVector.x );
161  double endAngle = ArcTangente( endVector.y, endVector.x );
162 
163  double midPointRotAngle = NormalizeAngle180( startAngle - endAngle ) / 2;
164  m_mid = m_start;
165  RotatePoint( m_mid, arcCenter, midPointRotAngle );
166  }
167 
168  update_bbox();
169 }
170 
171 
173  : SHAPE( SH_ARC )
174 {
175  m_start = aOther.m_start;
176  m_end = aOther.m_end;
177  m_mid = aOther.m_mid;
178  m_width = aOther.m_width;
179  m_bbox = aOther.m_bbox;
180 }
181 
182 
184  double aAngle, double aWidth )
185 {
186  m_start = aStart;
187  m_mid = aStart;
188  m_end = aEnd;
189  m_width = aWidth;
190 
191  VECTOR2I center( CalcArcCenter( aStart, aEnd, aAngle ) );
192 
193  RotatePoint( m_mid, center, -aAngle * 10.0 / 2.0 );
194 
195  update_bbox();
196 
197  return *this;
198 }
199 
200 
202  const VECTOR2I& aCenter, bool aClockwise,
203  double aWidth )
204 {
205  VECTOR2I startLine = aStart - aCenter;
206  VECTOR2I endLine = aEnd - aCenter;
207 
208  double startangle = NormalizeAnglePos(RAD2DECIDEG( startLine.Angle() ));
209  double endangle = NormalizeAnglePos(RAD2DECIDEG( endLine.Angle() ));
210  double angle = endangle - startangle;
211 
212  if( aClockwise )
214  else
216 
217  m_start = aStart;
218  m_end = aEnd;
219  m_mid = aStart;
220 
221  RotatePoint( m_mid, aCenter, -angle / 2.0 );
222 
223  update_bbox();
224 
225  return *this;
226 }
227 
228 
229 bool SHAPE_ARC::Collide( const SEG& aSeg, int aClearance, int* aActual, VECTOR2I* aLocation ) const
230 {
231  if( aSeg.A == aSeg.B )
232  return Collide( aSeg.A, aClearance, aActual, aLocation );
233 
234  int minDist = aClearance + m_width / 2;
235  VECTOR2I center = GetCenter();
236  ecoord dist_sq;
237  ecoord closest_dist_sq = VECTOR2I::ECOORD_MAX;
238  VECTOR2I nearest;
239 
240  VECTOR2I ab = ( aSeg.B - aSeg.A );
241  VECTOR2I ac = ( center - aSeg.A );
242 
243  ecoord lenAbSq = ab.SquaredEuclideanNorm();
244  double lambda = (double) ac.Dot( ab ) / (double) lenAbSq;
245 
246  if( lambda >= 0.0 && lambda <= 1.0 )
247  {
248  VECTOR2I p;
249 
250  p.x = (double) aSeg.A.x * lambda + (double) aSeg.B.x * (1.0 - lambda);
251  p.y = (double) aSeg.A.y * lambda + (double) aSeg.B.y * (1.0 - lambda);
252 
253  dist_sq = ( m_start - p ).SquaredEuclideanNorm();
254 
255  if( dist_sq < closest_dist_sq )
256  {
257  closest_dist_sq = dist_sq;
258  nearest = p;
259  }
260 
261  dist_sq = ( m_end - p ).SquaredEuclideanNorm();
262 
263  if( dist_sq < closest_dist_sq )
264  {
265  closest_dist_sq = dist_sq;
266  nearest = p;
267  }
268  }
269 
270  dist_sq = aSeg.SquaredDistance( m_start );
271 
272  if( dist_sq < closest_dist_sq )
273  {
274  closest_dist_sq = dist_sq;
275  nearest = m_start;
276  }
277 
278  dist_sq = aSeg.SquaredDistance( m_end );
279 
280  if( dist_sq < closest_dist_sq )
281  {
282  closest_dist_sq = dist_sq;
283  nearest = m_end;
284  }
285 
286  if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( minDist ) )
287  {
288  if( aLocation )
289  *aLocation = nearest;
290 
291  if( aActual )
292  *aActual = std::max( 0, (int) sqrt( closest_dist_sq ) - m_width / 2 );
293 
294  return true;
295  }
296 
297  return false;
298 }
299 
300 
301 int SHAPE_ARC::IntersectLine( const SEG& aSeg, std::vector<VECTOR2I>* aIpsBuffer ) const
302 {
303  CIRCLE circ( GetCenter(), GetRadius() );
304 
305  std::vector<VECTOR2I> intersections = circ.IntersectLine( aSeg );
306 
307  size_t originalSize = aIpsBuffer->size();
308 
309  for( const VECTOR2I& intersection : intersections )
310  {
311  if( sliceContainsPoint( intersection ) )
312  aIpsBuffer->push_back( intersection );
313  }
314 
315  return aIpsBuffer->size() - originalSize;
316 }
317 
318 
319 int SHAPE_ARC::Intersect( const SHAPE_ARC& aArc, std::vector<VECTOR2I>* aIpsBuffer ) const
320 {
321  CIRCLE thiscirc( GetCenter(), GetRadius() );
322  CIRCLE othercirc( aArc.GetCenter(), aArc.GetRadius() );
323 
324  std::vector<VECTOR2I> intersections = thiscirc.Intersect( othercirc );
325 
326  size_t originalSize = aIpsBuffer->size();
327 
328  for( const VECTOR2I& intersection : intersections )
329  {
330  if( sliceContainsPoint( intersection ) && aArc.sliceContainsPoint( intersection ) )
331  aIpsBuffer->push_back( intersection );
332  }
333 
334  return aIpsBuffer->size() - originalSize;
335 }
336 
337 
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  double start_angle = GetStartAngle();
346  double 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 / 90.0 );
353  int quad_angle_end = std::floor( end_angle / 90.0 );
354 
355  // count through quadrants included in arc
356  for( int quad_angle = quad_angle_start; quad_angle <= quad_angle_end; ++quad_angle )
357  {
358  const int radius = KiROUND( GetRadius() );
359  VECTOR2I quad_pt = GetCenter();
360 
361  switch( quad_angle % 4 )
362  {
363  case 0: quad_pt += { radius, 0 }; break;
364  case 1:
365  case -3: quad_pt += { 0, radius }; break;
366  case 2:
367  case -2: quad_pt += { -radius, 0 }; break;
368  case 3:
369  case -1: quad_pt += { 0, -radius }; break;
370  default: assert( false );
371  }
372 
373  points.push_back( quad_pt );
374  }
375 
376  m_bbox.Compute( points );
377 }
378 
379 
380 const BOX2I SHAPE_ARC::BBox( int aClearance ) const
381 {
382  BOX2I bbox( m_bbox );
383 
384  if( aClearance != 0 )
385  bbox.Inflate( aClearance );
386 
387  return bbox;
388 }
389 
390 
392 {
393  return GetCentralAngle() < 0;
394 }
395 
396 
397 bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
398  VECTOR2I* aLocation ) const
399 {
400  int minDist = aClearance + m_width / 2;
401  auto bbox = BBox( minDist );
402 
403  // Fast check using bounding box:
404  if( !bbox.Contains( aP ) )
405  return false;
406 
407  VECTOR2I center = GetCenter();
408  VECTOR2I vec = aP - center;
409 
410  int dist = abs( vec.EuclideanNorm() - GetRadius() );
411 
412  // If not a 360 degree arc, need to use arc angles to decide if point collides
413  if( m_start != m_end )
414  {
415  bool ccw = GetCentralAngle() > 0.0;
416  double rotatedVecAngle = NormalizeAngleDegreesPos( NormalizeAngleDegreesPos( RAD2DEG( vec.Angle() ) )
417  - GetStartAngle() );
418  double rotatedEndAngle = NormalizeAngleDegreesPos( GetEndAngle() - GetStartAngle() );
419 
420  if( ( ccw && rotatedVecAngle > rotatedEndAngle )
421  || ( !ccw && rotatedVecAngle < rotatedEndAngle ) )
422  {
423  int distStartpt = ( aP - m_start ).EuclideanNorm();
424  int distEndpt = ( aP - m_end ).EuclideanNorm();
425  dist = std::min( distStartpt, distEndpt );
426  }
427  }
428 
429  if( dist <= minDist )
430  {
431  if( aLocation )
432  *aLocation = ( aP + GetCenter() ) / 2;
433 
434  if( aActual )
435  *aActual = std::max( 0, dist - m_width / 2 );
436 
437  return true;
438  }
439 
440  return false;
441 }
442 
443 
445 {
446  VECTOR2D d( m_start - GetCenter() );
447 
448  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
449 
450  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
451 }
452 
453 
455 {
456  VECTOR2D d( m_end - GetCenter() );
457 
458  auto ang = 180.0 / M_PI * atan2( d.y, d.x );
459 
460  return NormalizeAngleDegrees( ang, 0.0, 360.0 );
461 }
462 
463 
465 {
466  return CalcArcCenter( m_start, m_mid, m_end );
467 }
468 
469 
470 double SHAPE_ARC::GetLength() const
471 {
472  double radius = GetRadius();
473  double includedAngle = std::abs( GetCentralAngle() );
474 
475  return radius * M_PI * includedAngle / 180.0;
476 }
477 
478 
480 {
481  VECTOR2I center = GetCenter();
482  VECTOR2I p0 = m_start - center;
483  VECTOR2I p1 = m_mid - center;
484  VECTOR2I p2 = m_end - center;
485  double angle1 = ArcTangente( p1.y, p1.x ) - ArcTangente( p0.y, p0.x );
486  double angle2 = ArcTangente( p2.y, p2.x ) - ArcTangente( p1.y, p1.x );
487 
488  return ( NormalizeAngle180( angle1 ) + NormalizeAngle180( angle2 ) ) / 10.0;
489 }
490 
491 
492 double SHAPE_ARC::GetRadius() const
493 {
494  return ( m_start - GetCenter() ).EuclideanNorm();
495 }
496 
497 
499  double* aEffectiveAccuracy ) const
500 {
501  SHAPE_LINE_CHAIN rv;
502  double r = GetRadius();
503  double sa = GetStartAngle();
504  VECTOR2I c = GetCenter();
505  double ca = GetCentralAngle();
506 
507  int n;
508 
509  // To calculate the arc to segment count, use the external radius instead of the radius.
510  // for a arc with small radius and large width, the difference can be significant
511  double external_radius = r+(m_width/2);
512  double effectiveAccuracy;
513 
514  if( external_radius < aAccuracy/2 ) // Should be a very rare case
515  {
516  // In this case, the arc is approximated by one segment, with a effective error
517  // between -aAccuracy/2 and +aAccuracy/2, as expected.
518  n = 0;
519  effectiveAccuracy = external_radius;
520  }
521  else
522  {
523  double arc_angle = std::abs( ca );
524  n = GetArcToSegmentCount( external_radius, aAccuracy, arc_angle );
525 
526  // Recalculate the effective error of approximation, that can be < aAccuracy
527  int seg360 = n * 360.0 / arc_angle;
528  effectiveAccuracy = CircleToEndSegmentDeltaRadius( external_radius, seg360 );
529  }
530 
531  // Split the error on either side of the arc. Since we want the start and end points
532  // to be exactly on the arc, the first and last segments need to be shorter to stay within
533  // the error band (since segments normally start 1/2 the error band outside the arc).
534  r += effectiveAccuracy / 2;
535  n = n * 2;
536 
537  rv.Append( m_start );
538 
539  for( int i = 1; i < n ; i += 2 )
540  {
541  double a = sa;
542 
543  if( n != 0 )
544  a += ( ca * i ) / n;
545 
546  double x = c.x + r * cos( a * M_PI / 180.0 );
547  double y = c.y + r * sin( a * M_PI / 180.0 );
548 
549  rv.Append( KiROUND( x ), KiROUND( y ) );
550  }
551 
552  rv.Append( m_end );
553 
554  if( aEffectiveAccuracy )
555  *aEffectiveAccuracy = effectiveAccuracy;
556 
557  return rv;
558 }
559 
560 
561 void SHAPE_ARC::Move( const VECTOR2I& aVector )
562 {
563  m_start += aVector;
564  m_end += aVector;
565  m_mid += aVector;
566  update_bbox();
567 }
568 
569 
570 void SHAPE_ARC::Rotate( double aAngle, const VECTOR2I& aCenter )
571 {
572  m_start -= aCenter;
573  m_end -= aCenter;
574  m_mid -= aCenter;
575 
576  m_start = m_start.Rotate( aAngle );
577  m_end = m_end.Rotate( aAngle );
578  m_mid = m_mid.Rotate( aAngle );
579 
580  m_start += aCenter;
581  m_end += aCenter;
582  m_mid += aCenter;
583 
584  update_bbox();
585 }
586 
587 
588 void SHAPE_ARC::Mirror( bool aX, bool aY, const VECTOR2I& aVector )
589 {
590  if( aX )
591  {
592  m_start.x = -m_start.x + 2 * aVector.x;
593  m_end.x = -m_end.x + 2 * aVector.x;
594  m_mid.x = -m_mid.x + 2 * aVector.x;
595  }
596 
597  if( aY )
598  {
599  m_start.y = -m_start.y + 2 * aVector.y;
600  m_end.y = -m_end.y + 2 * aVector.y;
601  m_mid.y = -m_mid.y + 2 * aVector.y;
602  }
603 
604  update_bbox();
605 }
606 
607 
608 void SHAPE_ARC::Mirror( const SEG& axis )
609 {
610  m_start = axis.ReflectPoint( m_start );
611  m_end = axis.ReflectPoint( m_end );
612  m_mid = axis.ReflectPoint( m_mid );
613 
614  update_bbox();
615 }
616 
617 
619 {
620  std::swap( m_start, m_end );
621 }
622 
623 
625 {
626  return SHAPE_ARC( m_end, m_mid, m_start, m_width );
627 }
628 
629 
631 {
632  VECTOR2I center = GetCenter();
633  double phi = 180.0 / M_PI * atan2( p.y - center.y, p.x - center.x );
634  double ca = GetCentralAngle();
635  double sa = GetStartAngle();
636  double ea;
637 
638  if( ca >= 0 )
639  {
640  ea = sa + ca;
641  }
642  else
643  {
644  ea = sa;
645  sa += ca;
646  }
647 
648  return alg::within_wrapped_range( phi, sa, ea, 360.0 );
649 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
int Length() const
Return the length (this).
Definition: seg.h:350
void Mirror(bool aX=true, bool aY=false, const VECTOR2I &aVector={ 0, 0 })
Definition: shape_arc.cpp:588
T NormalizeAngleNeg(T Angle)
Normalize angle to be in the 0.0 .. -360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:268
int CircleToEndSegmentDeltaRadius(int aInnerCircleRadius, int aSegCount)
void Rotate(double aAngle, const VECTOR2I &aCenter) override
Rotate the arc by a given angle about a point.
Definition: shape_arc.cpp:570
bool IsClockwise() const
Definition: shape_arc.cpp:391
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:229
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:154
double GetRadius() const
Definition: shape_arc.cpp:492
VECTOR2I m_end
Definition: shape_arc.h:260
double RAD2DEG(double rad)
Definition: trigo.h:230
const VECTOR2I ReflectPoint(const VECTOR2I &aP) const
Reflect a point using this segment as axis.
Definition: seg.cpp:249
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
Definition: shape_arc.cpp:183
double RAD2DECIDEG(double rad)
Definition: trigo.h:234
void Compute(const Container &aPointList)
Compute the bounding box from a given list of points.
Definition: box2.h:75
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:300
ecoord SquaredDistance(const SEG &aSeg) const
Definition: seg.cpp:39
bool ccw(const VECTOR2I &aA, const VECTOR2I &aB, const VECTOR2I &aC) const
Definition: shape_arc.h:247
double GetStartAngle() const
Definition: shape_arc.cpp:444
bool sliceContainsPoint(const VECTOR2I &p) const
Definition: shape_arc.cpp:630
VECTOR2I Center() const
Definition: seg.h:386
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int Intersect(const SHAPE_ARC &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aArc.
Definition: shape_arc.cpp:319
static SEG::ecoord Square(int a)
Definition: seg.h:122
std::ostream & operator<<(std::ostream &aStream, const SHAPE_ARC &aArc)
Definition: shape_arc.cpp:35
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
T NormalizeAngle180(T Angle)
Normalize angle to be in the -180.0 .. 180.0 range.
Definition: trigo.h:387
VECTOR2I m_mid
Definition: shape_arc.h:259
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
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:268
double NormalizeAngleDegreesPos(double Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in degrees.
Definition: trigo.h:297
OPT< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:38
const VECTOR2I & GetP0() const
Definition: shape_arc.h:111
std::vector< VECTOR2I > IntersectLine(const SEG &aLine) const
Compute the intersection points between this circle and aLine.
Definition: circle.cpp:288
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:113
circular arc
Definition: shape.h:50
a few functions useful in geometry calculations.
An abstract shape on 2D plane.
Definition: shape.h:116
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:32
double Angle() const
Compute the angle of the vector.
Definition: vector2d.h:307
E_SERIE r
Definition: eserie.cpp:41
double GetEndAngle() const
Definition: shape_arc.cpp:454
void update_bbox()
Definition: shape_arc.cpp:338
void Reverse()
Definition: shape_arc.cpp:618
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:301
Definition: seg.h:40
void Move(const VECTOR2I &aVector) override
Definition: shape_arc.cpp:561
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:281
int GetWidth() const
Definition: shape_arc.h:156
VECTOR2< T > Rotate(double aAngle) const
Rotate the vector by a given angle.
Definition: vector2d.h:371
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:498
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:521
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:201
std::vector< VECTOR2I > Intersect(const CIRCLE &aCircle) const
Compute the intersection points between this circle and aCircle.
Definition: circle.cpp:209
VECTOR2I::extended_type ecoord
Definition: shape.h:236
Represent a polyline (an zero-thickness chain of connected line segments).
VECTOR2I m_start
Definition: shape_arc.h:258
T NormalizeAnglePos(T Angle)
Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
Definition: trigo.h:281
static DIRECTION_45::AngleType angle(const VECTOR2I &a, const VECTOR2I &b)
VECTOR2I A
Definition: seg.h:48
double GetCentralAngle() const
Definition: shape_arc.cpp:479
double DECIDEG2RAD(double deg)
Definition: trigo.h:233
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:73
SHAPE_ARC()
Definition: shape_arc.h:39
double NormalizeAngleDegrees(double Angle, double aMin, double aMax)
Normalize angle to be aMin < angle <= aMax angle is in degrees.
Definition: trigo.h:327
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:380
SHAPE_ARC Reversed() const
Definition: shape_arc.cpp:624
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183
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:454
double GetLength() const
Definition: shape_arc.cpp:470
int m_width
Definition: shape_arc.h:262
int GetArcToSegmentCount(int aRadius, int aErrorMax, double aArcAngleDegree)
BOX2I m_bbox
Definition: shape_arc.h:263
const VECTOR2I & GetP1() const
Definition: shape_arc.h:112
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:464
bool within_wrapped_range(T __val, T __minval, T __maxval, T __wrap)
Test if __val lies within __minval and __maxval in a wrapped range.
Definition: kicad_algo.h:128
VECTOR2I B
Definition: seg.h:49