Base: add methods to get volume and get max/min points
This commit is contained in:
@@ -208,6 +208,10 @@ public:
|
||||
|
||||
/** Returns the center of the box. */
|
||||
inline Vector3<Precision> GetCenter () const;
|
||||
/** Returns the minimum point of the box. */
|
||||
inline Vector3<Precision> GetMinimum () const;
|
||||
/** Returns the maximum point of the box. */
|
||||
inline Vector3<Precision> GetMaximum () const;
|
||||
/** Compute the diagonal length of this bounding box.
|
||||
* @note It's up to the client programmer to make sure that this bounding box is valid.
|
||||
*/
|
||||
@@ -225,6 +229,8 @@ public:
|
||||
inline Precision LengthY () const;
|
||||
/** Calculates expansion in z-direction. */
|
||||
inline Precision LengthZ () const;
|
||||
/** Calculates the volume. If the box is invalid a negative value is returned */
|
||||
inline Precision Volume () const;
|
||||
/** Moves in x-direction. */
|
||||
inline void MoveX (Precision value);
|
||||
/** Moves in y-direction. */
|
||||
@@ -971,6 +977,18 @@ inline Vector3<Precision> BoundBox3<Precision>::GetCenter () const
|
||||
(MaxZ + MinZ) / 2);
|
||||
}
|
||||
|
||||
template <class Precision>
|
||||
inline Vector3<Precision> BoundBox3<Precision>::GetMinimum () const
|
||||
{
|
||||
return Vector3<Precision>(MinX, MinY, MinZ);
|
||||
}
|
||||
|
||||
template <class Precision>
|
||||
inline Vector3<Precision> BoundBox3<Precision>::GetMaximum () const
|
||||
{
|
||||
return Vector3<Precision>(MaxX, MaxY, MaxZ);
|
||||
}
|
||||
|
||||
template <class Precision>
|
||||
inline Precision BoundBox3<Precision>::CalcDiagonalLength () const
|
||||
{
|
||||
@@ -1018,6 +1036,15 @@ inline Precision BoundBox3<Precision>::LengthZ () const
|
||||
return MaxZ - MinZ;
|
||||
}
|
||||
|
||||
template <class Precision>
|
||||
inline Precision BoundBox3<Precision>::Volume () const
|
||||
{
|
||||
if (!IsValid()) {
|
||||
return -1.0;
|
||||
}
|
||||
return LengthX() * LengthY() * LengthZ();
|
||||
}
|
||||
|
||||
template <class Precision>
|
||||
inline void BoundBox3<Precision>::MoveX (Precision value)
|
||||
{
|
||||
|
||||
@@ -201,6 +201,24 @@ TEST(BoundBox, TestCenter)
|
||||
EXPECT_EQ(box.GetCenter(), Base::Vector3d(0.5, 0.5, 0.5));
|
||||
}
|
||||
|
||||
TEST(BoundBox, TestMinimum)
|
||||
{
|
||||
Base::BoundBox3d box;
|
||||
box.Add(Base::Vector3d(0, 0, 0));
|
||||
box.Add(Base::Vector3d(1, 1, 1));
|
||||
|
||||
EXPECT_EQ(box.GetMinimum(), Base::Vector3d(0, 0, 0));
|
||||
}
|
||||
|
||||
TEST(BoundBox, TestMaximum)
|
||||
{
|
||||
Base::BoundBox3d box;
|
||||
box.Add(Base::Vector3d(0, 0, 0));
|
||||
box.Add(Base::Vector3d(1, 1, 1));
|
||||
|
||||
EXPECT_EQ(box.GetMaximum(), Base::Vector3d(1, 1, 1));
|
||||
}
|
||||
|
||||
TEST(BoundBox, TestDiagonalLength)
|
||||
{
|
||||
Base::BoundBox3d box;
|
||||
@@ -211,6 +229,16 @@ TEST(BoundBox, TestDiagonalLength)
|
||||
EXPECT_LT(box.CalcDiagonalLength(), 1.8);
|
||||
}
|
||||
|
||||
TEST(BoundBox, TestVolume)
|
||||
{
|
||||
Base::BoundBox3d box;
|
||||
EXPECT_LT(box.Volume(), 0.0);
|
||||
box.Add(Base::Vector3d(0, 0, 0));
|
||||
EXPECT_EQ(box.Volume(), 0.0);
|
||||
box.Add(Base::Vector3d(1, 1, 1));
|
||||
EXPECT_GT(box.Volume(), 0.0);
|
||||
}
|
||||
|
||||
TEST(BoundBox, TestDiagonalEnlarge)
|
||||
{
|
||||
Base::BoundBox3d box;
|
||||
|
||||
Reference in New Issue
Block a user