From d5f349cfff13e984cef48ab36d398aa790c6b2c0 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 17 Oct 2018 01:06:24 +0200 Subject: [PATCH] Add comparison operators to geom classes --- LibCarla/source/carla/geom/Location.h | 8 ++++++++ LibCarla/source/carla/geom/Rotation.h | 8 ++++++++ LibCarla/source/carla/geom/Transform.h | 8 ++++++++ LibCarla/source/carla/geom/Vector3D.h | 8 ++++++++ PythonAPI/source/libcarla/Blueprint.cpp | 2 ++ PythonAPI/source/libcarla/Transform.cpp | 8 ++++++++ 6 files changed, 42 insertions(+) diff --git a/LibCarla/source/carla/geom/Location.h b/LibCarla/source/carla/geom/Location.h index 7ef93d411..911081a67 100644 --- a/LibCarla/source/carla/geom/Location.h +++ b/LibCarla/source/carla/geom/Location.h @@ -48,6 +48,14 @@ namespace geom { return lhs; } + bool operator==(const Location &rhs) const { + return static_cast(*this) == rhs; + } + + bool operator!=(const Location &rhs) const { + return !(*this == rhs); + } + #ifdef LIBCARLA_INCLUDED_FROM_UE4 Location(const FVector &vector) // from centimeters to meters. diff --git a/LibCarla/source/carla/geom/Rotation.h b/LibCarla/source/carla/geom/Rotation.h index 7e8f75b71..8bfd2cbc6 100644 --- a/LibCarla/source/carla/geom/Rotation.h +++ b/LibCarla/source/carla/geom/Rotation.h @@ -29,6 +29,14 @@ namespace geom { float yaw = 0.0f; float roll = 0.0f; + bool operator==(const Rotation &rhs) const { + return (pitch == rhs.pitch) && (yaw == rhs.yaw) && (roll == rhs.roll); + } + + bool operator!=(const Rotation &rhs) const { + return !(*this == rhs); + } + #ifdef LIBCARLA_INCLUDED_FROM_UE4 Rotation(const FRotator &rotator) diff --git a/LibCarla/source/carla/geom/Transform.h b/LibCarla/source/carla/geom/Transform.h index e53f8f06d..5402729d7 100644 --- a/LibCarla/source/carla/geom/Transform.h +++ b/LibCarla/source/carla/geom/Transform.h @@ -29,6 +29,14 @@ namespace geom { Location location; Rotation rotation; + bool operator==(const Transform &rhs) const { + return (location == rhs.location) && (rotation == rhs.rotation); + } + + bool operator!=(const Transform &rhs) const { + return !(*this == rhs); + } + #ifdef LIBCARLA_INCLUDED_FROM_UE4 Transform(const FTransform &transform) diff --git a/LibCarla/source/carla/geom/Vector3D.h b/LibCarla/source/carla/geom/Vector3D.h index 8f8ddab11..fc45b6de9 100644 --- a/LibCarla/source/carla/geom/Vector3D.h +++ b/LibCarla/source/carla/geom/Vector3D.h @@ -49,6 +49,14 @@ namespace geom { return lhs; } + bool operator==(const Vector3D &rhs) const { + return (x == rhs.x) && (y == rhs.y) && (z == rhs.z); + } + + bool operator!=(const Vector3D &rhs) const { + return !(*this == rhs); + } + // ========================================================================= /// @todo The following is copy-pasted from MSGPACK_DEFINE_ARRAY. /// This is a workaround for an issue in msgpack library. The diff --git a/PythonAPI/source/libcarla/Blueprint.cpp b/PythonAPI/source/libcarla/Blueprint.cpp index d329034df..5cff1eb23 100644 --- a/PythonAPI/source/libcarla/Blueprint.cpp +++ b/PythonAPI/source/libcarla/Blueprint.cpp @@ -114,6 +114,8 @@ void export_blueprint() { .def_readwrite("g", &csd::Color::g) .def_readwrite("b", &csd::Color::b) .def_readwrite("a", &csd::Color::a) + .def("__eq__", &csd::Color::operator==) + .def("__ne__", &csd::Color::operator!=) .def(self_ns::str(self_ns::self)) ; diff --git a/PythonAPI/source/libcarla/Transform.cpp b/PythonAPI/source/libcarla/Transform.cpp index ce4ef7914..41410f1ac 100644 --- a/PythonAPI/source/libcarla/Transform.cpp +++ b/PythonAPI/source/libcarla/Transform.cpp @@ -49,6 +49,8 @@ void export_transform() { .def_readwrite("x", &cg::Vector3D::x) .def_readwrite("y", &cg::Vector3D::y) .def_readwrite("z", &cg::Vector3D::z) + .def("__eq__", &cg::Vector3D::operator==) + .def("__ne__", &cg::Vector3D::operator!=) .def(self += self) .def(self + self) .def(self -= self) @@ -61,6 +63,8 @@ void export_transform() { .add_property("x", +[](const cg::Location &self) { return self.x; }, +[](cg::Location &self, float x) { self.x = x; }) .add_property("y", +[](const cg::Location &self) { return self.y; }, +[](cg::Location &self, float y) { self.y = y; }) .add_property("z", +[](const cg::Location &self) { return self.z; }, +[](cg::Location &self, float z) { self.z = z; }) + .def("__eq__", &cg::Location::operator==) + .def("__ne__", &cg::Location::operator!=) .def(self += self) .def(self + self) .def(self -= self) @@ -73,6 +77,8 @@ void export_transform() { .def_readwrite("pitch", &cg::Rotation::pitch) .def_readwrite("yaw", &cg::Rotation::yaw) .def_readwrite("roll", &cg::Rotation::roll) + .def("__eq__", &cg::Rotation::operator==) + .def("__ne__", &cg::Rotation::operator!=) .def(self_ns::str(self_ns::self)) ; @@ -81,6 +87,8 @@ void export_transform() { (arg("location")=cg::Location(), arg("rotation")=cg::Rotation()))) .def_readwrite("location", &cg::Transform::location) .def_readwrite("rotation", &cg::Transform::rotation) + .def("__eq__", &cg::Transform::operator==) + .def("__ne__", &cg::Transform::operator!=) .def(self_ns::str(self_ns::self)) ; }