Fix edge cases in CIRCLE::Intersect that were causing KiROUND overflow
This commit is contained in:
parent
eeb9a5d910
commit
22df01183d
|
@ -208,6 +208,8 @@ VECTOR2I CIRCLE::NearestPoint( const VECTOR2I& aP ) const
|
|||
|
||||
std::vector<VECTOR2I> CIRCLE::Intersect( const CIRCLE& aCircle ) const
|
||||
{
|
||||
// From https://mathworld.wolfram.com/Circle-CircleIntersection.html
|
||||
//
|
||||
// Simplify the problem:
|
||||
// Let this circle be centered at (0,0), with radius r1
|
||||
// Let aCircle be centered at (d, 0), with radius r2
|
||||
|
@ -234,7 +236,7 @@ std::vector<VECTOR2I> CIRCLE::Intersect( const CIRCLE& aCircle ) const
|
|||
int64_t r1 = Radius;
|
||||
int64_t r2 = aCircle.Radius;
|
||||
|
||||
if( d > ( r1 + r2 ) || d == 0 )
|
||||
if( d > ( r1 + r2 ) || ( d < (std::abs( r1 - r2) ) ) )
|
||||
return retval; //circles do not intersect
|
||||
|
||||
// Equation (3)
|
||||
|
|
|
@ -286,6 +286,38 @@ static const std::vector<CIR_CIR_VECPT_CASE> intersect_circle_cases = {
|
|||
//no points
|
||||
},
|
||||
},
|
||||
{
|
||||
"KiROUND overflow 1",
|
||||
{ { 44798001, -94001999 }, 200001 },
|
||||
{ { 44797999, -94001999 }, 650001 },
|
||||
{
|
||||
//no points
|
||||
},
|
||||
},
|
||||
{
|
||||
"KiROUND overflow 2",
|
||||
{ { 50747999, -92402001 }, 650001 },
|
||||
{ { 50748001, -92402001 }, 200001 },
|
||||
{
|
||||
//no points
|
||||
},
|
||||
},
|
||||
{
|
||||
"KiROUND overflow 3",
|
||||
{ { 43947999, -92402001 }, 650001 },
|
||||
{ { 43948001, -92402001 }, 200001 },
|
||||
{
|
||||
//no points
|
||||
},
|
||||
},
|
||||
{
|
||||
"KiROUND overflow 4",
|
||||
{ { 46497999, -94001999 }, 200001 },
|
||||
{ { 46498001, -94001999 }, 650001 },
|
||||
{
|
||||
//no points
|
||||
},
|
||||
},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
Loading…
Reference in New Issue