22 #include "pybind11/pybind11.h"
32 using namespace pybind11::literals;
39 py::class_<Vector3d, std::shared_ptr<Vector3d>>
cls(mod,
"Vector3d");
41 cls.def(py::init<>());
42 cls.def(py::init<double, double, double>(),
"x"_a,
"y"_a,
"z"_a);
43 cls.def(py::init<Vector3d const &>(),
"vector"_a);
48 return new Vector3d(u.x(), u.y(), u.z());
51 cls.def(
"__eq__", &Vector3d::operator==, py::is_operator());
52 cls.def(
"__ne__", &Vector3d::operator!=, py::is_operator());
53 cls.def(
"__neg__", (Vector3d(Vector3d::*)()
const) & Vector3d::operator-);
54 cls.def(
"__add__", &Vector3d::operator+, py::is_operator());
56 (Vector3d(Vector3d::*)(Vector3d
const &)
const) &
59 cls.def(
"__mul__", &Vector3d::operator*, py::is_operator());
60 cls.def(
"__truediv__", &Vector3d::operator/, py::is_operator());
62 cls.def(
"__iadd__", &Vector3d::operator+=);
63 cls.def(
"__isub__", &Vector3d::operator-=);
64 cls.def(
"__imul__", &Vector3d::operator*=);
65 cls.def(
"__itruediv__", &Vector3d::operator/=);
71 cls.def(
"getSquaredNorm", &Vector3d::getSquaredNorm);
72 cls.def(
"getNorm", &Vector3d::getNorm);
73 cls.def(
"isZero", &Vector3d::isZero);
74 cls.def(
"normalize", &Vector3d::normalize);
75 cls.def(
"isNormalized", &Vector3d::isNormalized);
76 cls.def(
"cross", &Vector3d::cross);
77 cls.def(
"cwiseProduct", &Vector3d::cwiseProduct);
78 cls.def(
"rotatedAround", &Vector3d::rotatedAround,
"axis"_a,
"angle"_a);
80 cls.def(
"__len__", [](Vector3d
const &
self) {
return py::int_(3); });
81 cls.def(
"__getitem__", [](Vector3d
const &
self, py::int_ i) {
82 return self(python::convertIndex(3, i));
85 cls.def(
"__str__", [](Vector3d
const &
self) {
86 return py::str(
"[{!s}, {!s}, {!s}]")
87 .format(
self.
x(),
self.
y(),
self.
z());
89 cls.def(
"__repr__", [](Vector3d
const &
self) {
90 return py::str(
"Vector3d({!r}, {!r}, {!r})")
91 .format(
self.
x(),
self.
y(),
self.
z());
94 cls.def(
"__reduce__", [
cls](Vector3d
const &
self) {
95 return py::make_tuple(
cls,
96 py::make_tuple(
self.
x(),
self.
y(),
self.
z()));