-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add AxisAlignedBox conversion helpers #667
base: gz-math8
Are you sure you want to change the base?
Conversation
Adds helper functions to create AxisAlignedBox from shapes Origin shapes: Box, Sphere, Capsure, Cylinder Fixes gazebosim#666 Signed-off-by: anshium <[email protected]>
For the files AxisAlignedBoxHelpers.hh, AxisAlignedBoxHelpers.cc and AxisAlignedBoxHelpers.hh in detail/ Signed-off-by: anshium <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution, Do you mind to add the python bindings too ? If you don't have time to do it please open a issue indicating that Python binding are missing for this new feature. Otherwise you can include them in this PR or open a new one.
@@ -0,0 +1,74 @@ | |||
/* | |||
* Copyright (C) 2012 Open Source Robotics Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (C) 2012 Open Source Robotics Foundation | |
* Copyright (C) 2025 Open Source Robotics Foundation |
/// This class provides static methods for | ||
/// converting different types of 3D | ||
/// shapes, such as Box, Sphere, Capsule, | ||
/// and Cylinder, into AxisAlignedBox | ||
/// objects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This class provides static methods for | |
/// converting different types of 3D | |
/// shapes, such as Box, Sphere, Capsule, | |
/// and Cylinder, into AxisAlignedBox | |
/// objects. | |
/// This class provides static methods for converting different types of 3D | |
/// shapes, such as Box, Sphere, Capsule, and Cylinder, into AxisAlignedBox | |
/// objects. |
@@ -0,0 +1,122 @@ | |||
/* | |||
* Copyright (C) 2012 Open Source Robotics Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (C) 2012 Open Source Robotics Foundation | |
* Copyright (C) 2025 Open Source Robotics Foundation |
AxisAlignedBox AxisAlignedBoxHelpers<Precision>::ConvertToAxisAlignedBox( | ||
const Box<Precision> &_box) | ||
{ | ||
Vector3<Precision> size = _box.Size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include "gz/math/Vector3.hh"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"gz/math/Vector3.hh"
gets included when <gz/math/AxisAlignedBox.hh>
is included. Should we include it to be more explicit about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, please
src/AxisAlignedBoxHelpers_TEST.cc
Outdated
@@ -0,0 +1,96 @@ | |||
/* | |||
* Copyright (C) 2018 Open Source Robotics Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright (C) 2018 Open Source Robotics Foundation | |
* Copyright (C) 2025 Open Source Robotics Foundation |
style: improve comment formatting Signed-off-by: anshium <[email protected]>
Signed-off-by: anshium <[email protected]>
Made the said changes. Working on the python bindings now :) |
also add tests Signed-off-by: anshium <[email protected]>
Added the python bindings, along with tests. |
Adds helper functions to create AxisAlignedBox from shapes Origin shapes: Box, Sphere, Capsure, Cylinder
🎉 New feature
Closes #666
Summary
Implementation of static helper functions in
gz::math::AxisAlignedBoxHelpers
to convert shape objects (Box, Sphere, Capsule, Cylinder) into AxisAlignedBox objects.I have tried to write the functions in more or less the same format as other files. Since, the functions are template functions, I have kept their implementation in
gz/math/detail/AxisAlignedBoxHelpers.hh
and the declarations ingz/math/AxisAlignedBoxHelpers.hh
.I have also written comments in the same style as other files.
Also, I have added a few tests to check their correctness.
Test it
Testing can be done by creating a new shape:
math::Box<double> box(2.0, 4.0, 6.0);
Then, using the helper function:
math::AxisAlignedBox aabb = math::AxisAlignedBoxHelpers<double>::ConvertToAxisAlignedBox(box);
Then, can call functions like:
aabb.Min()
The output would be:
Vector3d(-1.0, -2.0, -3.0)
Checklist
codecheck
passed (See contributing)Doubts
I am not sure if we need an example / tutorial for these helper functions. Kindly let me know if we do, I will add them.
Also, kindly let me know if the python bindings have to be updated and where do I update the documentation.