Skip to content

Commit

Permalink
Foundation Classes - BVH surface area calculation for transformed boxes
Browse files Browse the repository at this point in the history
#322

BVH::SurfaceCalculator::Area() fails to calculate area of transformed box.
Use absolute values of intermediate calculations to
  compute surface area of a box, so they do not diminish each other.
  • Loading branch information
oan authored and dpasukhi committed Jan 31, 2025
1 parent 73fcf4b commit f1b10fe
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/BVH/BVH_Box.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,11 @@ struct SurfaceCalculator<T, 2>
{
static T Area(const typename BVH_Box<T, 2>::BVH_VecNt& theSize)
{
const T anArea = theSize.x() * theSize.y();
const T anArea = std::abs(theSize.x() * theSize.y());

if (anArea < std::numeric_limits<T>::epsilon())
{
return theSize.x() + theSize.y();
return std::abs(theSize.x()) + std::abs(theSize.y());
}

return anArea;
Expand All @@ -443,13 +443,13 @@ struct SurfaceCalculator<T, 3>
{
static T Area(const typename BVH_Box<T, 3>::BVH_VecNt& theSize)
{
const T anArea =
(theSize.x() * theSize.y() + theSize.x() * theSize.z() + theSize.z() * theSize.y())
* static_cast<T>(2.0);
const T anArea = (std::abs(theSize.x() * theSize.y()) + std::abs(theSize.x() * theSize.z())
+ std::abs(theSize.z() * theSize.y()))
* static_cast<T>(2.0);

if (anArea < std::numeric_limits<T>::epsilon())
{
return theSize.x() + theSize.y() + theSize.z();
return std::abs(theSize.x()) + std::abs(theSize.y()) + std::abs(theSize.z());
}

return anArea;
Expand All @@ -461,13 +461,13 @@ struct SurfaceCalculator<T, 4>
{
static T Area(const typename BVH_Box<T, 4>::BVH_VecNt& theSize)
{
const T anArea =
(theSize.x() * theSize.y() + theSize.x() * theSize.z() + theSize.z() * theSize.y())
* static_cast<T>(2.0);
const T anArea = (std::abs(theSize.x() * theSize.y()) + std::abs(theSize.x() * theSize.z())
+ std::abs(theSize.z() * theSize.y()))
* static_cast<T>(2.0);

if (anArea < std::numeric_limits<T>::epsilon())
{
return theSize.x() + theSize.y() + theSize.z();
return std::abs(theSize.x()) + std::abs(theSize.y()) + std::abs(theSize.z());
}

return anArea;
Expand Down

0 comments on commit f1b10fe

Please sign in to comment.