Slight optimization in RTREE_QUAL::RectSphericalVolume.
This commit is contained in:
parent
d0547cbde7
commit
fb7bc263de
|
@ -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
|
||||
//
|
||||
|
||||
/*
|
||||
|
@ -1514,8 +1515,7 @@ ELEMTYPEREAL RTREE_QUAL::RectSphericalVolume( const Rect* a_rect ) const
|
|||
{
|
||||
ASSERT( a_rect );
|
||||
|
||||
ELEMTYPEREAL sumOfSquares = (ELEMTYPEREAL) 0;
|
||||
ELEMTYPEREAL radius;
|
||||
ELEMTYPEREAL sumOfSquares = (ELEMTYPEREAL) 0;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue