Optimize TestSegmentHitFast

Check for co-linear points (common occurence) before using expensive
EuclideanNorm
This commit is contained in:
Seth Hillbrand 2024-04-29 17:46:27 -07:00
parent 9e83a7bcb3
commit 8b5564629a
1 changed files with 9 additions and 1 deletions

View File

@ -561,7 +561,15 @@ bool TestSegmentHitFast( const VECTOR2I& aRefPoint, const VECTOR2I& aStart, cons
if( aStart.y == aEnd.y && aRefPoint.x > xmin && aRefPoint.x < xmax )
return std::abs( delta.y ) <= aDist;
VECTOR2I::extended_type len = ( aEnd - aStart ).EuclideanNorm();
VECTOR2I::extended_type len;
if( aStart.x == aEnd.x )
len = std::abs( aStart.y - aEnd.y );
else if( aStart.y == aEnd.y )
len = std::abs( aStart.x - aEnd.x );
else
len = ( aEnd - aStart ).EuclideanNorm();
VECTOR2I::extended_type area = len * aDist;
return std::abs( ParallelogramArea( aStart, aRefPoint, aEnd ) ) <= area;