Avoid some overflows in KiROUND

This commit is contained in:
Seth Hillbrand 2024-06-18 21:37:00 -07:00
parent 9aba808366
commit cde153c75f
2 changed files with 6 additions and 6 deletions

View File

@ -149,7 +149,7 @@ CIRCLE& CIRCLE::ConstructFromTanTanPt( const SEG& aLineA, const SEG& aLineB, con
VECTOR2I hTanLineB = aLineB.LineProject( hSolution.Center );
// To minimise errors, use the furthest away tangent point from aP
if( ( hTanLineA - aP ).EuclideanNorm() > ( hTanLineB - aP ).EuclideanNorm() )
if( ( hTanLineA - aP ).SquaredEuclideanNorm() > ( hTanLineB - aP ).SquaredEuclideanNorm() )
{
// Find the tangent at line A by homothetic inversion
SEG hT( hTanLineA, hSelected );
@ -187,7 +187,7 @@ CIRCLE& CIRCLE::ConstructFromTanTanPt( const SEG& aLineA, const SEG& aLineB, con
bool CIRCLE::Contains( const VECTOR2I& aP ) const
{
int distance = ( aP - Center ).EuclideanNorm();
int64_t distance = VECTOR2L( aP - Center ).EuclideanNorm();
return distance <= ( (int64_t) Radius + SHAPE::MIN_PRECISION_IU )
&& distance >= ( (int64_t) Radius - SHAPE::MIN_PRECISION_IU );
@ -244,7 +244,7 @@ std::vector<VECTOR2I> CIRCLE::Intersect( const CIRCLE& aCircle ) const
std::vector<VECTOR2I> retval;
VECTOR2I vecCtoC = aCircle.Center - Center;
int64_t d = vecCtoC.EuclideanNorm();
int64_t d = VECTOR2L( vecCtoC ).EuclideanNorm();
int64_t r1 = Radius;
int64_t r2 = aCircle.Radius;
@ -324,7 +324,7 @@ std::vector<VECTOR2I> CIRCLE::IntersectLine( const SEG& aLine ) const
//
VECTOR2I m = aLine.LineProject( Center ); // O projected perpendicularly to the line
int64_t omDist = ( m - Center ).EuclideanNorm();
int64_t omDist = VECTOR2L( m - Center ).EuclideanNorm();
if( omDist > ( (int64_t) Radius + SHAPE::MIN_PRECISION_IU ) )
{

View File

@ -244,7 +244,7 @@ SHAPE_ARC& SHAPE_ARC::ConstructFromStartEndCenter( const VECTOR2I& aStart, const
bool SHAPE_ARC::Collide( const SEG& aSeg, int aClearance, int* aActual, VECTOR2I* aLocation ) const
{
VECTOR2I center = GetCenter();
double radius = ( center - m_start ).EuclideanNorm();
double radius = VECTOR2D( center - m_start ).EuclideanNorm();
SHAPE_CIRCLE circle( center, radius );
ecoord clearance_sq = SEG::Square( aClearance );
@ -430,7 +430,7 @@ bool SHAPE_ARC::Collide( const VECTOR2I& aP, int aClearance, int* aActual,
return false;
VECTOR2L center = GetCenter();
double radius = ( center - m_start ).EuclideanNorm();
double radius = VECTOR2D( center - m_start ).EuclideanNorm();
CIRCLE fullCircle( center, radius );
VECTOR2D nearestPt = fullCircle.NearestPoint( VECTOR2D( aP ) );
int dist = KiROUND( nearestPt.Distance( aP ) );