Cleanup.
This commit is contained in:
parent
b4e4e1cf5e
commit
f08b7f098f
|
@ -2,6 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 CERN
|
* Copyright (C) 2013 CERN
|
||||||
|
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -22,8 +23,6 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <assert.h> // for assert
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits.h> // for INT_MAX
|
#include <limits.h> // for INT_MAX
|
||||||
|
|
||||||
|
@ -39,6 +38,7 @@
|
||||||
|
|
||||||
typedef VECTOR2I::extended_type ecoord;
|
typedef VECTOR2I::extended_type ecoord;
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
|
@ -72,9 +72,9 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aC
|
||||||
const VECTOR2I c = aB.GetCenter();
|
const VECTOR2I c = aB.GetCenter();
|
||||||
const VECTOR2I p0 = aA.GetPosition();
|
const VECTOR2I p0 = aA.GetPosition();
|
||||||
const VECTOR2I size = aA.GetSize();
|
const VECTOR2I size = aA.GetSize();
|
||||||
const int r = aB.GetRadius();
|
const int r = aB.GetRadius();
|
||||||
const int min_dist = aClearance + r;
|
const int min_dist = aClearance + r;
|
||||||
const ecoord min_dist_sq = SEG::Square( min_dist );
|
const ecoord min_dist_sq = SEG::Square( min_dist );
|
||||||
|
|
||||||
const VECTOR2I vts[] =
|
const VECTOR2I vts[] =
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,7 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aC
|
||||||
VECTOR2I( p0.x, p0.y )
|
VECTOR2I( p0.x, p0.y )
|
||||||
};
|
};
|
||||||
|
|
||||||
ecoord nearest_side_dist_sq = VECTOR2I::ECOORD_MAX;
|
ecoord nearest_side_dist_sq = VECTOR2I::ECOORD_MAX;
|
||||||
VECTOR2I nearest;
|
VECTOR2I nearest;
|
||||||
|
|
||||||
bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
|
bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
|
||||||
|
@ -260,7 +260,9 @@ static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_SEGMENT& aSeg, i
|
||||||
static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CHAIN_BASE& aB,
|
static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CHAIN_BASE& aB,
|
||||||
int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
// TODO: why doesn't this handle MTV?
|
wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
|
||||||
|
aA.Type(),
|
||||||
|
aB.Type() ) );
|
||||||
|
|
||||||
int closest_dist = INT_MAX;
|
int closest_dist = INT_MAX;
|
||||||
VECTOR2I nearest;
|
VECTOR2I nearest;
|
||||||
|
@ -315,7 +317,9 @@ static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CH
|
||||||
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN_BASE& aB, int aClearance,
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN_BASE& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
// TODO: why doesn't this handle MTV?
|
wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
|
||||||
|
aA.Type(),
|
||||||
|
aB.Type() ) );
|
||||||
|
|
||||||
int closest_dist = INT_MAX;
|
int closest_dist = INT_MAX;
|
||||||
VECTOR2I nearest;
|
VECTOR2I nearest;
|
||||||
|
@ -367,15 +371,17 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN_BASE& a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
if( aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2, aActual, aLocation ) )
|
wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
|
||||||
|
aA.Type(),
|
||||||
|
aB.Type() ) );
|
||||||
|
|
||||||
|
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
|
||||||
{
|
{
|
||||||
if( aActual )
|
if( aActual )
|
||||||
*aActual = std::max( 0, *aActual - aSeg.GetWidth() / 2 );
|
*aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
|
||||||
|
|
||||||
// TODO: why doesn't this handle MTV?
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -387,13 +393,15 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aSeg, int
|
||||||
static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
|
wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
|
||||||
|
aA.Type(),
|
||||||
|
aB.Type() ) );
|
||||||
|
|
||||||
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
|
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
|
||||||
{
|
{
|
||||||
if( aActual )
|
if( aActual )
|
||||||
*aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
|
*aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
|
||||||
|
|
||||||
// TODO: why doesn't this handle MTV?
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,13 +412,15 @@ static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, in
|
||||||
static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_SEGMENT& aB,
|
static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_SEGMENT& aB,
|
||||||
int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
|
wxASSERT_MSG( !aMTV, wxString::Format( "MTV not implemented for %s : %s collisions",
|
||||||
|
aA.Type(),
|
||||||
|
aB.Type() ) );
|
||||||
|
|
||||||
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
|
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2, aActual, aLocation ) )
|
||||||
{
|
{
|
||||||
if( aActual )
|
if( aActual )
|
||||||
*aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
|
*aActual = std::max( 0, *aActual - aB.GetWidth() / 2 );
|
||||||
|
|
||||||
// TODO: why doesn't this handle MTV?
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,17 +434,20 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_RECT& aB, int aCle
|
||||||
return Collide( aA.Outline(), aB.Outline(), aClearance, aActual, aLocation, aMTV );
|
return Collide( aA.Outline(), aB.Outline(), aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_RECT& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_RECT& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lc = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
|
||||||
|
|
||||||
return Collide( lc, aB.Outline(), aClearance, aActual, aLocation, aMTV );
|
return Collide( lc, aB.Outline(), aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lc = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
|
||||||
bool rv = Collide( aB, lc, aClearance, aActual, aLocation, aMTV );
|
bool rv = Collide( aB, lc, aClearance, aActual, aLocation, aMTV );
|
||||||
|
|
||||||
if( rv && aMTV )
|
if( rv && aMTV )
|
||||||
|
@ -443,36 +456,44 @@ static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_CIRCLE& aB, int aCl
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lc = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
|
||||||
|
|
||||||
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lc = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
|
||||||
|
|
||||||
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN_BASE& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_LINE_CHAIN_BASE& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lc = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lc = aA.ConvertToPolyline();
|
||||||
|
|
||||||
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
return Collide( lc, aB, aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_ARC& aB, int aClearance,
|
static inline bool Collide( const SHAPE_ARC& aA, const SHAPE_ARC& aB, int aClearance,
|
||||||
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
const auto lcA = aA.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lcA = aA.ConvertToPolyline();
|
||||||
const auto lcB = aB.ConvertToPolyline();
|
const SHAPE_LINE_CHAIN lcB = aB.ConvertToPolyline();
|
||||||
|
|
||||||
return Collide( lcA, lcB, aClearance, aActual, aLocation, aMTV );
|
return Collide( lcA, lcB, aClearance, aActual, aLocation, aMTV );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T_a, class T_b>
|
template<class T_a, class T_b>
|
||||||
inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual,
|
inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual,
|
||||||
VECTOR2I* aLocation, VECTOR2I* aMTV )
|
VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
|
@ -482,6 +503,7 @@ inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aAc
|
||||||
aClearance, aActual, aLocation, aMTV);
|
aClearance, aActual, aLocation, aMTV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T_a, class T_b>
|
template<class T_a, class T_b>
|
||||||
inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual,
|
inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual,
|
||||||
VECTOR2I* aLocation, VECTOR2I* aMTV )
|
VECTOR2I* aLocation, VECTOR2I* aMTV )
|
||||||
|
@ -820,6 +842,7 @@ static bool collideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, int
|
||||||
return colliding;
|
return colliding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SHAPE::Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const
|
bool SHAPE::Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const
|
||||||
{
|
{
|
||||||
return collideShapes( this, aShape, aClearance, nullptr, nullptr, aMTV );
|
return collideShapes( this, aShape, aClearance, nullptr, nullptr, aMTV );
|
||||||
|
|
Loading…
Reference in New Issue