2013-09-10 11:43:09 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
2014-05-14 09:45:01 +00:00
|
|
|
#include <math.h>
|
2013-09-10 11:43:09 +00:00
|
|
|
|
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
#include <geometry/shape_circle.h>
|
|
|
|
#include <geometry/shape_rect.h>
|
2014-05-14 09:45:01 +00:00
|
|
|
#include <geometry/shape_segment.h>
|
2015-07-02 14:09:43 +00:00
|
|
|
#include <geometry/shape_convex.h>
|
2013-09-10 11:43:09 +00:00
|
|
|
|
2013-09-23 15:02:25 +00:00
|
|
|
typedef VECTOR2I::extended_type ecoord;
|
2013-09-10 11:43:09 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
ecoord min_dist = aClearance + aA.GetRadius() + aB.GetRadius();
|
|
|
|
ecoord min_dist_sq = min_dist * min_dist;
|
2013-09-10 11:43:09 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
const VECTOR2I delta = aB.GetCenter() - aA.GetCenter();
|
2013-09-10 11:43:09 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
ecoord dist_sq = delta.SquaredEuclideanNorm();
|
2013-09-10 11:43:09 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
if( dist_sq >= min_dist_sq )
|
2013-10-14 11:43:57 +00:00
|
|
|
return false;
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
if( aNeedMTV )
|
2014-05-14 09:45:01 +00:00
|
|
|
aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
return true;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
const VECTOR2I c = aB.GetCenter();
|
|
|
|
const VECTOR2I p0 = aA.GetPosition();
|
|
|
|
const VECTOR2I size = aA.GetSize();
|
2014-05-14 09:45:01 +00:00
|
|
|
const int r = aB.GetRadius();
|
|
|
|
const int min_dist = aClearance + r;
|
2014-09-09 16:46:12 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
const VECTOR2I vts[] =
|
|
|
|
{
|
|
|
|
VECTOR2I( p0.x, p0.y ),
|
|
|
|
VECTOR2I( p0.x, p0.y + size.y ),
|
|
|
|
VECTOR2I( p0.x + size.x, p0.y + size.y ),
|
|
|
|
VECTOR2I( p0.x + size.x, p0.y ),
|
|
|
|
VECTOR2I( p0.x, p0.y )
|
|
|
|
};
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
int nearest_seg_dist = INT_MAX;
|
2013-10-14 11:43:57 +00:00
|
|
|
VECTOR2I nearest;
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
bool inside = c.x >= p0.x && c.x <= ( p0.x + size.x )
|
|
|
|
&& c.y >= p0.y && c.y <= ( p0.y + size.y );
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
|
|
|
|
if( !aNeedMTV && inside )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2014-05-14 09:45:01 +00:00
|
|
|
const SEG seg( vts[i], vts[i + 1] );
|
|
|
|
|
|
|
|
VECTOR2I pn = seg.NearestPoint( c );
|
|
|
|
|
|
|
|
int d = ( pn - c ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( ( d < min_dist ) && !aNeedMTV )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( d < nearest_seg_dist )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2014-05-14 09:45:01 +00:00
|
|
|
nearest = pn;
|
|
|
|
nearest_seg_dist = d;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
if( nearest_seg_dist >= min_dist && !inside )
|
2013-10-14 11:43:57 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
VECTOR2I delta = c - nearest;
|
|
|
|
|
|
|
|
if( !aNeedMTV )
|
|
|
|
return true;
|
|
|
|
|
2014-09-09 16:46:12 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
if( inside )
|
2014-05-14 09:45:01 +00:00
|
|
|
aMTV = -delta.Resize( abs( min_dist + 1 + nearest_seg_dist ) + 1 );
|
2013-10-14 11:43:57 +00:00
|
|
|
else
|
2014-05-14 09:45:01 +00:00
|
|
|
aMTV = delta.Resize( abs( min_dist + 1 - nearest_seg_dist ) + 1 );
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
return true;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 14:23:43 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static VECTOR2I pushoutForce( const SHAPE_CIRCLE& aA, const SEG& aB, int aClearance )
|
|
|
|
{
|
2016-03-01 13:26:08 +00:00
|
|
|
VECTOR2I f( 0, 0 );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2016-03-01 13:26:08 +00:00
|
|
|
const VECTOR2I c = aA.GetCenter();
|
|
|
|
const VECTOR2I nearest = aB.NearestPoint( c );
|
|
|
|
|
|
|
|
const int r = aA.GetRadius();
|
|
|
|
|
|
|
|
int dist = ( nearest - c ).EuclideanNorm();
|
|
|
|
int min_dist = aClearance + r;
|
2014-05-14 09:45:01 +00:00
|
|
|
|
|
|
|
if( dist < min_dist )
|
2016-03-01 13:26:08 +00:00
|
|
|
{
|
|
|
|
for( int corr = 0; corr < 5; corr++ )
|
|
|
|
{
|
|
|
|
f = ( aA.GetCenter() - nearest ).Resize( min_dist - dist + corr );
|
|
|
|
|
|
|
|
if( aB.Distance( c + f ) >= min_dist )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-14 09:45:01 +00:00
|
|
|
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2014-05-14 09:45:01 +00:00
|
|
|
bool found = false;
|
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
for( int s = 0; s < aB.SegmentCount(); s++ )
|
|
|
|
{
|
2013-10-14 14:13:35 +00:00
|
|
|
if( aA.Collide( aB.CSegment( s ), aClearance ) )
|
2014-05-14 09:45:01 +00:00
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
if( !aNeedMTV || !found )
|
|
|
|
return found;
|
2014-09-09 16:46:12 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
SHAPE_CIRCLE cmoved( aA );
|
|
|
|
VECTOR2I f_total( 0, 0 );
|
|
|
|
|
|
|
|
for( int s = 0; s < aB.SegmentCount(); s++ )
|
|
|
|
{
|
|
|
|
VECTOR2I f = pushoutForce( cmoved, aB.CSegment( s ), aClearance );
|
|
|
|
cmoved.SetCenter( cmoved.GetCenter() + f );
|
|
|
|
f_total += f;
|
|
|
|
}
|
2014-09-09 16:46:12 +00:00
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
aMTV = f_total;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CONVEX& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
const SHAPE_LINE_CHAIN& lc( aB.Vertices() );
|
|
|
|
|
|
|
|
found = lc.Distance( aA.GetCenter() ) <= aClearance + aA.GetRadius();
|
|
|
|
|
|
|
|
if( !aNeedMTV || !found )
|
|
|
|
return found;
|
|
|
|
|
|
|
|
SHAPE_CIRCLE cmoved( aA );
|
|
|
|
VECTOR2I f_total( 0, 0 );
|
|
|
|
|
|
|
|
for( int s = 0; s < lc.SegmentCount(); s++ )
|
|
|
|
{
|
|
|
|
VECTOR2I f = pushoutForce( cmoved, lc.CSegment( s ), aClearance );
|
|
|
|
cmoved.SetCenter( cmoved.GetCenter() + f );
|
|
|
|
f_total += f;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMTV = f_total;
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
2015-01-16 08:10:23 +00:00
|
|
|
bool col = aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
|
2014-05-14 09:45:01 +00:00
|
|
|
|
|
|
|
if( col && aNeedMTV )
|
|
|
|
{
|
2014-11-14 18:17:52 +00:00
|
|
|
aMTV = -pushoutForce( aA, aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2);
|
2014-05-14 09:45:01 +00:00
|
|
|
}
|
|
|
|
return col;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 14:23:43 +00:00
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
for( int i = 0; i < aB.SegmentCount(); i++ )
|
2013-10-14 14:13:35 +00:00
|
|
|
if( aA.Collide( aB.CSegment( i ), aClearance ) )
|
2013-10-14 11:43:57 +00:00
|
|
|
return true;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
return false;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_CONVEX& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline bool Collide( const SHAPE_CONVEX& aA, const SHAPE_CONVEX& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
return Collide( aA.Vertices(), aB.Vertices(), aClearance, aNeedMTV, aMTV );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
for( int s = 0; s < aB.SegmentCount(); s++ )
|
|
|
|
{
|
|
|
|
SEG seg = aB.CSegment( s );
|
2013-10-14 14:13:35 +00:00
|
|
|
|
|
|
|
if( aA.Collide( seg, aClearance ) )
|
|
|
|
return true;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CONVEX& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
return Collide( aA, aB.Vertices(), aClearance, aNeedMTV, aMTV );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_SEGMENT& aSeg, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2015-01-16 08:10:23 +00:00
|
|
|
return aA.Collide( aSeg.GetSeg(), aClearance + aSeg.GetWidth() / 2 );
|
2014-05-14 09:45:01 +00:00
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static inline bool Collide( const SHAPE_SEGMENT& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
2015-01-16 08:10:23 +00:00
|
|
|
return aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 );
|
2014-05-14 09:45:01 +00:00
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
|
2014-05-14 09:45:01 +00:00
|
|
|
static inline bool Collide( const SHAPE_LINE_CHAIN& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
2015-01-16 08:10:23 +00:00
|
|
|
if( aA.Collide( aB.GetSeg(), aClearance + aB.GetWidth() / 2 ) )
|
|
|
|
return true;
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
return false;
|
2014-05-14 09:45:01 +00:00
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
static inline bool Collide( const SHAPE_CONVEX& aA, const SHAPE_SEGMENT& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
return Collide( aA.Vertices(), aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
}
|
|
|
|
|
2015-08-19 16:07:16 +00:00
|
|
|
static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_RECT& aB, int aClearance,
|
|
|
|
bool aNeedMTV, VECTOR2I& aMTV )
|
|
|
|
{
|
|
|
|
return Collide( aA.Outline(), aB.Outline(), aClearance, aNeedMTV, aMTV );
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
template<class ShapeAType, class ShapeBType>
|
2014-11-14 18:17:52 +00:00
|
|
|
inline bool CollCase( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
|
2014-05-14 09:45:01 +00:00
|
|
|
{
|
2015-01-16 08:10:23 +00:00
|
|
|
return Collide (*static_cast<const ShapeAType*>( aA ),
|
|
|
|
*static_cast<const ShapeBType*>( aB ),
|
|
|
|
aClearance, aNeedMTV, aMTV);
|
2014-05-14 09:45:01 +00:00
|
|
|
}
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
template<class ShapeAType, class ShapeBType>
|
2014-11-14 18:17:52 +00:00
|
|
|
inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
|
2014-05-14 09:45:01 +00:00
|
|
|
{
|
2014-11-14 18:17:52 +00:00
|
|
|
bool rv = Collide (*static_cast<const ShapeBType*>( aB ),
|
|
|
|
*static_cast<const ShapeAType*>( aA ),
|
|
|
|
aClearance, aNeedMTV, aMTV);
|
2015-01-16 08:10:23 +00:00
|
|
|
if(rv && aNeedMTV)
|
2014-11-14 18:17:52 +00:00
|
|
|
aMTV = -aMTV;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CollideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, bool aNeedMTV, VECTOR2I& aMTV )
|
2015-01-16 08:10:23 +00:00
|
|
|
{
|
|
|
|
switch( aA->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
|
|
|
switch( aB->Type() )
|
|
|
|
{
|
2015-08-19 16:07:16 +00:00
|
|
|
case SH_RECT:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2015-07-07 17:49:03 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_CIRCLE:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_SEGMENT:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
case SH_CONVEX:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 16:37:03 +00:00
|
|
|
break;
|
2015-01-16 08:10:23 +00:00
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
switch( aB->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
2014-11-14 18:17:52 +00:00
|
|
|
return CollCaseReversed<SHAPE_CIRCLE, SHAPE_RECT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_CIRCLE:
|
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_SEGMENT:
|
2014-11-14 18:17:52 +00:00
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2015-01-16 08:10:23 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
case SH_CONVEX:
|
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
2014-11-14 18:17:52 +00:00
|
|
|
default:
|
2015-01-16 08:10:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-07 16:37:03 +00:00
|
|
|
break;
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
switch( aB->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_CIRCLE:
|
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_LINE_CHAIN>( aB, aA, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
return CollCase<SHAPE_LINE_CHAIN, SHAPE_LINE_CHAIN>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_SEGMENT:
|
|
|
|
return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
case SH_CONVEX:
|
|
|
|
return CollCase<SHAPE_LINE_CHAIN, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 16:37:03 +00:00
|
|
|
break;
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_SEGMENT:
|
|
|
|
switch( aB->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_CIRCLE:
|
2014-11-14 18:17:52 +00:00
|
|
|
return CollCaseReversed<SHAPE_SEGMENT, SHAPE_CIRCLE>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
return CollCase<SHAPE_LINE_CHAIN, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
case SH_SEGMENT:
|
|
|
|
return CollCase<SHAPE_SEGMENT, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-07-02 14:09:43 +00:00
|
|
|
case SH_CONVEX:
|
|
|
|
return CollCase<SHAPE_CONVEX, SHAPE_SEGMENT>( aB, aA, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 16:37:03 +00:00
|
|
|
break;
|
2015-07-02 14:09:43 +00:00
|
|
|
|
|
|
|
case SH_CONVEX:
|
|
|
|
switch( aB->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
|
|
|
return CollCase<SHAPE_RECT, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
return CollCase<SHAPE_CIRCLE, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
return CollCase<SHAPE_LINE_CHAIN, SHAPE_CONVEX>( aB, aA, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_SEGMENT:
|
|
|
|
return CollCase<SHAPE_CONVEX, SHAPE_SEGMENT>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
|
|
|
case SH_CONVEX:
|
|
|
|
return CollCase<SHAPE_CONVEX, SHAPE_CONVEX>( aA, aB, aClearance, aNeedMTV, aMTV );
|
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 16:37:03 +00:00
|
|
|
break;
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
bool unsupported_collision = true;
|
2014-09-09 16:46:12 +00:00
|
|
|
(void) unsupported_collision; // make gcc quiet
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
assert( unsupported_collision == false );
|
2014-05-14 09:45:01 +00:00
|
|
|
|
2015-01-16 08:10:23 +00:00
|
|
|
return false;
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-27 14:23:43 +00:00
|
|
|
bool SHAPE::Collide( const SHAPE* aShape, int aClerance, VECTOR2I& aMTV ) const
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 14:13:35 +00:00
|
|
|
return CollideShapes( this, aShape, aClerance, true, aMTV );
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 14:23:43 +00:00
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
bool SHAPE::Collide( const SHAPE* aShape, int aClerance ) const
|
2013-09-10 11:43:09 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
VECTOR2I dummy;
|
2013-10-14 14:13:35 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
return CollideShapes( this, aShape, aClerance, false, dummy );
|
2013-09-10 11:43:09 +00:00
|
|
|
}
|
2015-06-12 15:11:50 +00:00
|
|
|
|
|
|
|
bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance ) const
|
|
|
|
{
|
|
|
|
//VECTOR2I pmin = VECTOR2I( std::min( aSeg.a.x, aSeg.b.x ), std::min( aSeg.a.y, aSeg.b.y ) );
|
|
|
|
//VECTOR2I pmax = VECTOR2I( std::max( aSeg.a.x, aSeg.b.x ), std::max( aSeg.a.y, aSeg.b.y ));
|
|
|
|
//BOX2I r( pmin, VECTOR2I( pmax.x - pmin.x, pmax.y - pmin.y ) );
|
|
|
|
|
|
|
|
//if( BBox( 0 ).SquaredDistance( r ) > aClearance * aClearance )
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
if( BBox( 0 ).Contains( aSeg.A ) || BBox( 0 ).Contains( aSeg.B ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
VECTOR2I vts[] = { VECTOR2I( m_p0.x, m_p0.y ),
|
|
|
|
VECTOR2I( m_p0.x, m_p0.y + m_h ),
|
|
|
|
VECTOR2I( m_p0.x + m_w, m_p0.y + m_h ),
|
|
|
|
VECTOR2I( m_p0.x + m_w, m_p0.y ),
|
|
|
|
VECTOR2I( m_p0.x, m_p0.y ) };
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
SEG s( vts[i], vts[i + 1], i );
|
|
|
|
|
|
|
|
if( s.Distance( aSeg ) < aClearance )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-06-26 23:29:01 +00:00
|
|
|
}
|