forked from gazebosim/sdformat
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benjamin Perseghetti <[email protected]>
- Loading branch information
1 parent
9c2474f
commit d9154be
Showing
21 changed files
with
754 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2024 CogniPilot Foundation | ||
* Copyright 2024 Open Source Robotics Foundation | ||
* Copyright 2024 Rudis Laboratories | ||
* | ||
* 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 "pyCone.hh" | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "sdf/Cone.hh" | ||
|
||
using namespace pybind11::literals; | ||
|
||
namespace sdf | ||
{ | ||
// Inline bracket to help doxygen filtering. | ||
inline namespace SDF_VERSION_NAMESPACE { | ||
namespace python | ||
{ | ||
///////////////////////////////////////////////// | ||
void defineCone(pybind11::object module) | ||
{ | ||
pybind11::class_<sdf::Cone>(module, "Cone") | ||
.def(pybind11::init<>()) | ||
.def(pybind11::init<sdf::Cone>()) | ||
.def("radius", &sdf::Cone::Radius, | ||
"Get the cone's radius in meters.") | ||
.def("set_radius", &sdf::Cone::SetRadius, | ||
"Set the cone's radius in meters.") | ||
.def("length", &sdf::Cone::Length, | ||
"Get the cone's length in meters.") | ||
.def("set_length", &sdf::Cone::SetLength, | ||
"Set the cone's length in meters.") | ||
.def( | ||
"shape", | ||
pybind11::overload_cast<>(&sdf::Cone::Shape, pybind11::const_), | ||
pybind11::return_value_policy::reference, | ||
"Get a mutable Gazebo Math representation of this Cone.") | ||
.def("__copy__", [](const sdf::Cone &self) { | ||
return sdf::Cone(self); | ||
}) | ||
.def("__deepcopy__", [](const sdf::Cone &self, pybind11::dict) { | ||
return sdf::Cone(self); | ||
}, "memo"_a); | ||
} | ||
} // namespace python | ||
} // namespace SDF_VERSION_NAMESPACE | ||
} // namespace sdf |
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,43 @@ | ||
/* | ||
* Copyright 2024 CogniPilot Foundation | ||
* Copyright 2024 Open Source Robotics Foundation | ||
* Copyright 2024 Rudis Laboratories | ||
* | ||
* 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 SDFORMAT_PYTHON_CONE_HH_ | ||
#define SDFORMAT_PYTHON_CONE_HH_ | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include "sdf/Cone.hh" | ||
|
||
#include "sdf/config.hh" | ||
|
||
namespace sdf | ||
{ | ||
// Inline bracket to help doxygen filtering. | ||
inline namespace SDF_VERSION_NAMESPACE { | ||
namespace python | ||
{ | ||
/// Define a pybind11 wrapper for an sdf::Cone | ||
/** | ||
* \param[in] module a pybind11 module to add the definition to | ||
*/ | ||
void defineCone(pybind11::object module); | ||
} // namespace python | ||
} // namespace SDF_VERSION_NAMESPACE | ||
} // namespace sdf | ||
|
||
#endif // SDFORMAT_PYTHON_CONE_HH_ |
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,114 @@ | ||
# Copyright 2024 CogniPilot Foundation | ||
# Copyright 2024 Open Source Robotics Foundation | ||
# Copyright 2024 Rudis Laboratories | ||
|
||
# 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. | ||
|
||
import copy | ||
|
||
import math | ||
|
||
from gz_test_deps.sdformat import Cone | ||
|
||
import unittest | ||
|
||
|
||
class ConeTEST(unittest.TestCase): | ||
|
||
def test_default_construction(self): | ||
cone = Cone() | ||
|
||
self.assertEqual(math.pi * math.pow(0.5, 2) * 1.0, | ||
cone.shape().volume()) | ||
|
||
self.assertEqual(0.5, cone.radius()) | ||
self.assertEqual(1.0, cone.length()) | ||
|
||
cone.set_radius(0.5) | ||
cone.set_length(2.3) | ||
|
||
self.assertEqual(0.5, cone.radius()) | ||
self.assertEqual(2.3, cone.length()) | ||
|
||
def test_assignment(self): | ||
cone = Cone() | ||
cone.set_radius(0.2) | ||
cone.set_length(3.0) | ||
self.assertEqual(math.pi * math.pow(0.2, 2) * 3.0 / 3.0, | ||
cone.shape().volume()) | ||
|
||
cone2 = cone | ||
self.assertEqual(0.2, cone2.radius()) | ||
self.assertEqual(3.0, cone2.length()) | ||
|
||
self.assertEqual(math.pi * math.pow(0.2, 2) * 3.0 / 3.0, | ||
cone2.shape().volume()) | ||
self.assertEqual(0.2, cone2.shape().radius()) | ||
self.assertEqual(3.0, cone2.shape().length()) | ||
|
||
cone.set_radius(2.0) | ||
cone.set_length(0.3) | ||
|
||
self.assertEqual(2.0, cone.radius()) | ||
self.assertEqual(0.3, cone.length()) | ||
self.assertEqual(2.0, cone2.radius()) | ||
self.assertEqual(0.3, cone2.length()) | ||
|
||
|
||
def test_copy_construction(self): | ||
cone = Cone(); | ||
cone.set_radius(0.2) | ||
cone.set_length(3.0) | ||
|
||
cone2 = Cone(cone) | ||
self.assertEqual(0.2, cone2.radius()) | ||
self.assertEqual(3.0, cone2.length()) | ||
|
||
cone.set_radius(2.) | ||
cone.set_length(0.3) | ||
|
||
self.assertEqual(2, cone.radius()) | ||
self.assertEqual(0.3, cone.length()) | ||
self.assertEqual(0.2, cone2.radius()) | ||
self.assertEqual(3.0, cone2.length()) | ||
|
||
def test_deepcopy(self): | ||
cone = Cone(); | ||
cone.set_radius(0.2) | ||
cone.set_length(3.0) | ||
|
||
cone2 = copy.deepcopy(cone); | ||
self.assertEqual(0.2, cone2.radius()) | ||
self.assertEqual(3.0, cone2.length()) | ||
|
||
cone.set_radius(2.) | ||
cone.set_length(0.3) | ||
|
||
self.assertEqual(2, cone.radius()) | ||
self.assertEqual(0.3, cone.length()) | ||
self.assertEqual(0.2, cone2.radius()) | ||
self.assertEqual(3.0, cone2.length()) | ||
|
||
def test_shape(self): | ||
cone = Cone(); | ||
self.assertEqual(0.5, cone.radius()) | ||
self.assertEqual(1.0, cone.length()) | ||
|
||
cone.shape().set_radius(0.123) | ||
cone.shape().set_length(0.456) | ||
self.assertEqual(0.123, cone.radius()) | ||
self.assertEqual(0.456, cone.length()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
Oops, something went wrong.