Add class Vector3D
This commit is contained in:
parent
16f4996e71
commit
050467e109
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "carla/MsgPack.h"
|
||||
#include "carla/geom/Vector3D.h"
|
||||
|
||||
#ifdef LIBCARLA_INCLUDED_FROM_UE4
|
||||
# include "Math/Vector.h"
|
||||
|
@ -15,24 +15,21 @@
|
|||
namespace carla {
|
||||
namespace geom {
|
||||
|
||||
class Location {
|
||||
class Location : private Vector3D {
|
||||
public:
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
using Vector3D::Vector3D;
|
||||
|
||||
Location() = default;
|
||||
using Vector3D::x;
|
||||
using Vector3D::y;
|
||||
using Vector3D::z;
|
||||
|
||||
Location(float ix, float iy, float iz)
|
||||
: x(ix),
|
||||
y(iy),
|
||||
z(iz) {}
|
||||
using Vector3D::msgpack_pack;
|
||||
using Vector3D::msgpack_unpack;
|
||||
using Vector3D::msgpack_object;
|
||||
|
||||
Location &operator+=(const Location &rhs) {
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
z += rhs.z;
|
||||
static_cast<Vector3D &>(*this) += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -42,9 +39,7 @@ namespace geom {
|
|||
}
|
||||
|
||||
Location &operator-=(const Location &rhs) {
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
z -= rhs.z;
|
||||
static_cast<Vector3D &>(*this) -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -63,28 +58,6 @@ namespace geom {
|
|||
}
|
||||
|
||||
#endif // LIBCARLA_INCLUDED_FROM_UE4
|
||||
|
||||
// =========================================================================
|
||||
/// @todo The following is copy-pasted from MSGPACK_DEFINE_ARRAY.
|
||||
/// This is a workaround for an issue in msgpack library. The
|
||||
/// MSGPACK_DEFINE_ARRAY macro is shadowing our `z` variable.
|
||||
/// https://github.com/msgpack/msgpack-c/issues/709
|
||||
// =========================================================================
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_pack(pk);
|
||||
}
|
||||
void msgpack_unpack(clmdep_msgpack::object const& o)
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_unpack(o);
|
||||
}
|
||||
template <typename MSGPACK_OBJECT>
|
||||
void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& sneaky_variable_that_shadows_z) const
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_object(o, sneaky_variable_that_shadows_z);
|
||||
}
|
||||
// =========================================================================
|
||||
};
|
||||
|
||||
} // namespace geom
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
|
||||
// de Barcelona (UAB).
|
||||
//
|
||||
// This work is licensed under the terms of the MIT license.
|
||||
// For a copy, see <https://opensource.org/licenses/MIT>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "carla/MsgPack.h"
|
||||
|
||||
namespace carla {
|
||||
namespace geom {
|
||||
|
||||
class Vector3D {
|
||||
public:
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
|
||||
Vector3D() = default;
|
||||
|
||||
Vector3D(float ix, float iy, float iz)
|
||||
: x(ix),
|
||||
y(iy),
|
||||
z(iz) {}
|
||||
|
||||
Vector3D &operator+=(const Vector3D &rhs) {
|
||||
x += rhs.x;
|
||||
y += rhs.y;
|
||||
z += rhs.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend Vector3D operator+(Vector3D lhs, const Vector3D &rhs) {
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Vector3D &operator-=(const Vector3D &rhs) {
|
||||
x -= rhs.x;
|
||||
y -= rhs.y;
|
||||
z -= rhs.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend Vector3D operator-(Vector3D lhs, const Vector3D &rhs) {
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
/// @todo The following is copy-pasted from MSGPACK_DEFINE_ARRAY.
|
||||
/// This is a workaround for an issue in msgpack library. The
|
||||
/// MSGPACK_DEFINE_ARRAY macro is shadowing our `z` variable.
|
||||
/// https://github.com/msgpack/msgpack-c/issues/709
|
||||
// =========================================================================
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_pack(pk);
|
||||
}
|
||||
void msgpack_unpack(clmdep_msgpack::object const& o)
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_unpack(o);
|
||||
}
|
||||
template <typename MSGPACK_OBJECT>
|
||||
void msgpack_object(MSGPACK_OBJECT* o, clmdep_msgpack::zone& sneaky_variable_that_shadows_z) const
|
||||
{
|
||||
clmdep_msgpack::type::make_define_array(x, y, z).msgpack_object(o, sneaky_variable_that_shadows_z);
|
||||
}
|
||||
// =========================================================================
|
||||
};
|
||||
|
||||
} // namespace geom
|
||||
} // namespace carla
|
|
@ -11,6 +11,13 @@
|
|||
namespace carla {
|
||||
namespace geom {
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Vector3D &vector3D) {
|
||||
out << "Vector3D(x=" << vector3D.x
|
||||
<< ", y=" << vector3D.y
|
||||
<< ", z=" << vector3D.z << ')';
|
||||
return out;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Location &location) {
|
||||
out << "Location(x=" << location.x
|
||||
<< ", y=" << location.y
|
||||
|
@ -37,11 +44,23 @@ void export_transform() {
|
|||
using namespace boost::python;
|
||||
namespace cg = carla::geom;
|
||||
|
||||
class_<cg::Vector3D>("Vector3D")
|
||||
.def(init<float, float, float>((arg("x")=0.0f, arg("y")=0.0f, arg("z")=0.0f)))
|
||||
.def_readwrite("x", &cg::Vector3D::x)
|
||||
.def_readwrite("y", &cg::Vector3D::y)
|
||||
.def_readwrite("z", &cg::Vector3D::z)
|
||||
.def(self += self)
|
||||
.def(self + self)
|
||||
.def(self -= self)
|
||||
.def(self - self)
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cg::Location>("Location")
|
||||
.def(init<float, float, float>((arg("x")=0.0f, arg("y")=0.0f, arg("z")=0.0f)))
|
||||
.def_readwrite("x", &cg::Location::x)
|
||||
.def_readwrite("y", &cg::Location::y)
|
||||
.def_readwrite("z", &cg::Location::z)
|
||||
.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(self += self)
|
||||
.def(self + self)
|
||||
.def(self -= self)
|
||||
|
|
Loading…
Reference in New Issue