From ec271c20db73cadbc946ddeb351f19cd5ba3aba7 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Thu, 20 Jun 2024 04:01:19 +0300 Subject: [PATCH] Slightly optimize SEG::NearestPoint. --- libs/kimath/src/geometry/seg.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/kimath/src/geometry/seg.cpp b/libs/kimath/src/geometry/seg.cpp index c3d932e18b..57cedbf886 100644 --- a/libs/kimath/src/geometry/seg.cpp +++ b/libs/kimath/src/geometry/seg.cpp @@ -268,8 +268,9 @@ bool SEG::Contains( const VECTOR2I& aP ) const const VECTOR2I SEG::NearestPoint( const VECTOR2I& aP ) const { - VECTOR2I d = B - A; - ecoord l_squared = d.Dot( d ); + // Inlined for performance reasons + VECTOR2L d( B.x - A.x, B.y - A.y ); + ecoord l_squared( d.x * d.x + d.y * d.y ); if( l_squared == 0 ) return A;