From f9cfd3135143825436fdca4ff7027152bec9934f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 4 Oct 2020 10:46:18 +0100 Subject: [PATCH] 0 is always a collision (whether clearance is 0 or not). --- libs/kimath/src/geometry/shape_arc.cpp | 2 +- libs/kimath/src/geometry/shape_collisions.cpp | 11 +++++------ libs/kimath/src/geometry/shape_compound.cpp | 2 +- libs/kimath/src/geometry/shape_rect.cpp | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/kimath/src/geometry/shape_arc.cpp b/libs/kimath/src/geometry/shape_arc.cpp index 92bb62453a..9922d7a5dc 100644 --- a/libs/kimath/src/geometry/shape_arc.cpp +++ b/libs/kimath/src/geometry/shape_arc.cpp @@ -202,7 +202,7 @@ bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance, int* aActual, ecoord dist_sq = ( aP - GetCenter() ).SquaredEuclideanNorm(); ecoord dist_to_edge_sq = abs( dist_sq - r_sq ); - if( dist_to_edge_sq < min_dist_sq ) + if( dist_to_edge_sq == 0 || dist_to_edge_sq < min_dist_sq ) { if( aLocation ) *aLocation = ( aP + GetCenter() ) / 2; diff --git a/libs/kimath/src/geometry/shape_collisions.cpp b/libs/kimath/src/geometry/shape_collisions.cpp index 75107a749b..68e0dcf47b 100644 --- a/libs/kimath/src/geometry/shape_collisions.cpp +++ b/libs/kimath/src/geometry/shape_collisions.cpp @@ -49,7 +49,7 @@ static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_CIRCLE& aB, int const VECTOR2I delta = aB.GetCenter() - aA.GetCenter(); ecoord dist_sq = delta.SquaredEuclideanNorm(); - if( dist_sq < min_dist_sq ) + if( dist_sq == 0 || dist_sq < min_dist_sq ) { if( aActual ) *aActual = std::max( 0, (int) sqrt( dist_sq ) - aA.GetRadius() - aB.GetRadius() ); @@ -114,7 +114,7 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_CIRCLE& aB, int aC } } - if( inside || nearest_side_dist_sq < min_dist_sq ) + if( inside || nearest_side_dist_sq == 0 || nearest_side_dist_sq < min_dist_sq ) { if( aLocation ) *aLocation = nearest; @@ -192,7 +192,7 @@ static inline bool Collide( const SHAPE_CIRCLE& aA, const SHAPE_LINE_CHAIN_BASE& } } - if( closest_dist < aClearance ) + if( closest_dist == 0 || closest_dist < aClearance ) { if( aLocation ) *aLocation = nearest; @@ -241,7 +241,6 @@ static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CH int aClearance, int* aActual, VECTOR2I* aLocation, VECTOR2I* aMTV ) { // TODO: why doesn't this handle MTV? - // TODO: worse, why this doesn't handle closed shapes? int closest_dist = INT_MAX; VECTOR2I nearest; @@ -272,7 +271,7 @@ static inline bool Collide( const SHAPE_LINE_CHAIN_BASE& aA, const SHAPE_LINE_CH nearest = aA.GetPoint( 0 ); } - if( closest_dist < aClearance ) + if( closest_dist == 0 || closest_dist < aClearance ) { if( aLocation ) *aLocation = nearest; @@ -326,7 +325,7 @@ static inline bool Collide( const SHAPE_RECT& aA, const SHAPE_LINE_CHAIN_BASE& a } } - if( closest_dist < aClearance ) + if( closest_dist == 0 || closest_dist < aClearance ) { if( aLocation ) *aLocation = nearest; diff --git a/libs/kimath/src/geometry/shape_compound.cpp b/libs/kimath/src/geometry/shape_compound.cpp index dad7483d5e..57a626c1ad 100644 --- a/libs/kimath/src/geometry/shape_compound.cpp +++ b/libs/kimath/src/geometry/shape_compound.cpp @@ -139,7 +139,7 @@ bool SHAPE_COMPOUND::Collide( const SEG& aSeg, int aClearance, int* aActual, } } - if( closest_dist < aClearance ) + if( closest_dist == 0 || closest_dist < aClearance ) { if( aLocation ) *aLocation = nearest; diff --git a/libs/kimath/src/geometry/shape_rect.cpp b/libs/kimath/src/geometry/shape_rect.cpp index e4d07ccb8d..ce8cc52d9a 100644 --- a/libs/kimath/src/geometry/shape_rect.cpp +++ b/libs/kimath/src/geometry/shape_rect.cpp @@ -77,7 +77,7 @@ bool SHAPE_RECT::Collide( const SEG& aSeg, int aClearance, int* aActual, } } - if( closest_dist_sq < SEG::Square( aClearance ) ) + if( closest_dist_sq == 0 || closest_dist_sq < SEG::Square( aClearance ) ) { if( aLocation ) *aLocation = nearest;