KiCad PCB EDA Suite
shape_collisions.cpp File Reference
#include <assert.h>
#include <cmath>
#include <limits.h>
#include <stdlib.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_simple.h>
#include <math/box2.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, 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

◆ ecoord

Definition at line 42 of file shape_collisions.cpp.

Function Documentation

◆ CollCase()

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

Definition at line 357 of file shape_collisions.cpp.

358 {
359  return Collide (*static_cast<const ShapeAType*>( aA ),
360  *static_cast<const ShapeBType*>( aB ),
361  aClearance, aNeedMTV, aMTV);
362 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References Collide().

◆ CollCaseReversed()

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

Definition at line 365 of file shape_collisions.cpp.

366 {
367  bool rv = Collide (*static_cast<const ShapeBType*>( aB ),
368  *static_cast<const ShapeAType*>( aA ),
369  aClearance, aNeedMTV, aMTV);
370  if(rv && aNeedMTV)
371  aMTV = -aMTV;
372  return rv;
373 }
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

References Collide().

◆ Collide() [1/21]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_CIRCLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 44 of file shape_collisions.cpp.

46 {
47  ecoord min_dist = aClearance + aA.GetRadius() + aB.GetRadius();
48  ecoord min_dist_sq = min_dist * min_dist;
49 
50  const VECTOR2I delta = aB.GetCenter() - aA.GetCenter();
51 
52  ecoord dist_sq = delta.SquaredEuclideanNorm();
53 
54  if( dist_sq >= min_dist_sq )
55  return false;
56 
57  if( aNeedMTV )
58  aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
59 
60  return true;
61 }
int GetRadius() const
Definition: shape_circle.h:83
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:306
const VECTOR2I GetCenter() const
Definition: shape_circle.h:88
VECTOR2I::extended_type ecoord
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392

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

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

◆ Collide() [2/21]

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

Definition at line 64 of file shape_collisions.cpp.

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

References 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.

◆ Collide() [3/21]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 156 of file shape_collisions.cpp.

158 {
159  bool found = false;
160 
161  for( int s = 0; s < aB.SegmentCount(); s++ )
162  {
163  if( aA.Collide( aB.CSegment( s ), aClearance ) )
164  {
165  found = true;
166  break;
167  }
168  }
169 
170  if( !aNeedMTV || !found )
171  return found;
172 
173  SHAPE_CIRCLE cmoved( aA );
174  VECTOR2I f_total( 0, 0 );
175 
176  for( int s = 0; s < aB.SegmentCount(); s++ )
177  {
178  VECTOR2I f = pushoutForce( cmoved, aB.CSegment( s ), aClearance );
179  cmoved.SetCenter( cmoved.GetCenter() + f );
180  f_total += f;
181  }
182 
183  aMTV = f_total;
184  return found;
185 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
int SegmentCount() const
Function SegmentCount()
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_circle.h:66
const SEG CSegment(int aIndex) const
Function CSegment()

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

◆ Collide() [4/21]

static bool Collide ( const SHAPE_CIRCLE aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 188 of file shape_collisions.cpp.

190 {
191  bool found;
192  const SHAPE_LINE_CHAIN& lc( aB.Vertices() );
193 
194  found = lc.Distance( aA.GetCenter() ) <= aClearance + aA.GetRadius();
195 
196  if( !aNeedMTV || !found )
197  return found;
198 
199  SHAPE_CIRCLE cmoved( aA );
200  VECTOR2I f_total( 0, 0 );
201 
202  for( int s = 0; s < lc.SegmentCount(); s++ )
203  {
204  VECTOR2I f = pushoutForce( cmoved, lc.CSegment( s ), aClearance );
205  cmoved.SetCenter( cmoved.GetCenter() + f );
206  f_total += f;
207  }
208 
209  aMTV = f_total;
210  return found;
211 }
int GetRadius() const
Definition: shape_circle.h:83
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
int Distance(const VECTOR2I &aP, bool aOutlineOnly=false) const
Function Distance()
const VECTOR2I GetCenter() const
Definition: shape_circle.h:88
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
static VECTOR2I pushoutForce(const SHAPE_CIRCLE &aA, const SEG &aB, int aClearance)
SHAPE_LINE_CHAIN.

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

◆ Collide() [5/21]

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

Definition at line 214 of file shape_collisions.cpp.

216 {
217  bool col = aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
218 
219  if( col && aNeedMTV )
220  {
221  aMTV = -pushoutForce( aA, aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
222  }
223  return col;
224 }
const SEG & GetSeg() const
Definition: shape_segment.h:72
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:66
int GetWidth() const
Definition: shape_segment.h:82

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

◆ Collide() [6/21]

static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 227 of file shape_collisions.cpp.

229 {
230  for( int i = 0; i < aB.SegmentCount(); i++ )
231  if( aA.Collide( aB.CSegment( i ), aClearance ) )
232  return true;
233 
234  return false;
235 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()

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

◆ Collide() [7/21]

static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 238 of file shape_collisions.cpp.

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

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

◆ Collide() [8/21]

static bool Collide ( const SHAPE_SIMPLE aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 245 of file shape_collisions.cpp.

247 {
248  return Collide( aA.Vertices(), aB.Vertices(), aClearance, aNeedMTV, aMTV );
249 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

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

◆ Collide() [9/21]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_LINE_CHAIN aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 252 of file shape_collisions.cpp.

254 {
255  for( int s = 0; s < aB.SegmentCount(); s++ )
256  {
257  if( aA.Collide( aB.CSegment( s ), aClearance ) )
258  return true;
259  }
260 
261  return false;
262 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
int SegmentCount() const
Function SegmentCount()
const SEG CSegment(int aIndex) const
Function CSegment()

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

◆ Collide() [10/21]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 265 of file shape_collisions.cpp.

267 {
268  return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
269 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

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

◆ Collide() [11/21]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_SEGMENT aSeg,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 272 of file shape_collisions.cpp.

274 {
275  return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
276 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
const SEG & GetSeg() const
Definition: shape_segment.h:72
int GetWidth() const
Definition: shape_segment.h:82

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

◆ Collide() [12/21]

static bool Collide ( const SHAPE_SEGMENT aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 279 of file shape_collisions.cpp.

281 {
282  return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
283 }
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
Definition: shape_segment.h:57
const SEG & GetSeg() const
Definition: shape_segment.h:72
int GetWidth() const
Definition: shape_segment.h:82

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

◆ Collide() [13/21]

static bool Collide ( const SHAPE_LINE_CHAIN aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 286 of file shape_collisions.cpp.

288 {
289  if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
290  return true;
291 
292  return false;
293 }
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide()
const SEG & GetSeg() const
Definition: shape_segment.h:72
int GetWidth() const
Definition: shape_segment.h:82

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

◆ Collide() [14/21]

static bool Collide ( const SHAPE_SIMPLE aA,
const SHAPE_SEGMENT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 296 of file shape_collisions.cpp.

298 {
299  return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
300 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

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

◆ Collide() [15/21]

static bool Collide ( const SHAPE_RECT aA,
const SHAPE_RECT aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 302 of file shape_collisions.cpp.

304 {
305  return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
306 }
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:146
static bool Collide(const SHAPE_CIRCLE &aA, const SHAPE_CIRCLE &aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)

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

◆ Collide() [16/21]

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

Definition at line 308 of file shape_collisions.cpp.

310 {
311  const auto lc = aA.ConvertToPolyline();
312  return Collide( lc, aB.Outline(), aClearance, aNeedMTV, aMTV );
313 }
const SHAPE_LINE_CHAIN Outline() const
Definition: shape_rect.h:146
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:274

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

◆ Collide() [17/21]

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

Definition at line 315 of file shape_collisions.cpp.

317 {
318  const auto lc = aA.ConvertToPolyline();
319  bool rv = Collide( aB, lc, aClearance, aNeedMTV, aMTV );
320 
321  if( rv && aNeedMTV )
322  aMTV = -aMTV;
323 
324  return rv;
325 }
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:274

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

◆ Collide() [18/21]

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

Definition at line 327 of file shape_collisions.cpp.

329 {
330  const auto lc = aA.ConvertToPolyline();
331  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
332 }
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:274

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

◆ Collide() [19/21]

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

Definition at line 334 of file shape_collisions.cpp.

336 {
337  const auto lc = aA.ConvertToPolyline();
338  return Collide( lc, aB, aClearance, aNeedMTV, aMTV );
339 }
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:274

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

◆ Collide() [20/21]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_SIMPLE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 341 of file shape_collisions.cpp.

343 {
344  const auto lc = aA.ConvertToPolyline();
345  return Collide( lc, aB.Vertices(), aClearance, aNeedMTV, aMTV );
346 }
const SHAPE_LINE_CHAIN & Vertices() const
Function Vertices()
Definition: shape_simple.h:125
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:274

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

◆ Collide() [21/21]

static bool Collide ( const SHAPE_ARC aA,
const SHAPE_ARC aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)
inlinestatic

Definition at line 348 of file shape_collisions.cpp.

350 {
351  const auto lcA = aA.ConvertToPolyline();
352  const auto lcB = aB.ConvertToPolyline();
353  return Collide( lcA, lcB, aClearance, aNeedMTV, aMTV );
354 }
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:274

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

◆ CollideShapes()

bool CollideShapes ( const SHAPE aA,
const SHAPE aB,
int  aClearance,
bool  aNeedMTV,
VECTOR2I aMTV 
)

Definition at line 376 of file shape_collisions.cpp.

377 {
378  switch( aA->Type() )
379  {
380  case SH_RECT:
381  switch( aB->Type() )
382  {
383  case SH_RECT:
384  return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
385 
386  case SH_CIRCLE:
387  return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
388 
389  case SH_LINE_CHAIN:
390  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
391 
392  case SH_SEGMENT:
393  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
394 
395  case SH_SIMPLE:
396  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
397 
398  case SH_ARC:
399  return CollCaseReversed<SHAPE_RECT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
400 
401  default:
402  break;
403  }
404  break;
405 
406  case SH_CIRCLE:
407  switch( aB->Type() )
408  {
409  case SH_RECT:
410  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
411 
412  case SH_CIRCLE:
413  return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
414 
415  case SH_LINE_CHAIN:
416  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
417 
418  case SH_SEGMENT:
419  return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
420 
421  case SH_SIMPLE:
422  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
423 
424  case SH_ARC:
425  return CollCaseReversed<SHAPE_CIRCLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
426 
427  default:
428  break;
429  }
430  break;
431 
432  case SH_LINE_CHAIN:
433  switch( aB->Type() )
434  {
435  case SH_RECT:
436  return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
437 
438  case SH_CIRCLE:
439  return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
440 
441  case SH_LINE_CHAIN:
442  return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
443 
444  case SH_SEGMENT:
445  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
446 
447  case SH_SIMPLE:
448  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
449 
450  case SH_ARC:
451  return CollCaseReversed<SHAPE_LINE_CHAIN, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
452 
453  default:
454  break;
455  }
456  break;
457 
458  case SH_SEGMENT:
459  switch( aB->Type() )
460  {
461  case SH_RECT:
462  return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
463 
464  case SH_CIRCLE:
465  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
466 
467  case SH_LINE_CHAIN:
468  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
469 
470  case SH_SEGMENT:
471  return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
472 
473  case SH_SIMPLE:
474  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
475 
476  case SH_ARC:
477  return CollCaseReversed<SHAPE_SEGMENT, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
478 
479  default:
480  break;
481  }
482  break;
483 
484  case SH_SIMPLE:
485  switch( aB->Type() )
486  {
487  case SH_RECT:
488  return CollCase<SHAPE_RECT, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
489 
490  case SH_CIRCLE:
491  return CollCase<SHAPE_CIRCLE, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
492 
493  case SH_LINE_CHAIN:
494  return CollCase<SHAPE_LINE_CHAIN, SHAPE_SIMPLE>( aB, aA, aClearance, aNeedMTV, aMTV );
495 
496  case SH_SEGMENT:
497  return CollCase<SHAPE_SIMPLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
498 
499  case SH_SIMPLE:
500  return CollCase<SHAPE_SIMPLE, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
501 
502  case SH_ARC:
503  return CollCaseReversed<SHAPE_SIMPLE, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
504 
505  default:
506  break;
507  }
508  break;
509 
510  case SH_ARC:
511  switch( aB->Type() )
512  {
513  case SH_RECT:
514  return CollCase<SHAPE_ARC, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
515 
516  case SH_CIRCLE:
517  return CollCase<SHAPE_ARC, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
518 
519  case SH_LINE_CHAIN:
520  return CollCase<SHAPE_ARC, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
521 
522  case SH_SEGMENT:
523  return CollCase<SHAPE_ARC, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
524 
525  case SH_SIMPLE:
526  return CollCase<SHAPE_ARC, SHAPE_SIMPLE>( aA, aB, aClearance, aNeedMTV, aMTV );
527 
528  case SH_ARC:
529  return CollCase<SHAPE_ARC, SHAPE_ARC>( aA, aB, aClearance, aNeedMTV, aMTV );
530 
531  default:
532  break;
533  }
534  break;
535 
536  default:
537  break;
538  }
539 
540  bool unsupported_collision = true;
541  (void) unsupported_collision; // make gcc quiet
542 
543  assert( unsupported_collision == false );
544 
545  return false;
546 }
SHAPE_TYPE Type() const
Function Type()
Definition: shape.h:85
compound shape, consisting of multiple simple shapes
Definition: shape.h:52
line chain (polyline)
Definition: shape.h:48
line segment
Definition: shape.h:47
Definition: shape.h:45
circle
Definition: shape.h:49
axis-aligned rectangle
Definition: shape.h:46

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

◆ pushoutForce()

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

Definition at line 129 of file shape_collisions.cpp.

130 {
131  VECTOR2I f( 0, 0 );
132 
133  const VECTOR2I c = aA.GetCenter();
134  const VECTOR2I nearest = aB.NearestPoint( c );
135 
136  const int r = aA.GetRadius();
137 
138  int dist = ( nearest - c ).EuclideanNorm();
139  int min_dist = aClearance + r;
140 
141  if( dist < min_dist )
142  {
143  for( int corr = 0; corr < 5; corr++ )
144  {
145  f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
146 
147  if( aB.Distance( c + f ) >= min_dist )
148  break;
149  }
150  }
151 
152  return f;
153 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:128
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:202
static const int dist[10][10]
Definition: ar_matrix.cpp:326
int GetRadius() const
Definition: shape_circle.h:83
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
const VECTOR2I GetCenter() const
Definition: shape_circle.h:88
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Function NearestPoint()
Definition: seg.h:392

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

Referenced by Collide().