-
Notifications
You must be signed in to change notification settings - Fork 67
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
Added AxisAlignedBox pybind11 interface #338
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43d624a
Added AxisAlignedBox pybind11 interface
ahcorde 31c3ca6
Merge branch 'ign-math6' into ahcorde/pybind11/axisAlignedbox
ahcorde 4bd6a01
Merge branch 'ign-math6' into ahcorde/pybind11/axisAlignedbox
ahcorde b757293
Merge branch 'ign-math6' into ahcorde/pybind11/axisAlignedbox
ahcorde 37db423
Increase coverage
ahcorde 677b8fc
Merge branch 'ahcorde/pybind11/axisAlignedbox' of https://github.com/…
ahcorde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#include <string> | ||
|
||
#include <pybind11/operators.h> | ||
|
||
#include "AxisAlignedBox.hh" | ||
|
||
#include <ignition/math/AxisAlignedBox.hh> | ||
#include <ignition/math/Vector3.hh> | ||
|
||
using namespace pybind11::literals; | ||
|
||
namespace ignition | ||
{ | ||
namespace math | ||
{ | ||
namespace python | ||
{ | ||
void defineMathAxisAlignedBox(py::module &m, const std::string &typestr) | ||
{ | ||
using Class = ignition::math::AxisAlignedBox; | ||
auto toString = [](const Class &si) { | ||
std::stringstream stream; | ||
stream << si; | ||
return stream.str(); | ||
}; | ||
py::class_<Class>( | ||
m, | ||
typestr.c_str(), | ||
py::buffer_protocol(), | ||
py::dynamic_attr()) | ||
.def(py::init<>()) | ||
.def(py::init<const Class&>()) | ||
.def(py::init<double, double, double, | ||
double, double, double>()) | ||
.def(py::init<const ignition::math::Vector3d&, | ||
const ignition::math::Vector3d>()) | ||
.def("x_length", | ||
&Class::XLength, | ||
"Get the length along the x dimension") | ||
.def("y_length", | ||
&Class::YLength, | ||
"Get the length along the y dimension") | ||
.def("z_length", | ||
&Class::ZLength, | ||
"Get the length along the z dimension") | ||
.def("size", | ||
&Class::Size, | ||
"Get the size of the box") | ||
.def("center", | ||
&Class::Center, | ||
"Get the box center") | ||
.def("merge", | ||
&Class::Merge, | ||
"Merge a box with this box") | ||
.def("volume", | ||
&Class::Volume, | ||
"Get the volume of the box in m^3.") | ||
.def(py::self + py::self) | ||
.def(py::self += py::self) | ||
.def(py::self + ignition::math::Vector3d()) | ||
.def(py::self - ignition::math::Vector3d()) | ||
.def(py::self == py::self) | ||
.def(py::self != py::self) | ||
.def("min", | ||
py::overload_cast<>(&Class::Min, py::const_), | ||
py::return_value_policy::reference, | ||
"Get the minimum corner.") | ||
.def("max", | ||
py::overload_cast<>(&Class::Max, py::const_), | ||
py::return_value_policy::reference, | ||
"Get the maximum corner.") | ||
.def("intersects", | ||
&Class::Intersects, | ||
"Test box intersection. This test will only work if " | ||
" both box's minimum corner is less than or equal to their " | ||
" maximum corner.") | ||
.def("contains", | ||
&Class::Contains, | ||
"Check if a point lies inside the box.") | ||
.def("intersect_check", | ||
&Class::IntersectCheck, | ||
"Check if a ray (origin, direction) intersects the box.") | ||
.def("intersect_dist", | ||
&Class::IntersectDist, | ||
"Check if a ray (origin, direction) intersects the box.") | ||
.def("intersect", | ||
py::overload_cast<const Vector3d &, const Vector3d &, | ||
const double, const double> | ||
(&Class::Intersect, py::const_), | ||
"Check if a ray (origin, direction) intersects the box.") | ||
.def("intersect", | ||
py::overload_cast<const Line3d&>(&Class::Intersect, py::const_), | ||
"Check if a ray (origin, direction) intersects the box.") | ||
.def("__copy__", [](const Class &self) { | ||
return Class(self); | ||
}) | ||
.def("__deepcopy__", [](const Class &self, py::dict) { | ||
return Class(self); | ||
}, "memo"_a) | ||
.def("__str__", toString) | ||
.def("__repr__", toString); | ||
} | ||
} // namespace python | ||
} // namespace math | ||
} // namespace ignition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2021 Open Source Robotics Foundation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
#ifndef IGNITION_MATH_PYTHON__AXISALIGNEDBOX_HPP_ | ||
#define IGNITION_MATH_PYTHON__AXISALIGNEDBOX_HPP_ | ||
|
||
#include <string> | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
namespace py = pybind11; | ||
|
||
namespace ignition | ||
{ | ||
namespace math | ||
{ | ||
namespace python | ||
{ | ||
/// Define a pybind11 wrapper for an ignition::math::AxisAlignedBox | ||
/** | ||
* \param[in] module a pybind11 module to add the definition to | ||
* \param[in] typestr name of the type used by Python | ||
*/ | ||
void defineMathAxisAlignedBox(py::module &m, const std::string &typestr); | ||
} // namespace python | ||
} // namespace math | ||
} // namespace ignition | ||
|
||
#endif // IGNITION_MATH_PYTHON__AXISALIGNEDBOX_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The coverage is decreasing, we should add tests for the new functions