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 <cmath>
26 #include <math/vector2d.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  if( aA.Collide( aB.CSegment( s ), aClearance ) )
252  return true;
253  }
254 
255  return false;
256 }
257 
258 
259 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SIMPLE& aB, int aClearance,
260  bool aNeedMTV, VECTOR2I& aMTV )
261 {
262  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
263 }
264 
265 
266 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
267  bool aNeedMTV, VECTOR2I& aMTV )
268 {
269  return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
270 }
271 
272 
273 static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, int aClearance,
274  bool aNeedMTV, VECTOR2I& aMTV )
275 {
276  return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
277 }
278 
279 
280 static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_SEGMENT& aB, int aClearance,
281  bool aNeedMTV, VECTOR2I& aMTV )
282 {
283  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
284  return true;
285 
286  return false;
287 }
288 
289 
290 static inline bool Collide( const SHAPE_SIMPLE& aA, const SHAPE_SEGMENT& aB, int aClearance,
291  bool aNeedMTV, VECTOR2I& aMTV )
292 {
293  return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
294 }
295 
296 static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_RECT& aB, int aClearance,
297  bool aNeedMTV, VECTOR2I& aMTV )
298 {
299  return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
300 }
301 
302 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_RECT& aB, int aClearance,
303  bool aNeedMTV, VECTOR2I& aMTV )
304 {
305  const auto lc = aA.ConvertToPolyline();
306  return Collide( lc, aB.Outline(), aClearance, aNeedMTV, aMTV );
307 }
308 
309 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_CIRCLE& aB, int aClearance,
310  bool aNeedMTV, VECTOR2I& aMTV )
311 {
312  const auto lc = aA.ConvertToPolyline();
313  bool rv = Collide( aB, lc, aClearance, aNeedMTV, aMTV );
314 
315  if( rv && aNeedMTV )
316  aMTV = -aMTV;
317 
318  return rv;
319 }
320 
321 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
322  bool aNeedMTV, VECTOR2I& aMTV )
323 {
324  const auto lc = aA.ConvertToPolyline();
325  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
326 }
327 
328 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SEGMENT& aB, int aClearance,
329  bool aNeedMTV, VECTOR2I& aMTV )
330 {
331  const auto lc = aA.ConvertToPolyline();
332  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
333 }
334 
335 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SIMPLE& aB, int aClearance,
336  bool aNeedMTV, VECTOR2I& aMTV )
337 {
338  const auto lc = aA.ConvertToPolyline();
339  return Collide( lc, aB.Vertices(), aClearance, aNeedMTV, aMTV );
340 }
341 
342 static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_ARC& aB, int aClearance,
343  bool aNeedMTV, VECTOR2I& aMTV )
344 {
345  const auto lcA = aA.ConvertToPolyline();
346  const auto lcB = aB.ConvertToPolyline();
347  return Collide( lcA, lcB, aClearance, aNeedMTV, aMTV );
348 }
349 
350 template<class ShapeAType, class ShapeBType>
351 inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
352 {
353  return Collide (*static_cast<const ShapeAType*>( aA ),
354  *static_cast<const ShapeBType*>( aB ),
355  aClearance, aNeedMTV, aMTV);
356 }
357 
358 template<class ShapeAType, class ShapeBType>
359 inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
360 {
361  bool rv = Collide (*static_cast<const ShapeBType*>( aB ),
362  *static_cast<const ShapeAType*>( aA ),
363  aClearance, aNeedMTV, aMTV);
364  if(rv && aNeedMTV)
365  aMTV = -aMTV;
366  return rv;
367 }
368 
369 
370 bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
371 {
372  switch( aA->Type() )
373  {
374  case SH_RECT:
375  switch( aB->Type() )
376  {
377  case SH_RECT:
378  return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
379 
380  case SH_CIRCLE:
381  return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
382 
383  case SH_LINE_CHAIN:
384  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
385 
386  case SH_SEGMENT:
387  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
388 
389  case SH_SIMPLE:
390  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
391 
392  case SH_ARC:
393  return CollCaseReversed<SHAPE_RECT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
394 
395  default:
396  break;
397  }
398  break;
399 
400  case SH_CIRCLE:
401  switch( aB->Type() )
402  {
403  case SH_RECT:
404  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
405 
406  case SH_CIRCLE:
407  return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
408 
409  case SH_LINE_CHAIN:
410  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
411 
412  case SH_SEGMENT:
413  return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
414 
415  case SH_SIMPLE:
416  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
417 
418  case SH_ARC:
419  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
420 
421  default:
422  break;
423  }
424  break;
425 
426  case SH_LINE_CHAIN:
427  switch( aB->Type() )
428  {
429  case SH_RECT:
430  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
431 
432  case SH_CIRCLE:
433  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
434 
435  case SH_LINE_CHAIN:
436  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
437 
438  case SH_SEGMENT:
439  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
440 
441  case SH_SIMPLE:
442  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
443 
444  case SH_ARC:
445  return CollCaseReversed<SHAPE_LINE_CHAIN, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
446 
447  default:
448  break;
449  }
450  break;
451 
452  case SH_SEGMENT:
453  switch( aB->Type() )
454  {
455  case SH_RECT:
456  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
457 
458  case SH_CIRCLE:
459  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
460 
461  case SH_LINE_CHAIN:
462  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
463 
464  case SH_SEGMENT:
465  return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
466 
467  case SH_SIMPLE:
468  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
469 
470  case SH_ARC:
471  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
472 
473  default:
474  break;
475  }
476  break;
477 
478  case SH_SIMPLE:
479  switch( aB->Type() )
480  {
481  case SH_RECT:
482  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
483 
484  case SH_CIRCLE:
485  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
486 
487  case SH_LINE_CHAIN:
488  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
489 
490  case SH_SEGMENT:
491  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
492 
493  case SH_SIMPLE:
494  return CollCase<SHAPE_SIMPLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
495 
496  case SH_ARC:
497  return CollCaseReversed<SHAPE_SIMPLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
498 
499  default:
500  break;
501  }
502  break;
503 
504  case SH_ARC:
505  switch( aB->Type() )
506  {
507  case SH_RECT:
508  return CollCase<SHAPE_ARC, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
509 
510  case SH_CIRCLE:
511  return CollCase<SHAPE_ARC, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
512 
513  case SH_LINE_CHAIN:
514  return CollCase<SHAPE_ARC, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
515 
516  case SH_SEGMENT:
517  return CollCase<SHAPE_ARC, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
518 
519  case SH_SIMPLE:
520  return CollCase<SHAPE_ARC, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
521 
522  case SH_ARC:
523  return CollCase<SHAPE_ARC, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
524 
525  default:
526  break;
527  }
528  break;
529 
530  default:
531  break;
532  }
533 
534  bool unsupported_collision = true;
535  (void) unsupported_collision; // make gcc quiet
536 
537  assert( unsupported_collision == false );
538 
539  return false;
540 }
541 
542 
543 bool SHAPE::Collide( const SHAPE* aShape, int aClearance, VECTOR2I& aMTV ) const
544 {
545  return CollideShapes( this, aShape, aClearance, true, aMTV );
546 }
547 
548 
549 bool SHAPE::Collide( const SHAPE* aShape, int aClearance ) const
550 {
551  VECTOR2I dummy;
552 
553  return CollideShapes( this, aShape, aClearance, false, dummy );
554 }
555 
556 
557 bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance ) const
558 {
559  //VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
560  //VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
561  //BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
562 
563  //if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
564  // return false;
565 
566  if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
567  return true;
568 
569  VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
570  VECTOR2I( m_p0.x, m_p0.y + m_h ),
571  VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
572  VECTOR2I( m_p0.x + m_w, m_p0.y ),
573  VECTOR2I( m_p0.x, m_p0.y ) };
574 
575  for( int i = 0; i < 4; i++ )
576  {
577  SEG s( vts[i], vts[i + 1], i );
578 
579  if( s.Distance( aSeg ) < aClearance )
580  return true;
581  }
582 
583  return false;
584 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:123
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
void SetCenter(const VECTOR2I &aCenter)
Definition: shape_circle.h:74
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:199
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 SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:145
static const int dist[10][10]
Definition: ar_matrix.cpp:320
int GetRadius() const
Definition: shape_circle.h:79
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:83
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:299
int Distance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Function Distance()
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
virtual bool Collide(const VECTOR2I &aP, int aClearance=0) const
Function Collide()
Definition: shape.h:107
#define abs(a)
Definition: auxiliary.h:84
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
const SEG & GetSeg() const
Definition: shape_segment.h:70
VECTOR2I::extended_type ecoord
Definition: pns_item.cpp:26
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
VECTOR2I m_p0
Top-left corner
Definition: shape_rect.h:159
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
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:165
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:374
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
Class SHAPE.
Definition: shape.h:58
int m_w
Width
Definition: shape_rect.h:162
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
int SegmentCount() const
Function SegmentCount()
line chain (polyline)
Definition: shape.h:46
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
Definition: seg.h:36
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
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.
Class SHAPE_LINE_CHAIN.
const BOX2I BBox(int aClearance=0) const override
Function BBox()
Definition: shape_rect.h:73
size_t i
Definition: json11.cpp:649
VECTOR2I A
Definition: seg.h:44
line segment
Definition: shape.h:45
Definition: shape.h:43
int GetWidth() const
Definition: shape_segment.h:80
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:240
circle
Definition: shape.h:47
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
VECTOR2I B
Definition: seg.h:45