Change implementation of Box2::FarthestPointTo to actually return the farthest point.

This commit is contained in:
Jonathan Haas 2022-09-19 13:12:44 +02:00 committed by Mark Roszko
parent 6b15231f4b
commit 9d45b5a197
1 changed files with 17 additions and 5 deletions

View File

@ -114,7 +114,7 @@ public:
} }
/** /**
* Ensure that the height ant width are positive. * Ensure that the height and width are positive.
*/ */
BOX2<Vec>& Normalize() BOX2<Vec>& Normalize()
{ {
@ -482,8 +482,8 @@ public:
Vec farpt = FarthestPointTo( aCenter ); Vec farpt = FarthestPointTo( aCenter );
// Farthest point must be further than the inside of the line // Farthest point must be further than the inside of the line
double fx = (double) farpt.x; double fx = (double) farpt.x - aCenter.x;
double fy = (double) farpt.y; double fy = (double) farpt.y - aCenter.y;
double r = (double) aRadius - (double) aWidth / 2; double r = (double) aRadius - (double) aWidth / 2;
@ -800,8 +800,20 @@ public:
me.Normalize(); // ensure size is >= 0 me.Normalize(); // ensure size is >= 0
coord_type fx = std::max( std::abs( aPoint.x - me.GetLeft() ), std::abs( aPoint.x - me.GetRight() ) ); coord_type fx;
coord_type fy = std::max( std::abs( aPoint.y - me.GetTop() ), std::abs( aPoint.y - me.GetBottom() ) ); coord_type fy;
Vec center = me.GetCenter();
if( aPoint.x < center.x )
fx = me.GetRight();
else
fx = me.GetLeft();
if( aPoint.y < center.y )
fy = me.GetBottom();
else
fy = me.GetTop();
return Vec( fx, fy ); return Vec( fx, fy );
} }