Slight optimization in RTREE_QUAL::RectSphericalVolume.

This commit is contained in:
Alex 2022-07-16 19:51:32 +03:00
parent d0547cbde7
commit fb7bc263de
1 changed files with 10 additions and 8 deletions

View File

@ -16,6 +16,7 @@
// * 2013 CERN (www.cern.ch)
// * 2020 KiCad Developers - Add std::iterator support for searching
// * 2020 KiCad Developers - Add container nearest neighbor based on Hjaltason & Samet
// * 2022 KiCad Developers - Slight optimizations in RectSphericalVolume
//
/*
@ -1515,7 +1516,6 @@ ELEMTYPEREAL RTREE_QUAL::RectSphericalVolume( const Rect* a_rect ) const
ASSERT( a_rect );
ELEMTYPEREAL sumOfSquares = (ELEMTYPEREAL) 0;
ELEMTYPEREAL radius;
for( int index = 0; index < NUMDIMS; ++index )
{
@ -1524,19 +1524,21 @@ ELEMTYPEREAL RTREE_QUAL::RectSphericalVolume( const Rect* a_rect ) const
sumOfSquares += halfExtent * halfExtent;
}
radius = (ELEMTYPEREAL) std::sqrt( sumOfSquares );
// Pow maybe slow, so test for common dims like 2,3 and just use x*x, x*x*x.
if( NUMDIMS == 3 )
if( NUMDIMS == 2 )
{
return radius * radius * radius * m_unitSphereVolume;
return sumOfSquares * m_unitSphereVolume;
}
else if( NUMDIMS == 2 )
else if( NUMDIMS == 3 )
{
return radius * radius * m_unitSphereVolume;
ELEMTYPEREAL radius = (ELEMTYPEREAL) std::sqrt( sumOfSquares );
return radius * radius * radius * m_unitSphereVolume;
}
else
{
ELEMTYPEREAL radius = (ELEMTYPEREAL) std::sqrt( sumOfSquares );
return (ELEMTYPEREAL) (std::pow( radius, NUMDIMS ) * m_unitSphereVolume);
}
}