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