Skip to content

Commit

Permalink
MathLib: updated BoundBox
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 2, 2023
1 parent 87bf9a5 commit 448e81e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Common/interface/AdvancedMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,36 @@ struct BoundBox

return NewBB;
}

BoundBox Combine(const BoundBox& Box) const
{
return {
(std::min)(Min, Box.Min),
(std::max)(Max, Box.Max),
};
}

constexpr bool IsValid() const
{
return (Max.x >= Min.x &&
Max.y >= Min.y &&
Max.z >= Min.z);
}

explicit constexpr operator bool() const
{
return IsValid();
}

constexpr bool operator==(const BoundBox& rhs) const
{
return Min == rhs.Min && Max == rhs.Max;
}

constexpr bool operator!=(const BoundBox& rhs) const
{
return !(*this == rhs);
}
};

struct OrientedBoundingBox
Expand Down
9 changes: 9 additions & 0 deletions Tests/DiligentCoreTest/src/Common/MathLibTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,15 @@ TEST(Common_AdvancedMath, TransformBoundBox)
}
}

TEST(Common_AdvancedMath, CombineBoundBoxes)
{
const BoundBox BB1{float3{1, 2, 3}, float3{4, 5, 6}};
const BoundBox BB2{float3{-2, -3, -4}, float3{50, 60, 70}};
const BoundBox RefBB{float3{-2, -3, -4}, float3{50, 60, 70}};
EXPECT_EQ(BB1.Combine(BB2), RefBB);
EXPECT_EQ(BB2.Combine(BB1), RefBB);
}

TEST(Common_AdvancedMath, CheckBox2DBox2DOverlap)
{
// clang-format off
Expand Down

0 comments on commit 448e81e

Please sign in to comment.