From 24ce69948bb20635fe74aa8962aabbe0fd8e9242 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Tue, 9 Jun 2020 17:48:37 -0700 Subject: [PATCH 1/2] Add AxisAlignedBox::Volume imp Signed-off-by: Ian Chen --- src/AxisAlignedBox.cc | 5 +++++ src/AxisAlignedBox_TEST.cc | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/AxisAlignedBox.cc b/src/AxisAlignedBox.cc index 1bf91cc2f..f917633bd 100644 --- a/src/AxisAlignedBox.cc +++ b/src/AxisAlignedBox.cc @@ -284,6 +284,11 @@ std::tuple AxisAlignedBox::Intersect( dir.Normalize(); return this->Intersect(Line3d(_origin + dir * _min, _origin + dir * _max)); } +///////////////////////////////////////////////// +double AxisAlignedBox::Volume() const +{ + return this->XLength() * this->YLength() * this->ZLength(); +} ///////////////////////////////////////////////// // Find the intersection of a line from v0 to v1 and an diff --git a/src/AxisAlignedBox_TEST.cc b/src/AxisAlignedBox_TEST.cc index 4ac638168..4e7edfa6f 100644 --- a/src/AxisAlignedBox_TEST.cc +++ b/src/AxisAlignedBox_TEST.cc @@ -252,6 +252,12 @@ TEST_F(ExampleAxisAlignedBox, Merge) Vector3d(2, 2, 3))); } +///////////////////////////////////////////////// +TEST_F(ExampleAxisAlignedBox, Volume) +{ + EXPECT_DOUBLE_EQ(1.0, box.Volume()); +} + ///////////////////////////////////////////////// TEST(AxisAlignedBoxTest, OperatorEqual) { @@ -577,3 +583,13 @@ TEST(AxisAlignedBoxTest, Intersect) Vector3d(-0.707107, 0, -0.707107), 0, 1000)), dist, 1e-5); EXPECT_EQ(pt, Vector3d(1, 0, 0.3)); } + +///////////////////////////////////////////////// +TEST(AxisAlignedBoxTest, Volume) +{ + AxisAlignedBox box; + EXPECT_DOUBLE_EQ(0.0, box.Volume()); + + AxisAlignedBox box2(math::Vector3d(-1, -2, -3), math::Vector3d(1, 2, 3)); + EXPECT_DOUBLE_EQ(48.0, box2.Volume()); +} From 52c19b867e8fc0023f566703c1495c5d98d9d96a Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Wed, 10 Jun 2020 11:36:08 -0700 Subject: [PATCH 2/2] changelog Signed-off-by: Ian Chen --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index feaa9b41d..3eedb8723 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,9 @@ ## Ignition Math 6.x.x +1. Implement AxisAlignedBox Volume function + * [Pull request 126](https://github.com/ignitionrobotics/ign-math/pull/126) + 1. Add operator + for AxisAlignedBox and Vector3. * [Pull request 122](https://github.com/ignitionrobotics/ign-math/pull/122)