KiCad PCB EDA Suite
shape_collisions.cpp File Reference
#include <math/vector2d.h>
#include <math.h>
#include <geometry/shape.h>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_circle.h>
#include <geometry/shape_rect.h>
#include <geometry/shape_segment.h>
#include <geometry/shape_convex.h>

Go to the source code of this file.

Typedefs

typedef VECTOR2I::extended_type ecoord
 

Functions

static bool Collide (const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static VECTOR2I pushoutForce (const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
 
static bool Collide (const SHAPE_CIRCLE &aA, const SHAPE_LINE_CHAIN &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_CIRCLE &aA, const SHAPE_CONVEX &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_CIRCLE &aA, const SHAPE_SEGMENT &aSeg, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_LINE_CHAIN &aA, const SHAPE_LINE_CHAIN &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_LINE_CHAIN &aA, const SHAPE_CONVEX &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_CONVEX &aA, const SHAPE_CONVEX &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_LINE_CHAIN &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_CONVEX &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_SEGMENT &aSeg, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_SEGMENT &aA, const SHAPE_SEGMENT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_LINE_CHAIN &aA, const SHAPE_SEGMENT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_CONVEX &aA, const SHAPE_SEGMENT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_RECT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
template<class ShapeAType , class ShapeBType >
bool CollCase (const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
template<class ShapeAType , class ShapeBType >
bool CollCaseReversed (const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
bool CollideShapes (const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 

Typedef Documentation

Definition at line 35 of file shape_collisions.cpp.

Function Documentation

template<class ShapeAType , class ShapeBType >
bool CollCase ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inline

Definition at line 305 of file shape_collisions.cpp.

References Collide().

306 {
307  return Collide (*static_cast<const ShapeAType*>( aA ),
308  *static_cast<const ShapeBType*>( aB ),
309  aClearance, aNeedMTV, aMTV);
310 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
template<class ShapeAType , class ShapeBType >
bool CollCaseReversed ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inline

Definition at line 313 of file shape_collisions.cpp.

References Collide().

314 {
315  bool rv = Collide (*static_cast<const ShapeBType*>( aB ),
316  *static_cast<const ShapeAType*>( aA ),
317  aClearance, aNeedMTV, aMTV);
318  if(rv && aNeedMTV)
319  aMTV = -aMTV;
320  return rv;
321 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_CIRCLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 37 of file shape_collisions.cpp.

References delta, SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), VECTOR2< T >::Resize(), and VECTOR2< T >::SquaredEuclideanNorm().

Referenced by CollCase(), CollCaseReversed(), and Collide().

39 {
40  ecoord min_dist = aClearance + aA.GetRadius() + aB.GetRadius();
41  ecoord min_dist_sq = min_dist * min_dist;
42 
43  const VECTOR2I delta = aB.GetCenter() - aA.GetCenter();
44 
45  ecoord dist_sq = delta.SquaredEuclideanNorm();
46 
47  if( dist_sq >= min_dist_sq )
48  return false;
49 
50  if( aNeedMTV )
51  aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
52 
53  return true;
54 }
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
int GetRadius() const
Definition: shape_circle.h:79
static const int delta[8][2]
Definition: solve.cpp:112
VECTOR2I::extended_type ecoord
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:302
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_CIRCLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 57 of file shape_collisions.cpp.

References abs, delta, EuclideanNorm(), SHAPE_CIRCLE::GetCenter(), SHAPE_RECT::GetPosition(), SHAPE_CIRCLE::GetRadius(), SHAPE_RECT::GetSize(), SEG::NearestPoint(), VECTOR2< T >::Resize(), VECTOR2< T >::x, and VECTOR2< T >::y.

59 {
60  const VECTOR2I c = aB.GetCenter();
61  const VECTOR2I p0 = aA.GetPosition();
62  const VECTOR2I size = aA.GetSize();
63  const int r = aB.GetRadius();
64  const int min_dist = aClearance + r;
65 
66  const VECTOR2I vts[] =
67  {
68  VECTOR2I( p0.x, p0.y ),
69  VECTOR2I( p0.x, p0.y + size.y ),
70  VECTOR2I( p0.x + size.x, p0.y + size.y ),
71  VECTOR2I( p0.x + size.x, p0.y ),
72  VECTOR2I( p0.x, p0.y )
73  };
74 
75  int nearest_seg_dist = INT_MAX;
76  VECTOR2I nearest;
77 
78  bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
79  && c.y >= p0.y && c.y <= ( p0.y + size.y );
80 
81 
82  if( !aNeedMTV && inside )
83  return true;
84 
85  for( int i = 0; i < 4; i++ )
86  {
87  const SEG seg( vts[i], vts[i + 1] );
88 
89  VECTOR2I pn = seg.NearestPoint( c );
90 
91  int d = ( pn - c ).EuclideanNorm();
92 
93  if( ( d < min_dist ) && !aNeedMTV )
94  return true;
95 
96  if( d < nearest_seg_dist )
97  {
98  nearest = pn;
99  nearest_seg_dist = d;
100  }
101  }
102 
103  if( nearest_seg_dist >= min_dist && !inside )
104  return false;
105 
106  VECTOR2I delta = c - nearest;
107 
108  if( !aNeedMTV )
109  return true;
110 
111 
112  if( inside )
113  aMTV = -delta.Resize( abs( min_dist + 1 + nearest_seg_dist ) + 1 );
114  else
115  aMTV = delta.Resize( abs( min_dist + 1 - nearest_seg_dist ) + 1 );
116 
117 
118  return true;
119 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:388
int GetRadius() const
Definition: shape_circle.h:79
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
#define abs(a)
Definition: auxiliary.h:84
static const int delta[8][2]
Definition: solve.cpp:112
const VECTOR2I & GetPosition() const
Function GetPosition()
Definition: shape_rect.h:100
Definition: seg.h:37
const VECTOR2I GetSize() const
Function GetSize()
Definition: shape_rect.h:110
static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 149 of file shape_collisions.cpp.

References SHAPE_CIRCLE::Collide(), SHAPE_LINE_CHAIN::CSegment(), SHAPE_CIRCLE::GetCenter(), pushoutForce(), SHAPE_LINE_CHAIN::SegmentCount(), and SHAPE_CIRCLE::SetCenter().

151 {
152  bool found = false;
153 
154  for( int s = 0; s < aB.SegmentCount(); s++ )
155  {
156  if( aA.Collide( aB.CSegment( s ), aClearance ) )
157  {
158  found = true;
159  break;
160  }
161  }
162 
163  if( !aNeedMTV || !found )
164  return found;
165 
166  SHAPE_CIRCLE cmoved( aA );
167  VECTOR2I f_total( 0, 0 );
168 
169  for( int s = 0; s < aB.SegmentCount(); s++ )
170  {
171  VECTOR2I f = pushoutForce( cmoved, aB.CSegment( s ), aClearance );
172  cmoved.SetCenter( cmoved.GetCenter() + f );
173  f_total += f;
174  }
175 
176  aMTV = f_total;
177  return found;
178 }
const SEG CSegment(int aIndex) const
Function CSegment()
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
int SegmentCount() const
Function SegmentCount()
static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_CONVEX aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 181 of file shape_collisions.cpp.

References SHAPE_LINE_CHAIN::Distance(), SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), pushoutForce(), SHAPE_CIRCLE::SetCenter(), and SHAPE_CONVEX::Vertices().

183 {
184  bool found;
185  const SHAPE_LINE_CHAIN& lc( aB.Vertices() );
186 
187  found = lc.Distance( aA.GetCenter() ) <= aClearance + aA.GetRadius();
188 
189  if( !aNeedMTV || !found )
190  return found;
191 
192  SHAPE_CIRCLE cmoved( aA );
193  VECTOR2I f_total( 0, 0 );
194 
195  for( int s = 0; s < lc.SegmentCount(); s++ )
196  {
197  VECTOR2I f = pushoutForce( cmoved, lc.CSegment( s ), aClearance );
198  cmoved.SetCenter( cmoved.GetCenter() + f );
199  f_total += f;
200  }
201 
202  aMTV = f_total;
203  return found;
204 }
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
int GetRadius() const
Definition: shape_circle.h:79
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
int Distance(const VECTOR2I &aP) const
Function Distance()
Class SHAPE_LINE_CHAIN.
static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_SEGMENT aSeg,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 207 of file shape_collisions.cpp.

References SHAPE_CIRCLE::Collide(), SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), and pushoutForce().

209 {
210  bool col = aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
211 
212  if( col && aNeedMTV )
213  {
214  aMTV = -pushoutForce( aA, aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
215  }
216  return col;
217 }
int GetWidth() const
Definition: shape_segment.h:80
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:62
const SEG & GetSeg() const
Definition: shape_segment.h:70
static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 220 of file shape_collisions.cpp.

References SHAPE_LINE_CHAIN::Collide(), SHAPE_LINE_CHAIN::CSegment(), and SHAPE_LINE_CHAIN::SegmentCount().

222 {
223  for( int i = 0; i < aB.SegmentCount(); i++ )
224  if( aA.Collide( aB.CSegment( i ), aClearance ) )
225  return true;
226 
227  return false;
228 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
const SEG CSegment(int aIndex) const
Function CSegment()
int SegmentCount() const
Function SegmentCount()
static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_CONVEX aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 231 of file shape_collisions.cpp.

References Collide(), and SHAPE_CONVEX::Vertices().

233 {
234  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
235 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
static bool Collide ( const SHAPE_CONVEX aA,
const SHAPE_CONVEX aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 238 of file shape_collisions.cpp.

References Collide(), and SHAPE_CONVEX::Vertices().

240 {
241  return Collide( aA.Vertices(), aB.Vertices(), aClearance, aNeedMTV, aMTV );
242 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 245 of file shape_collisions.cpp.

References SHAPE_RECT::Collide(), SHAPE_LINE_CHAIN::CSegment(), and SHAPE_LINE_CHAIN::SegmentCount().

247 {
248  for( int s = 0; s < aB.SegmentCount(); s++ )
249  {
250  SEG seg = aB.CSegment( s );
251 
252  if( aA.Collide( seg, aClearance ) )
253  return true;
254  }
255 
256  return false;
257 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
const SEG CSegment(int aIndex) const
Function CSegment()
Definition: seg.h:37
int SegmentCount() const
Function SegmentCount()
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_CONVEX aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 260 of file shape_collisions.cpp.

References Collide(), and SHAPE_CONVEX::Vertices().

262 {
263  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
264 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_SEGMENT aSeg,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 267 of file shape_collisions.cpp.

References SHAPE_RECT::Collide(), SHAPE_SEGMENT::GetSeg(), and SHAPE_SEGMENT::GetWidth().

269 {
270  return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
271 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
int GetWidth() const
Definition: shape_segment.h:80
const SEG & GetSeg() const
Definition: shape_segment.h:70
static bool Collide ( const SHAPE_SEGMENT aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 274 of file shape_collisions.cpp.

References SHAPE_SEGMENT::Collide(), SHAPE_SEGMENT::GetSeg(), and SHAPE_SEGMENT::GetWidth().

276 {
277  return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
278 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_segment.h:55
int GetWidth() const
Definition: shape_segment.h:80
const SEG & GetSeg() const
Definition: shape_segment.h:70
static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 281 of file shape_collisions.cpp.

References SHAPE_LINE_CHAIN::Collide(), SHAPE_SEGMENT::GetSeg(), and SHAPE_SEGMENT::GetWidth().

283 {
284  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
285  return true;
286 
287  return false;
288 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
int GetWidth() const
Definition: shape_segment.h:80
const SEG & GetSeg() const
Definition: shape_segment.h:70
static bool Collide ( const SHAPE_CONVEX aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 291 of file shape_collisions.cpp.

References Collide(), and SHAPE_CONVEX::Vertices().

293 {
294  return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
295 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_convex.h:139
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_RECT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 297 of file shape_collisions.cpp.

References Collide(), and SHAPE_RECT::Outline().

299 {
300  return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
301 }
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:145
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool CollideShapes ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)

Definition at line 324 of file shape_collisions.cpp.

References SH_CIRCLE, SH_CONVEX, SH_LINE_CHAIN, SH_RECT, SH_SEGMENT, and SHAPE::Type().

Referenced by SHAPE::Collide(), PNS::SHOVE::onCollidingVia(), and PNS::VIA::PushoutForce().

325 {
326  switch( aA->Type() )
327  {
328  case SH_RECT:
329  switch( aB->Type() )
330  {
331  case SH_RECT:
332  return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
333 
334  case SH_CIRCLE:
335  return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
336 
337  case SH_LINE_CHAIN:
338  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
339 
340  case SH_SEGMENT:
341  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
342 
343  case SH_CONVEX:
344  return CollCase<SHAPE_RECT, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
345 
346  default:
347  break;
348  }
349  break;
350 
351  case SH_CIRCLE:
352  switch( aB->Type() )
353  {
354  case SH_RECT:
355  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
356 
357  case SH_CIRCLE:
358  return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
359 
360  case SH_LINE_CHAIN:
361  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
362 
363  case SH_SEGMENT:
364  return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
365 
366  case SH_CONVEX:
367  return CollCase<SHAPE_CIRCLE, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
368 
369  default:
370  break;
371  }
372  break;
373 
374  case SH_LINE_CHAIN:
375  switch( aB->Type() )
376  {
377  case SH_RECT:
378  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
379 
380  case SH_CIRCLE:
381  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
382 
383  case SH_LINE_CHAIN:
384  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
385 
386  case SH_SEGMENT:
387  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
388 
389  case SH_CONVEX:
390  return CollCase<SHAPE_LINE_CHAIN, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
391 
392  default:
393  break;
394  }
395  break;
396 
397  case SH_SEGMENT:
398  switch( aB->Type() )
399  {
400  case SH_RECT:
401  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
402 
403  case SH_CIRCLE:
404  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
405 
406  case SH_LINE_CHAIN:
407  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
408 
409  case SH_SEGMENT:
410  return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
411 
412  case SH_CONVEX:
413  return CollCase<SHAPE_CONVEX, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
414 
415  default:
416  break;
417  }
418  break;
419 
420  case SH_CONVEX:
421  switch( aB->Type() )
422  {
423  case SH_RECT:
424  return CollCase<SHAPE_RECT, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
425 
426  case SH_CIRCLE:
427  return CollCase<SHAPE_CIRCLE, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
428 
429  case SH_LINE_CHAIN:
430  return CollCase<SHAPE_LINE_CHAIN, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
431 
432  case SH_SEGMENT:
433  return CollCase<SHAPE_CONVEX, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
434 
435  case SH_CONVEX:
436  return CollCase<SHAPE_CONVEX, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
437 
438  default:
439  break;
440  }
441  break;
442 
443  default:
444  break;
445  }
446 
447  bool unsupported_collision = true;
448  (void) unsupported_collision; // make gcc quiet
449 
450  assert( unsupported_collision == false );
451 
452  return false;
453 }
line chain (polyline)
Definition: shape.h:46
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:82
line segment
Definition: shape.h:45
Definition: shape.h:43
circle
Definition: shape.h:47
axis-aligned rectangle
Definition: shape.h:44
static VECTOR2I pushoutForce ( const SHAPE_CIRCLE aA,
const SEG aB,
int  aClearance 
)
static

Definition at line 122 of file shape_collisions.cpp.

References dist, SEG::Distance(), EuclideanNorm(), SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), and SEG::NearestPoint().

Referenced by Collide().

123 {
124  VECTOR2I f( 0, 0 );
125 
126  const VECTOR2I c = aA.GetCenter();
127  const VECTOR2I nearest = aB.NearestPoint( c );
128 
129  const int r = aA.GetRadius();
130 
131  int dist = ( nearest - c ).EuclideanNorm();
132  int min_dist = aClearance + r;
133 
134  if( dist < min_dist )
135  {
136  for( int corr = 0; corr < 5; corr++ )
137  {
138  f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
139 
140  if( aB.Distance( c + f ) >= min_dist )
141  break;
142  }
143  }
144 
145  return f;
146 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:104
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
int GetRadius() const
Definition: shape_circle.h:79
static const int dist[10][10]
Definition: dist.cpp:57
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:397
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:228