KiCad PCB EDA Suite
shape_collisions.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) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <math/vector2d.h>
26 #include <math.h>
27 
28 #include <geometry/shape.h>
29 #include <geometry/shape_arc.h>
31 #include <geometry/shape_circle.h>
32 #include <geometry/shape_rect.h>
33 #include <geometry/shape_segment.h>
34 #include "../../include/geometry/shape_simple.h"
35 
37 
38 static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int aClearance,
39  bool aNeedMTV, VECTOR2I& aMTV )
40 {
41  ecoord min_dist = aClearance + aA.GetRadius() + aB.GetRadius();
42  ecoord min_dist_sq = min_dist * min_dist;
43 
44  const VECTOR2I delta = aB.GetCenter() - aA.GetCenter();
45 
46  ecoord dist_sq = delta.SquaredEuclideanNorm();
47 
48  if( dist_sq >= min_dist_sq )
49  return false;
50 
51  if( aNeedMTV )
52  aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
53 
54  return true;
55 }
56 
57 
58 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aClearance,
59  bool aNeedMTV, VECTOR2I& aMTV )
60 {
61  const VECTOR2I c = aB.GetCenter();
62  const VECTOR2I p0 = aA.GetPosition();
63  const VECTOR2I size = aA.GetSize();
64  const int r = aB.GetRadius();
65  const int min_dist = aClearance + r;
66 
67  const VECTOR2I vts[] =
68  {
69  VECTOR2I( p0.x, p0.y ),
70  VECTOR2I( p0.x, p0.y + size.y ),
71  VECTOR2I( p0.x + size.x, p0.y + size.y ),
72  VECTOR2I( p0.x + size.x, p0.y ),
73  VECTOR2I( p0.x, p0.y )
74  };
75 
76  int nearest_seg_dist = INT_MAX;
77  VECTOR2I nearest;
78 
79  bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
80  && c.y >= p0.y && c.y <= ( p0.y + size.y );
81 
82 
83  if( !aNeedMTV && inside )
84  return true;
85 
86  for( int i = 0; i < 4; i++ )
87  {
88  const SEG seg( vts[i], vts[i + 1] );
89 
90  VECTOR2I pn = seg.NearestPoint( c );
91 
92  int d = ( pn - c ).EuclideanNorm();
93 
94  if( ( d < min_dist ) && !aNeedMTV )
95  return true;
96 
97  if( d < nearest_seg_dist )
98  {
99  nearest = pn;
100  nearest_seg_dist = d;
101  }
102  }
103 
104  if( nearest_seg_dist >= min_dist && !inside )
105  return false;
106 
107  VECTOR2I delta = c - nearest;
108 
109  if( !aNeedMTV )
110  return true;
111 
112 
113  if( inside )
114  aMTV = -delta.Resize( abs( min_dist + 1 + nearest_seg_dist ) + 1 );
115  else
116  aMTV = delta.Resize( abs( min_dist + 1 - nearest_seg_dist ) + 1 );
117 
118 
119  return true;
120 }
121 
122 
123 static VECTOR2I pushoutForce( const SHAPE_CIRCLE& aA, const SEG& aB, int aClearance )
124 {
125  VECTOR2I f( 0, 0 );
126 
127  const VECTOR2I c = aA.GetCenter();
128  const VECTOR2I nearest = aB.NearestPoint( c );
129 
130  const int r = aA.GetRadius();
131 
132  int dist = ( nearest - c ).EuclideanNorm();
133  int min_dist = aClearance + r;
134 
135  if( dist < min_dist )
136  {
137  for( int corr = 0; corr < 5; corr++ )
138  {
139  f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
140 
141  if( aB.Distance( c + f ) >= min_dist )
142  break;
143  }
144  }
145 
146  return f;
147 }
148 
149 
150 static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
151  bool aNeedMTV, VECTOR2I& aMTV )
152 {
153  bool found = false;
154 
155  for( int s = 0; s < aB.SegmentCount(); s++ )
156  {
157  if( aA.Collide( aB.CSegment( s ), aClearance ) )
158  {
159  found = true;
160  break;
161  }
162  }
163 
164  if( !aNeedMTV || !found )
165  return found;
166 
167  SHAPE_CIRCLE cmoved( aA );
168  VECTOR2I f_total( 0, 0 );
169 
170  for( int s = 0; s < aB.SegmentCount(); s++ )
171  {
172  VECTOR2I f = pushoutForce( cmoved, aB.CSegment( s ), aClearance );
173  cmoved.SetCenter( cmoved.GetCenter() + f );
174  f_total += f;
175  }
176 
177  aMTV = f_total;
178  return found;
179 }
180 
181 
182 static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_SIMPLE& aB, int aClearance,
183  bool aNeedMTV, VECTOR2I& aMTV )
184 {
185  bool found;
186  const SHAPE_LINE_CHAIN& lc( aB.Vertices() );
187 
188  found = lc.Distance( aA.GetCenter() ) <= aClearance + aA.GetRadius();
189 
190  if( !aNeedMTV || !found )
191  return found;
192 
193  SHAPE_CIRCLE cmoved( aA );
194  VECTOR2I f_total( 0, 0 );
195 
196  for( int s = 0; s < lc.SegmentCount(); s++ )
197  {
198  VECTOR2I f = pushoutForce( cmoved, lc.CSegment( s ), aClearance );
199  cmoved.SetCenter( cmoved.GetCenter() + f );
200  f_total += f;
201  }
202 
203  aMTV = f_total;
204  return found;
205 }
206 
207 
208 static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
209  bool aNeedMTV, VECTOR2I& aMTV )
210 {
211  bool col = aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
212 
213  if( col && aNeedMTV )
214  {
215  aMTV = -pushoutForce( aA, aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
216  }
217  return col;
218 }
219 
220 
221 static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
222  bool aNeedMTV, VECTOR2I& aMTV )
223 {
224  for( int i = 0; i < aB.SegmentCount(); i++ )
225  if( aA.Collide( aB.CSegment( i ), aClearance ) )
226  return true;
227 
228  return false;
229 }
230 
231 
232 static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_SIMPLE& aB, int aClearance,
233  bool aNeedMTV, VECTOR2I& aMTV )
234 {
235  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
236 }
237 
238 
239 static inline bool Collide( const SHAPE_SIMPLE& aA, const SHAPE_SIMPLE& aB, int aClearance,
240  bool aNeedMTV, VECTOR2I& aMTV )
241 {
242  return Collide( aA.Vertices(), aB.Vertices(), aClearance, aNeedMTV, aMTV );
243 }
244 
245 
246 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
247  bool aNeedMTV, VECTOR2I& aMTV )
248 {
249  for( int s = 0; s < aB.SegmentCount(); s++ )
250  {
251  SEG seg = aB.CSegment( s );
252 
253  if( aA.Collide( seg, aClearance ) )
254  return true;
255  }
256 
257  return false;
258 }
259 
260 
261 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SIMPLE& aB, int aClearance,
262  bool aNeedMTV, VECTOR2I& aMTV )
263 {
264  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
265 }
266 
267 
268 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
269  bool aNeedMTV, VECTOR2I& aMTV )
270 {
271  return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
272 }
273 
274 
275 static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, int aClearance,
276  bool aNeedMTV, VECTOR2I& aMTV )
277 {
278  return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
279 }
280 
281 
282 static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_SEGMENT& aB, int aClearance,
283  bool aNeedMTV, VECTOR2I& aMTV )
284 {
285  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
286  return true;
287 
288  return false;
289 }
290 
291 
292 static inline bool Collide( const SHAPE_SIMPLE& aA, const SHAPE_SEGMENT& aB, int aClearance,
293  bool aNeedMTV, VECTOR2I& aMTV )
294 {
295  return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
296 }
297 
298 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_RECT& aB, int aClearance,
299  bool aNeedMTV, VECTOR2I& aMTV )
300 {
301  return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
302 }
303 
304 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_RECT& aB, int aClearance,
305  bool aNeedMTV, VECTOR2I& aMTV )
306 {
307  const auto lc = aA.ConvertToPolyline();
308  return Collide( lc, aB.Outline(), aClearance, aNeedMTV, aMTV );
309 }
310 
311 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_CIRCLE& aB, int aClearance,
312  bool aNeedMTV, VECTOR2I& aMTV )
313 {
314  const auto lc = aA.ConvertToPolyline();
315  bool rv = Collide( aB, lc, aClearance, aNeedMTV, aMTV );
316 
317  if( rv && aNeedMTV )
318  aMTV = -aMTV;
319 
320  return rv;
321 }
322 
323 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
324  bool aNeedMTV, VECTOR2I& aMTV )
325 {
326  const auto lc = aA.ConvertToPolyline();
327  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
328 }
329 
330 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SEGMENT& aB, int aClearance,
331  bool aNeedMTV, VECTOR2I& aMTV )
332 {
333  const auto lc = aA.ConvertToPolyline();
334  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
335 }
336 
337 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SIMPLE& aB, int aClearance,
338  bool aNeedMTV, VECTOR2I& aMTV )
339 {
340  const auto lc = aA.ConvertToPolyline();
341  return Collide( lc, aB.Vertices(), aClearance, aNeedMTV, aMTV );
342 }
343 
344 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_ARC& aB, int aClearance,
345  bool aNeedMTV, VECTOR2I& aMTV )
346 {
347  const auto lcA = aA.ConvertToPolyline();
348  const auto lcB = aB.ConvertToPolyline();
349  return Collide( lcA, lcB, aClearance, aNeedMTV, aMTV );
350 }
351 
352 template<class ShapeAType, class ShapeBType>
353 inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
354 {
355  return Collide (*static_cast<const ShapeAType*>( aA ),
356  *static_cast<const ShapeBType*>( aB ),
357  aClearance, aNeedMTV, aMTV);
358 }
359 
360 template<class ShapeAType, class ShapeBType>
361 inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
362 {
363  bool rv = Collide (*static_cast<const ShapeBType*>( aB ),
364  *static_cast<const ShapeAType*>( aA ),
365  aClearance, aNeedMTV, aMTV);
366  if(rv && aNeedMTV)
367  aMTV = -aMTV;
368  return rv;
369 }
370 
371 
372 bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
373 {
374  switch( aA->Type() )
375  {
376  case SH_RECT:
377  switch( aB->Type() )
378  {
379  case SH_RECT:
380  return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
381 
382  case SH_CIRCLE:
383  return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
384 
385  case SH_LINE_CHAIN:
386  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
387 
388  case SH_SEGMENT:
389  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
390 
391  case SH_SIMPLE:
392  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
393 
394  case SH_ARC:
395  return CollCaseReversed<SHAPE_RECT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
396 
397  default:
398  break;
399  }
400  break;
401 
402  case SH_CIRCLE:
403  switch( aB->Type() )
404  {
405  case SH_RECT:
406  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
407 
408  case SH_CIRCLE:
409  return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
410 
411  case SH_LINE_CHAIN:
412  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
413 
414  case SH_SEGMENT:
415  return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
416 
417  case SH_SIMPLE:
418  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
419 
420  case SH_ARC:
421  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
422 
423  default:
424  break;
425  }
426  break;
427 
428  case SH_LINE_CHAIN:
429  switch( aB->Type() )
430  {
431  case SH_RECT:
432  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
433 
434  case SH_CIRCLE:
435  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
436 
437  case SH_LINE_CHAIN:
438  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
439 
440  case SH_SEGMENT:
441  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
442 
443  case SH_SIMPLE:
444  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
445 
446  case SH_ARC:
447  return CollCaseReversed<SHAPE_LINE_CHAIN, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
448 
449  default:
450  break;
451  }
452  break;
453 
454  case SH_SEGMENT:
455  switch( aB->Type() )
456  {
457  case SH_RECT:
458  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
459 
460  case SH_CIRCLE:
461  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
462 
463  case SH_LINE_CHAIN:
464  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
465 
466  case SH_SEGMENT:
467  return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
468 
469  case SH_SIMPLE:
470  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
471 
472  case SH_ARC:
473  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
474 
475  default:
476  break;
477  }
478  break;
479 
480  case SH_SIMPLE:
481  switch( aB->Type() )
482  {
483  case SH_RECT:
484  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
485 
486  case SH_CIRCLE:
487  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
488 
489  case SH_LINE_CHAIN:
490  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
491 
492  case SH_SEGMENT:
493  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
494 
495  case SH_SIMPLE:
496  return CollCase<SHAPE_SIMPLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
497 
498  case SH_ARC:
499  return CollCaseReversed<SHAPE_SIMPLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
500 
501  default:
502  break;
503  }
504  break;
505 
506  case SH_ARC:
507  switch( aB->Type() )
508  {
509  case SH_RECT:
510  return CollCase<SHAPE_ARC, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
511 
512  case SH_CIRCLE:
513  return CollCase<SHAPE_ARC, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
514 
515  case SH_LINE_CHAIN:
516  return CollCase<SHAPE_ARC, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
517 
518  case SH_SEGMENT:
519  return CollCase<SHAPE_ARC, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
520 
521  case SH_SIMPLE:
522  return CollCase<SHAPE_ARC, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
523 
524  case SH_ARC:
525  return CollCase<SHAPE_ARC, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
526 
527  default:
528  break;
529  }
530  break;
531 
532  default:
533  break;
534  }
535 
536  bool unsupported_collision = true;
537  (void) unsupported_collision; // make gcc quiet
538 
539  assert( unsupported_collision == false );
540 
541  return false;
542 }
543 
544 
545 bool SHAPE::Collide( const SHAPE* aShape, int aClearance, VECTOR2I& aMTV ) const
546 {
547  return CollideShapes( this, aShape, aClearance, true, aMTV );
548 }
549 
550 
551 bool SHAPE::Collide( const SHAPE* aShape, int aClearance ) const
552 {
553  VECTOR2I dummy;
554 
555  return CollideShapes( this, aShape, aClearance, false, dummy );
556 }
557 
558 
559 bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance ) const
560 {
561  //VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
562  //VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
563  //BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
564 
565  //if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
566  // return false;
567 
568  if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
569  return true;
570 
571  VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
572  VECTOR2I( m_p0.x, m_p0.y + m_h ),
573  VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
574  VECTOR2I( m_p0.x + m_w, m_p0.y ),
575  VECTOR2I( m_p0.x, m_p0.y ) };
576 
577  for( int i = 0; i < 4; i++ )
578  {
579  SEG s( vts[i], vts[i + 1], i );
580 
581  if( s.Distance( aSeg ) < aClearance )
582  return true;
583  }
584 
585  return false;
586 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:145
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:74
Class SHAPE_SIMPLE.
Definition: shape_simple.h:42
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_segment.h:55
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
static const int dist[10][10]
Definition: ar_matrix.cpp:320
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
int GetRadius() const
Definition: shape_circle.h:79
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:139
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
#define abs(a)
Definition: auxiliary.h:84
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
static const int delta[8][2]
Definition: solve.cpp:112
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
const SEG CSegment(int aIndex) const
Function CSegment()
bool CollCaseReversed(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
VECTOR2I::extended_type ecoord
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
int GetWidth() const
Definition: shape_segment.h:80
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
Class SHAPE.
Definition: shape.h:58
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
line chain (polyline)
Definition: shape.h:46
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:107
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:370
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
Definition: seg.h:36
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:299
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
const SEG & GetSeg() const
Definition: shape_segment.h:70
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:83
Class SHAPE_LINE_CHAIN.
size_t i
Definition: json11.cpp:597
VECTOR2I A
Definition: seg.h:46
line segment
Definition: shape.h:45
Definition: shape.h:43
int Distance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Function Distance()
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
circle
Definition: shape.h:47
int SegmentCount() const
Function SegmentCount()
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool CollCase(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
axis-aligned rectangle
Definition: shape.h:44
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:208
VECTOR2I B
Definition: seg.h:47