From 4de4347baa27f60ae79ca52e13bc08f0f5d9edb9 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Tue, 14 Dec 2021 16:14:15 +0000 Subject: [PATCH] SHAPE_ARC::Collide( aSeg ) must check segment end points as candidates The edge case is when the segment is completely contained inside the arc (This partially reverts b4835c82085a074c0ee00247504055ee063da963 and adds the missing test cases) --- libs/kimath/src/geometry/shape_arc.cpp | 3 +++ qa/libs/kimath/geometry/test_shape_arc.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libs/kimath/src/geometry/shape_arc.cpp b/libs/kimath/src/geometry/shape_arc.cpp index 62608512e6..92b80adccd 100644 --- a/libs/kimath/src/geometry/shape_arc.cpp +++ b/libs/kimath/src/geometry/shape_arc.cpp @@ -238,12 +238,15 @@ bool SHAPE_ARC::Collide( const SEG& aSeg, int aClearance, int* aActual, VECTOR2I // 1. Intersetion of the segment with the full circle // 2. Closest point on the segment to the center of the circle // 3. Closest point on the segment to the end points of the arc + // 4. End points of the segment std::vector candidatePts = circle.Intersect( aSeg ); candidatePts.push_back( aSeg.NearestPoint( center ) ); candidatePts.push_back( aSeg.NearestPoint( m_start ) ); candidatePts.push_back( aSeg.NearestPoint( m_end ) ); + candidatePts.push_back( aSeg.A ); + candidatePts.push_back( aSeg.B ); for( const VECTOR2I& candidate : candidatePts ) { diff --git a/qa/libs/kimath/geometry/test_shape_arc.cpp b/qa/libs/kimath/geometry/test_shape_arc.cpp index 7d200dc35d..ac5fff4b4e 100644 --- a/qa/libs/kimath/geometry/test_shape_arc.cpp +++ b/qa/libs/kimath/geometry/test_shape_arc.cpp @@ -648,7 +648,11 @@ static const std::vector arc_seg_collide_cases = { { "270 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, -100 }, { 0, -50 } }, true, 0 }, { "45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, 71 }, { 35, 35 } }, true, 0 }, { "-45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, -71 }, { 35, -35 } }, false, -1 }, - { "edge case - large diameter arc", { { 172367922, 82282076 }, { 162530000, 92120000 }, -45.0 }, + { "seg inside arc start", { { 0, 0 }, { 71, -71 }, 90.0 }, + 10, { { 90, 0 }, { -35, 0 } }, true, 10 }, + { "seg inside arc end", { { 0, 0 }, { 71, -71 }, 90.0 }, + 10, { { -35, 0 }, { 90, 0 } }, true, 10 }, + { "large diameter arc", { { 172367922, 82282076 }, { 162530000, 92120000 }, -45.0 }, 433300, { { 162096732, 92331236 }, { 162096732, 78253268 } }, true, 433268 }, };