Skip to content
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

Open
wants to merge 5 commits into
base: gz-math8
Choose a base branch
from

Conversation

anshium
Copy link

@anshium anshium commented Mar 8, 2025

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 in gz/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

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)

Doubts

  1. 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.

  2. Also, kindly let me know if the python bindings have to be updated and where do I update the documentation.

anshium added 2 commits March 9, 2025 00:59
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]>
@github-actions github-actions bot added 🏛️ ionic Gazebo Ionic 🪵 jetty Gazebo Jetty labels Mar 8, 2025
Copy link
Contributor

@ahcorde ahcorde left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (C) 2012 Open Source Robotics Foundation
* Copyright (C) 2025 Open Source Robotics Foundation

Comment on lines 37 to 41
/// This class provides static methods for
/// converting different types of 3D
/// shapes, such as Box, Sphere, Capsule,
/// and Cylinder, into AxisAlignedBox
/// objects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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();
Copy link
Contributor

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"

Copy link
Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, please

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2018 Open Source Robotics Foundation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright (C) 2018 Open Source Robotics Foundation
* Copyright (C) 2025 Open Source Robotics Foundation

anshium added 2 commits March 10, 2025 21:57
style: improve comment formatting

Signed-off-by: anshium <[email protected]>
@anshium
Copy link
Author

anshium commented Mar 10, 2025

Made the said changes. Working on the python bindings now :)

@anshium
Copy link
Author

anshium commented Mar 10, 2025

Added the python bindings, along with tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic 🪵 jetty Gazebo Jetty
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

Add helper functions to create AxisAlignedBox objects from other shapes
2 participants