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