KiCad PCB EDA Suite
shape_collisions.cpp File Reference
#include <cmath>
#include <limits.h>
#include <geometry/seg.h>
#include <geometry/shape.h>
#include <geometry/shape_arc.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_compound.h>
#include <math/vector2d.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, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, 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_BASE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_CIRCLE &aA, const SHAPE_SEGMENT &aSeg, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_LINE_CHAIN_BASE &aA, const SHAPE_LINE_CHAIN_BASE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_LINE_CHAIN_BASE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_SEGMENT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_SEGMENT &aA, const SHAPE_SEGMENT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_LINE_CHAIN_BASE &aA, const SHAPE_SEGMENT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_RECT &aA, const SHAPE_RECT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_RECT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_LINE_CHAIN &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_SEGMENT &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_LINE_CHAIN_BASE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool Collide (const SHAPE_ARC &aA, const SHAPE_ARC &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
template<class T_a , class T_b >
bool CollCase (const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
template<class T_a , class T_b >
bool CollCaseReversed (const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool collideSingleShapes (const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 
static bool collideShapes (const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
 

Typedef Documentation

◆ ecoord

Definition at line 39 of file shape_collisions.cpp.

Function Documentation

◆ CollCase()

template<class T_a , class T_b >
bool CollCase ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inline

Definition at line 533 of file shape_collisions.cpp.

536 {
537  return Collide( *static_cast<const T_a*>( aA ), *static_cast<const T_b*>( aB ),
538  aClearance, aActual, aLocation, aMTV);
539 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)

References Collide().

◆ CollCaseReversed()

template<class T_a , class T_b >
bool CollCaseReversed ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inline

Definition at line 543 of file shape_collisions.cpp.

545 {
546  bool rv = Collide( *static_cast<const T_b*>( aB ), *static_cast<const T_a*>( aA ),
547  aClearance, aActual, aLocation, aMTV);
548 
549  if( rv && aMTV)
550  *aMTV = - *aMTV;
551 
552  return rv;
553 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)

References Collide().

◆ Collide() [1/16]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_CIRCLE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 42 of file shape_collisions.cpp.

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  ecoord dist_sq = delta.SquaredEuclideanNorm();
50 
51  if( dist_sq == 0 || dist_sq < min_dist_sq )
52  {
53  if( aActual )
54  *aActual = std::max( 0, (int) sqrt( dist_sq ) - aA.GetRadius() - aB.GetRadius() );
55 
56  if( aLocation )
57  *aLocation = ( aA.GetCenter() + aB.GetCenter() ) / 2;
58 
59  if( aMTV )
60  *aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
61 
62  return true;
63  }
64 
65  return false;
66 }
int GetRadius() const
Definition: shape_circle.h:107
Define a general 2D-vector/point.
Definition: vector2d.h:61
extended_type SquaredEuclideanNorm() const
Compute the squared euclidean norm of the vector, which is defined as (x ** 2 + y ** 2).
Definition: vector2d.h:300
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
VECTOR2I::extended_type ecoord
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404

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

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

◆ Collide() [2/16]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_CIRCLE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 69 of file shape_collisions.cpp.

71 {
72  const VECTOR2I c = aB.GetCenter();
73  const VECTOR2I p0 = aA.GetPosition();
74  const VECTOR2I size = aA.GetSize();
75  const int r = aB.GetRadius();
76  const int min_dist = aClearance + r;
77  const ecoord min_dist_sq = SEG::Square( min_dist );
78 
79  const VECTOR2I vts[] =
80  {
81  VECTOR2I( p0.x, p0.y ),
82  VECTOR2I( p0.x, p0.y + size.y ),
83  VECTOR2I( p0.x + size.x, p0.y + size.y ),
84  VECTOR2I( p0.x + size.x, p0.y ),
85  VECTOR2I( p0.x, p0.y )
86  };
87 
88  ecoord nearest_side_dist_sq = VECTOR2I::ECOORD_MAX;
89  VECTOR2I nearest;
90 
91  bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
92  && c.y >= p0.y && c.y <= ( p0.y + size.y );
93 
94  // If we're not looking for MTV or actual, short-circuit once we find a hard collision
95  if( inside && !aActual && !aLocation && !aMTV )
96  return true;
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 < nearest_side_dist_sq )
106  {
107  nearest = pn;
108  nearest_side_dist_sq = side_dist_sq;
109 
110  if( aMTV )
111  continue;
112 
113  if( nearest_side_dist_sq == 0 )
114  break;
115 
116  // If we're not looking for aActual then any collision will do
117  if( nearest_side_dist_sq < min_dist_sq && !aActual )
118  break;
119  }
120  }
121 
122  if( inside || nearest_side_dist_sq == 0 || nearest_side_dist_sq < min_dist_sq )
123  {
124  if( aLocation )
125  *aLocation = nearest;
126 
127  if( aActual )
128  *aActual = std::max( 0, (int) sqrt( nearest_side_dist_sq ) - r );
129 
130  if( aMTV )
131  {
132  VECTOR2I delta = c - nearest;
133 
134  if( inside )
135  *aMTV = -delta.Resize( abs( min_dist + 1 + sqrt( nearest_side_dist_sq ) ) + 1 );
136  else
137  *aMTV = delta.Resize( abs( min_dist + 1 - sqrt( nearest_side_dist_sq ) ) + 1 );
138  }
139 
140  return true;
141  }
142 
143  return false;
144 }
int GetRadius() const
Definition: shape_circle.h:107
Define a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
static SEG::ecoord Square(int a)
Definition: seg.h:123
const VECTOR2I GetSize() const
Definition: shape_rect.h:124
static constexpr extended_type ECOORD_MAX
Definition: vector2d.h:79
const VECTOR2I & GetPosition() const
Definition: shape_rect.h:116
VECTOR2I::extended_type ecoord
Definition: seg.h:41
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:404

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

◆ Collide() [3/16]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_LINE_CHAIN_BASE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 174 of file shape_collisions.cpp.

176 {
177  int closest_dist = INT_MAX;
178  int closest_mtv_dist = INT_MAX;
179  VECTOR2I nearest;
180  int closest_mtv_seg = -1;
181 
182  if( aB.IsClosed() && aB.PointInside( aA.GetCenter() ) )
183  {
184  nearest = aA.GetCenter();
185  closest_dist = 0;
186 
187  if( aMTV )
188  {
189  for( int s = 0; s < aB.GetSegmentCount(); s++ )
190  {
191  int dist = aB.GetSegment(s).Distance( aA.GetCenter() );
192 
193  if( dist < closest_mtv_dist )
194  {
195  closest_mtv_dist = dist;
196  closest_mtv_seg = s;
197  }
198  }
199  }
200 
201  }
202  else
203  {
204  for( size_t s = 0; s < aB.GetSegmentCount(); s++ )
205  {
206  int collision_dist = 0;
207  VECTOR2I pn;
208 
209  if( aA.Collide( aB.GetSegment( s ), aClearance,
210  aActual || aLocation ? &collision_dist : nullptr,
211  aLocation ? &pn : nullptr ) )
212  {
213  if( collision_dist < closest_dist )
214  {
215  nearest = pn;
216  closest_dist = collision_dist;
217  }
218 
219  if( closest_dist == 0 )
220  break;
221 
222  // If we're not looking for aActual then any collision will do
223  if( !aActual )
224  break;
225  }
226  }
227  }
228 
229  if( closest_dist == 0 || closest_dist < aClearance )
230  {
231  if( aLocation )
232  *aLocation = nearest;
233 
234  if( aActual )
235  *aActual = closest_dist;
236 
237  if( aMTV )
238  {
239  SHAPE_CIRCLE cmoved( aA );
240  VECTOR2I f_total( 0, 0 );
241 
242  VECTOR2I f;
243 
244  if (closest_mtv_seg >= 0)
245  {
246  SEG cs = aB.GetSegment( closest_mtv_seg );
247  VECTOR2I np = cs.NearestPoint( aA.GetCenter() );
248  f = ( np - aA.GetCenter() ) + ( np - aA.GetCenter() ).Resize( aA.GetRadius() );
249  }
250 
251  cmoved.SetCenter( cmoved.GetCenter() + f );
252  f_total += f;
253 
254  for( int s = 0; s < aB.GetSegmentCount(); s++ )
255  {
256  VECTOR2I f = pushoutForce( cmoved, aB.GetSegment( s ), aClearance );
257  cmoved.SetCenter( cmoved.GetCenter() + f );
258  f_total += f;
259  }
260 
261  *aMTV = f_total;
262  }
263 
264  return true;
265  }
266 
267  return false;
268 }
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.h:239
int GetRadius() const
Definition: shape_circle.h:107
virtual bool IsClosed() const =0
Define a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
virtual size_t GetSegmentCount() const =0
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition: shape_circle.h:76
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.h:437
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
Definition: seg.h:41
virtual const SEG GetSegment(int aIndex) const =0

References SHAPE_CIRCLE::Collide(), SEG::Distance(), SHAPE_CIRCLE::GetCenter(), SHAPE_CIRCLE::GetRadius(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SEG::NearestPoint(), SHAPE_LINE_CHAIN_BASE::PointInside(), pushoutForce(), and SHAPE_CIRCLE::SetCenter().

◆ Collide() [4/16]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_SEGMENT aSeg,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 271 of file shape_collisions.cpp.

273 {
274  if( aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2, aActual, aLocation ) )
275  {
276  if( aMTV )
277  *aMTV = -pushoutForce( aA, aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
278 
279  if( aActual )
280  *aActual = std::max( 0, *aActual - aSeg.GetWidth() / 2 );
281 
282  return true;
283  }
284 
285  return false;
286 }
const SEG & GetSeg() const
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
Definition: shape_circle.h:76
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
int GetWidth() const

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

◆ Collide() [5/16]

static bool Collide ( const SHAPE_LINE_CHAIN_BASE aA,
const SHAPE_LINE_CHAIN_BASE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 289 of file shape_collisions.cpp.

291 {
292  wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
293  aA.Type(),
294  aB.Type() ) );
295 
296  int closest_dist = INT_MAX;
297  VECTOR2I nearest;
298 
299  if( aB.IsClosed() && aA.GetPointCount() > 0 && aB.PointInside( aA.GetPoint( 0 ) ) )
300  {
301  closest_dist = 0;
302  nearest = aA.GetPoint( 0 );
303  }
304  else
305  {
306  for( size_t i = 0; i < aB.GetSegmentCount(); i++ )
307  {
308  int collision_dist = 0;
309  VECTOR2I pn;
310 
311  if( aA.Collide( aB.GetSegment( i ), aClearance,
312  aActual || aLocation ? &collision_dist : nullptr,
313  aLocation ? &pn : nullptr ) )
314  {
315  if( collision_dist < closest_dist )
316  {
317  nearest = pn;
318  closest_dist = collision_dist;
319  }
320 
321  if( closest_dist == 0 )
322  break;
323 
324  // If we're not looking for aActual then any collision will do
325  if( !aActual )
326  break;
327  }
328  }
329  }
330 
331  if( closest_dist == 0 || closest_dist < aClearance )
332  {
333  if( aLocation )
334  *aLocation = nearest;
335 
336  if( aActual )
337  *aActual = closest_dist;
338 
339  return true;
340  }
341 
342  return false;
343 }
virtual bool IsClosed() const =0
Define a general 2D-vector/point.
Definition: vector2d.h:61
virtual size_t GetPointCount() const =0
virtual size_t GetSegmentCount() const =0
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual const SEG GetSegment(int aIndex) const =0
virtual const VECTOR2I GetPoint(int aIndex) const =0
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

References SHAPE_LINE_CHAIN_BASE::Collide(), Format(), SHAPE_LINE_CHAIN_BASE::GetPoint(), SHAPE_LINE_CHAIN_BASE::GetPointCount(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SHAPE_BASE::Type().

◆ Collide() [6/16]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_LINE_CHAIN_BASE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 346 of file shape_collisions.cpp.

348 {
349  wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
350  aA.Type(),
351  aB.Type() ) );
352 
353  int closest_dist = INT_MAX;
354  VECTOR2I nearest;
355 
356  if( aB.IsClosed() && aB.PointInside( aA.Centre() ) )
357  {
358  nearest = aA.Centre();
359  closest_dist = 0;
360  }
361  else
362  {
363  for( size_t s = 0; s < aB.GetSegmentCount(); s++ )
364  {
365  int collision_dist = 0;
366  VECTOR2I pn;
367 
368  if( aA.Collide( aB.GetSegment( s ), aClearance,
369  aActual || aLocation ? &collision_dist : nullptr,
370  aLocation ? &pn : nullptr ) )
371  {
372  if( collision_dist < closest_dist )
373  {
374  nearest = pn;
375  closest_dist = collision_dist;
376  }
377 
378  if( closest_dist == 0 )
379  break;
380 
381  // If we're not looking for aActual then any collision will do
382  if( !aActual )
383  break;
384  }
385  }
386  }
387 
388  if( closest_dist == 0 || closest_dist < aClearance )
389  {
390  if( aLocation )
391  *aLocation = nearest;
392 
393  if( aActual )
394  *aActual = closest_dist;
395 
396  return true;
397  }
398 
399  return false;
400 }
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition: shape_rect.h:98
virtual bool IsClosed() const =0
Define a general 2D-vector/point.
Definition: vector2d.h:61
virtual VECTOR2I Centre() const
Compute a center-of-mass of the shape.
Definition: shape.h:216
virtual size_t GetSegmentCount() const =0
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const
Check if point aP lies inside a polygon (any type) defined by the line chain.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
virtual const SEG GetSegment(int aIndex) const =0
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

References SHAPE::Centre(), SHAPE_RECT::Collide(), Format(), SHAPE_LINE_CHAIN_BASE::GetSegment(), SHAPE_LINE_CHAIN_BASE::GetSegmentCount(), SHAPE_LINE_CHAIN_BASE::IsClosed(), SHAPE_LINE_CHAIN_BASE::PointInside(), and SHAPE_BASE::Type().

◆ Collide() [7/16]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_SEGMENT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 403 of file shape_collisions.cpp.

405 {
406  wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
407  aA.Type(),
408  aB.Type() ) );
409 
410  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
411  {
412  if( aActual )
413  *aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
414 
415  return true;
416  }
417 
418  return false;
419 }
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition: shape_rect.h:98
const SEG & GetSeg() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int GetWidth() const
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

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

◆ Collide() [8/16]

static bool Collide ( const SHAPE_SEGMENT aA,
const SHAPE_SEGMENT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 422 of file shape_collisions.cpp.

424 {
425  wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
426  aA.Type(),
427  aB.Type() ) );
428 
429  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
430  {
431  if( aActual )
432  *aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
433 
434  return true;
435  }
436 
437  return false;
438 }
const SEG & GetSeg() const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int GetWidth() const
bool Collide(const SHAPE *aShape, int aClearance, VECTOR2I *aMTV) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
Definition: shape_segment.h:67
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

References SHAPE_SEGMENT::Collide(), Format(), SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), and SHAPE_BASE::Type().

◆ Collide() [9/16]

static bool Collide ( const SHAPE_LINE_CHAIN_BASE aA,
const SHAPE_SEGMENT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 441 of file shape_collisions.cpp.

443 {
444  wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
445  aA.Type(),
446  aB.Type() ) );
447 
448  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
449  {
450  if( aActual )
451  *aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
452 
453  return true;
454  }
455 
456  return false;
457 }
const SEG & GetSeg() const
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int GetWidth() const
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

References SHAPE_LINE_CHAIN_BASE::Collide(), Format(), SHAPE_SEGMENT::GetSeg(), SHAPE_SEGMENT::GetWidth(), and SHAPE_BASE::Type().

◆ Collide() [10/16]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_RECT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 460 of file shape_collisions.cpp.

462 {
463  return Collide( aA.Outline(), aB.Outline(), aClearance, aActual, aLocation, aMTV );
464 }
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:170
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)

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

◆ Collide() [11/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_RECT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 467 of file shape_collisions.cpp.

469 {
470  int clearance = aClearance + ( aA.GetWidth() / 2 );
471  const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
472 
473  return Collide( lc, aB.Outline(), clearance, aActual, aLocation, aMTV );
474 }
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:170
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ Collide() [12/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_CIRCLE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 477 of file shape_collisions.cpp.

479 {
480  const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
481  int clearance = aClearance + ( aA.GetWidth() / 2 );
482  bool rv = Collide( aB, lc, clearance, aActual, aLocation, aMTV );
483 
484  if( rv && aMTV )
485  *aMTV = - *aMTV ;
486 
487  return rv;
488 }
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ Collide() [13/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 491 of file shape_collisions.cpp.

493 {
494  int clearance = aClearance + ( aA.GetWidth() / 2 );
495  const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
496 
497  return Collide( lc, aB, clearance, aActual, aLocation, aMTV );
498 }
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ Collide() [14/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_SEGMENT aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 501 of file shape_collisions.cpp.

503 {
504  int clearance = aClearance + ( aA.GetWidth() / 2 );
505  const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
506 
507  return Collide( lc, aB, clearance, aActual, aLocation, aMTV );
508 }
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ Collide() [15/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_LINE_CHAIN_BASE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 511 of file shape_collisions.cpp.

513 {
514  int clearance = aClearance + ( aA.GetWidth() / 2 );
515  const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
516 
517  return Collide( lc, aB, clearance, aActual, aLocation, aMTV );
518 }
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ Collide() [16/16]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_ARC aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 521 of file shape_collisions.cpp.

523 {
524  const SHAPE_LINE_CHAIN lcA = aA.ConvertToPolyline();
525  const SHAPE_LINE_CHAIN lcB = aB.ConvertToPolyline();
526  int clearance = aClearance + ( aA.GetWidth() / 2 ) + ( aB.GetWidth() / 2 );
527 
528  return Collide( lcA, lcB, clearance, aActual, aLocation, aMTV );
529 }
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=0.005 *PCB_IU_PER_MM) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:417
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
int GetWidth() const
Definition: shape_arc.h:112
SHAPE_LINE_CHAIN.

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

◆ collideShapes()

static bool collideShapes ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
static

Definition at line 756 of file shape_collisions.cpp.

758 {
759  int currentActual = std::numeric_limits<int>::max();
760  VECTOR2I currentLocation;
761  VECTOR2I currentMTV(0, 0);
762  bool colliding = false;
763 
764  auto canExit =
765  [&]()
766  {
767  if( !colliding )
768  return false;
769 
770  if( aActual && currentActual > 0 )
771  return false;
772 
773  if( aMTV )
774  return false;
775 
776  return true;
777  };
778 
779  auto collideCompoundSubshapes =
780  [&]( const SHAPE* elemA, const SHAPE* elemB, int clearance ) -> bool
781  {
782  int actual = 0;
783  VECTOR2I location;
784  VECTOR2I mtv;
785 
786  if( collideSingleShapes( elemA, elemB, clearance,
787  aActual || aLocation ? &actual : nullptr,
788  aLocation ? &location : nullptr,
789  aMTV ? &mtv : nullptr ) )
790  {
791  if( actual < currentActual )
792  {
793  currentActual = actual;
794  currentLocation = location;
795  }
796 
797  if( aMTV && mtv.SquaredEuclideanNorm() > currentMTV.SquaredEuclideanNorm() )
798  {
799  currentMTV = mtv;
800  }
801 
802  return true;
803  }
804 
805  return false;
806  };
807 
808  if( aA->Type() == SH_COMPOUND && aB->Type() == SH_COMPOUND )
809  {
810  const SHAPE_COMPOUND* cmpA = static_cast<const SHAPE_COMPOUND*>( aA );
811  const SHAPE_COMPOUND* cmpB = static_cast<const SHAPE_COMPOUND*>( aB );
812 
813  for( const SHAPE* elemA : cmpA->Shapes() )
814  {
815  for( const SHAPE* elemB : cmpB->Shapes() )
816  {
817  if( collideCompoundSubshapes( elemA, elemB, aClearance ) )
818  {
819  colliding = true;
820 
821  if( canExit() )
822  break;
823  }
824  }
825 
826  if( canExit() )
827  break;
828  }
829  }
830  else if( aA->Type() == SH_COMPOUND )
831  {
832  const SHAPE_COMPOUND* cmpA = static_cast<const SHAPE_COMPOUND*>( aA );
833 
834  for( const SHAPE* elemA : cmpA->Shapes() )
835  {
836  if( collideCompoundSubshapes( elemA, aB, aClearance ) )
837  {
838  colliding = true;
839 
840  if( canExit() )
841  break;
842  }
843  }
844  }
845  else if( aB->Type() == SH_COMPOUND )
846  {
847  const SHAPE_COMPOUND* cmpB = static_cast<const SHAPE_COMPOUND*>( aB );
848 
849  for( const SHAPE* elemB : cmpB->Shapes() )
850  {
851  if( collideCompoundSubshapes( aA, elemB, aClearance ) )
852  {
853  colliding = true;
854 
855  if( canExit() )
856  break;
857  }
858  }
859  }
860  else
861  {
862  return collideSingleShapes( aA, aB, aClearance, aActual, aLocation, aMTV );
863  }
864 
865  if( colliding )
866  {
867  if( aLocation )
868  *aLocation = currentLocation;
869 
870  if( aActual )
871  *aActual = currentActual;
872 
873  if( aMTV )
874  *aMTV = currentMTV;
875  }
876 
877  return colliding;
878 }
compound shape, consisting of multiple simple shapes
Definition: shape.h:49
Define a general 2D-vector/point.
Definition: vector2d.h:61
An abstract shape on 2D plane.
Definition: shape.h:116
const std::vector< SHAPE * > & Shapes() const
static bool collideSingleShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, int *aActual, VECTOR2I *aLocation, VECTOR2I *aMTV)
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94

References collideSingleShapes(), SH_COMPOUND, SHAPE_COMPOUND::Shapes(), VECTOR2< T >::SquaredEuclideanNorm(), and SHAPE_BASE::Type().

Referenced by SHAPE::Collide().

◆ collideSingleShapes()

static bool collideSingleShapes ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
int *  aActual,
VECTOR2I aLocation,
VECTOR2I aMTV 
)
static

Definition at line 556 of file shape_collisions.cpp.

558 {
559  switch( aA->Type() )
560  {
561  case SH_NULL:
562  return false;
563 
564  case SH_RECT:
565  switch( aB->Type() )
566  {
567  case SH_RECT:
568  return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aActual, aLocation, aMTV );
569 
570  case SH_CIRCLE:
571  return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aActual, aLocation, aMTV );
572 
573  case SH_LINE_CHAIN:
574  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aActual, aLocation, aMTV );
575 
576  case SH_SEGMENT:
577  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
578 
579  case SH_SIMPLE:
581  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN_BASE>( aA, aB, aClearance, aActual, aLocation, aMTV );
582 
583  case SH_ARC:
584  return CollCaseReversed<SHAPE_RECT, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
585 
586  case SH_NULL:
587  return false;
588 
589  default:
590  break;
591  }
592  break;
593 
594  case SH_CIRCLE:
595  switch( aB->Type() )
596  {
597  case SH_RECT:
598  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aActual, aLocation, aMTV );
599 
600  case SH_CIRCLE:
601  return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aActual, aLocation, aMTV );
602 
603  case SH_LINE_CHAIN:
604  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aActual, aLocation, aMTV );
605 
606  case SH_SEGMENT:
607  return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
608 
609  case SH_SIMPLE:
611  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN_BASE>( aA, aB, aClearance, aActual, aLocation, aMTV );
612 
613  case SH_ARC:
614  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
615 
616  case SH_NULL:
617  return false;
618 
619  default:
620  break;
621  }
622  break;
623 
624  case SH_LINE_CHAIN:
625  switch( aB->Type() )
626  {
627  case SH_RECT:
628  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aActual, aLocation, aMTV );
629 
630  case SH_CIRCLE:
631  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aActual, aLocation, aMTV );
632 
633  case SH_LINE_CHAIN:
634  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aActual, aLocation, aMTV );
635 
636  case SH_SEGMENT:
637  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
638 
639  case SH_SIMPLE:
641  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN_BASE>( aA, aB, aClearance, aActual, aLocation, aMTV );
642 
643  case SH_ARC:
644  return CollCaseReversed<SHAPE_LINE_CHAIN, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
645 
646  case SH_NULL:
647  return false;
648 
649  default:
650  break;
651  }
652  break;
653 
654  case SH_SEGMENT:
655  switch( aB->Type() )
656  {
657  case SH_RECT:
658  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aActual, aLocation, aMTV );
659 
660  case SH_CIRCLE:
661  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aActual, aLocation, aMTV );
662 
663  case SH_LINE_CHAIN:
664  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aActual, aLocation, aMTV );
665 
666  case SH_SEGMENT:
667  return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
668 
669  case SH_SIMPLE:
671  return CollCase<SHAPE_LINE_CHAIN_BASE, SHAPE_SEGMENT>( aB, aA, aClearance, aActual, aLocation, aMTV );
672 
673  case SH_ARC:
674  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
675 
676  case SH_NULL:
677  return false;
678 
679  default:
680  break;
681  }
682  break;
683 
684  case SH_SIMPLE:
686  switch( aB->Type() )
687  {
688  case SH_RECT:
689  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN_BASE>( aB, aA, aClearance, aActual, aLocation, aMTV );
690 
691  case SH_CIRCLE:
692  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN_BASE>( aB, aA, aClearance, aActual, aLocation, aMTV );
693 
694  case SH_LINE_CHAIN:
695  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN_BASE>( aB, aA, aClearance, aActual, aLocation, aMTV );
696 
697  case SH_SEGMENT:
698  return CollCase<SHAPE_LINE_CHAIN_BASE, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
699 
700  case SH_SIMPLE:
702  return CollCase<SHAPE_LINE_CHAIN_BASE, SHAPE_LINE_CHAIN_BASE>( aA, aB, aClearance, aActual, aLocation, aMTV );
703 
704  case SH_ARC:
705  return CollCaseReversed<SHAPE_LINE_CHAIN_BASE, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
706 
707  case SH_NULL:
708  return false;
709 
710  default:
711  break;
712  }
713  break;
714 
715  case SH_ARC:
716  switch( aB->Type() )
717  {
718  case SH_RECT:
719  return CollCase<SHAPE_ARC, SHAPE_RECT>( aA, aB, aClearance, aActual, aLocation, aMTV );
720 
721  case SH_CIRCLE:
722  return CollCase<SHAPE_ARC, SHAPE_CIRCLE>( aA, aB, aClearance, aActual, aLocation, aMTV );
723 
724  case SH_LINE_CHAIN:
725  return CollCase<SHAPE_ARC, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aActual, aLocation, aMTV );
726 
727  case SH_SEGMENT:
728  return CollCase<SHAPE_ARC, SHAPE_SEGMENT>( aA, aB, aClearance, aActual, aLocation, aMTV );
729 
730  case SH_SIMPLE:
732  return CollCase<SHAPE_ARC, SHAPE_LINE_CHAIN_BASE>( aA, aB, aClearance, aActual, aLocation, aMTV );
733 
734  case SH_ARC:
735  return CollCase<SHAPE_ARC, SHAPE_ARC>( aA, aB, aClearance, aActual, aLocation, aMTV );
736 
737  case SH_NULL:
738  return false;
739 
740  default:
741  break;
742  }
743  break;
744 
745  default:
746  break;
747  }
748 
749  wxFAIL_MSG( wxString::Format( "Unsupported collision: %s with %s",
750  SHAPE_TYPE_asString( aA->Type() ),
751  SHAPE_TYPE_asString( aB->Type() ) ) );
752 
753  return false;
754 }
static wxString SHAPE_TYPE_asString(SHAPE_TYPE a)
Definition: shape.h:55
circular arc
Definition: shape.h:50
circle
Definition: shape.h:46
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
a single triangle belonging to a POLY_SET triangulation
Definition: shape.h:52
empty shape (no shape...),
Definition: shape.h:51
line chain (polyline)
Definition: shape.h:45
axis-aligned rectangle
Definition: shape.h:43
simple polygon
Definition: shape.h:47
SHAPE_TYPE Type() const
Return the type of the shape.
Definition: shape.h:94
line segment
Definition: shape.h:44

References Format(), SH_ARC, SH_CIRCLE, SH_LINE_CHAIN, SH_NULL, SH_POLY_SET_TRIANGLE, SH_RECT, SH_SEGMENT, SH_SIMPLE, SHAPE_TYPE_asString(), and SHAPE_BASE::Type().

Referenced by collideShapes().

◆ pushoutForce()

static VECTOR2I pushoutForce ( const SHAPE_CIRCLE aA,
const SEG aB,
int  aClearance 
)
static

Definition at line 147 of file shape_collisions.cpp.

148 {
149  VECTOR2I f( 0, 0 );
150 
151  const VECTOR2I c = aA.GetCenter();
152  const VECTOR2I nearest = aB.NearestPoint( c );
153 
154  const int r = aA.GetRadius();
155 
156  int dist = ( nearest - c ).EuclideanNorm();
157  int min_dist = aClearance + r;
158 
159  if( dist < min_dist )
160  {
161  for( int corr = 0; corr < 5; corr++ )
162  {
163  f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
164 
165  if( aB.Distance( c + f ) >= min_dist )
166  break;
167  }
168  }
169 
170  return f;
171 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:148
int Distance(const SEG &aSeg) const
Compute minimum Euclidean distance to segment aSeg.
Definition: seg.h:239
int GetRadius() const
Definition: shape_circle.h:107
Define a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I GetCenter() const
Definition: shape_circle.h:112
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition: seg.h:437

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

Referenced by Collide().