KiCad PCB EDA Suite
shape_collisions.cpp File Reference

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_SIMPLE &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_SIMPLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_SIMPLE &aA, const SHAPE_SIMPLE &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_SIMPLE &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_SIMPLE &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)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_RECT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_LINE_CHAIN &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_SEGMENT &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_SIMPLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_ARC &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 36 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 353 of file shape_collisions.cpp.

References Collide().

354 {
355  return Collide (*static_cast<const ShapeAType*>( aA ),
356  *static_cast<const ShapeBType*>( aB ),
357  aClearance, aNeedMTV, aMTV);
358 }
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 361 of file shape_collisions.cpp.

References Collide().

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 }
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 38 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().

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 }
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:385
int GetRadius() const
Definition: shape_circle.h:79
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
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:299
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_CIRCLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 58 of file shape_collisions.cpp.

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

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 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
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:385
int GetRadius() const
Definition: shape_circle.h:79
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
VECTOR2< int > VECTOR2I
Definition: vector2d.h:587
#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:36
size_t i
Definition: json11.cpp:597
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 150 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().

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 }
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
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_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 182 of file shape_collisions.cpp.

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

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 }
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
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
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
Class SHAPE_LINE_CHAIN.
int Distance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Function Distance()
static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_SEGMENT aSeg,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 208 of file shape_collisions.cpp.

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

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 }
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 221 of file shape_collisions.cpp.

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

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 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
const SEG CSegment(int aIndex) const
Function CSegment()
size_t i
Definition: json11.cpp:597
int SegmentCount() const
Function SegmentCount()
static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 232 of file shape_collisions.cpp.

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

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

Definition at line 239 of file shape_collisions.cpp.

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

241 {
242  return Collide( aA.Vertices(), aB.Vertices(), aClearance, aNeedMTV, aMTV );
243 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.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 246 of file shape_collisions.cpp.

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

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 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
const SEG CSegment(int aIndex) const
Function CSegment()
Definition: seg.h:36
int SegmentCount() const
Function SegmentCount()
static bool Collide ( const SHAPE_RECT aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 261 of file shape_collisions.cpp.

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

263 {
264  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
265 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.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 268 of file shape_collisions.cpp.

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

270 {
271  return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
272 }
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 275 of file shape_collisions.cpp.

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

277 {
278  return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
279 }
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 282 of file shape_collisions.cpp.

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

284 {
285  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
286  return true;
287 
288  return false;
289 }
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_SIMPLE aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 292 of file shape_collisions.cpp.

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

294 {
295  return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
296 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.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 298 of file shape_collisions.cpp.

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

300 {
301  return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
302 }
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)
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_RECT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 304 of file shape_collisions.cpp.

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

306 {
307  const auto lc = aA.ConvertToPolyline();
308  return Collide( lc, aB.Outline(), aClearance, aNeedMTV, aMTV );
309 }
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)
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
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_CIRCLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 311 of file shape_collisions.cpp.

References Collide(), and SHAPE_ARC::ConvertToPolyline().

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 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
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
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 323 of file shape_collisions.cpp.

References Collide(), and SHAPE_ARC::ConvertToPolyline().

325 {
326  const auto lc = aA.ConvertToPolyline();
327  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
328 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
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
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 330 of file shape_collisions.cpp.

References Collide(), and SHAPE_ARC::ConvertToPolyline().

332 {
333  const auto lc = aA.ConvertToPolyline();
334  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
335 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
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
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 337 of file shape_collisions.cpp.

References Collide(), SHAPE_ARC::ConvertToPolyline(), and SHAPE_SIMPLE::Vertices().

339 {
340  const auto lc = aA.ConvertToPolyline();
341  return Collide( lc, aB.Vertices(), aClearance, aNeedMTV, aMTV );
342 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:139
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
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
static bool Collide ( const SHAPE_ARC aA,
const SHAPE_ARC aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 344 of file shape_collisions.cpp.

References Collide(), and SHAPE_ARC::ConvertToPolyline().

346 {
347  const auto lcA = aA.ConvertToPolyline();
348  const auto lcB = aB.ConvertToPolyline();
349  return Collide( lcA, lcB, aClearance, aNeedMTV, aMTV );
350 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
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
bool CollideShapes ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)

Definition at line 372 of file shape_collisions.cpp.

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

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

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 }
compound shape, consisting of multiple simple shapes
Definition: shape.h:50
line chain (polyline)
Definition: shape.h:46
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:83
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 123 of file shape_collisions.cpp.

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

Referenced by Collide().

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 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:112
const VECTOR2I GetCenter() const
Definition: shape_circle.h:84
static const int dist[10][10]
Definition: ar_matrix.cpp:320
int GetRadius() const
Definition: shape_circle.h:79
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:370
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195