| 55 | } |
| 56 | |
| 57 | void InitVector3D(py::module_& m) |
| 58 | { |
| 59 | py::class_<Vector3D>(m, "Vector3D", |
| 60 | R"(3D vector in world coordinates. |
| 61 | |
| 62 | A triple of double-precision scalars representing a direction or offset. |
| 63 | Distinct from :py:class:`Point3D`: a vector encodes a displacement and is |
| 64 | unaffected by translations of the coordinate system. |
| 65 | )") |
| 66 | .def(py::init<>(), |
| 67 | "Construct a zero vector (0, 0, 0).") |
| 68 | .def(py::init<ScalarType, ScalarType, ScalarType>(), py::arg("x"), py::arg("y"), py::arg("z"), |
| 69 | R"(Construct a vector with the given components. |
| 70 | |
| 71 | Args: |
| 72 | x: X component. |
| 73 | y: Y component. |
| 74 | z: Z component. |
| 75 | )") |
| 76 | .def("__getitem__", [](const Vector3D& p, size_t i) { return p[i]; }, |
| 77 | "Return the i-th component (0 = x, 1 = y, 2 = z).") |
| 78 | .def("__setitem__", [](Vector3D& p, size_t i, ScalarType v) { p[i] = v; }, |
| 79 | "Set the i-th component.") |
| 80 | .def_property("x", |
| 81 | [](const Vector3D& p) { return p[0]; }, |
| 82 | [](Vector3D& p, ScalarType v) { p[0] = v; }, |
| 83 | "X component.") |
| 84 | .def_property("y", |
| 85 | [](const Vector3D& p) { return p[1]; }, |
| 86 | [](Vector3D& p, ScalarType v) { p[1] = v; }, |
| 87 | "Y component.") |
| 88 | .def_property("z", |
| 89 | [](const Vector3D& p) { return p[2]; }, |
| 90 | [](Vector3D& p, ScalarType v) { p[2] = v; }, |
| 91 | "Z component.") |
| 92 | .def("__repr__", |
| 93 | [](const Vector3D& p) { |
| 94 | return "<Vector3D [" |
| 95 | + std::to_string(p[0]) + ", " |
| 96 | + std::to_string(p[1]) + ", " |
| 97 | + std::to_string(p[2]) + "]>"; |
| 98 | }); |
| 99 | } |
| 100 | |
| 101 | void InitVectors(py::module_& m) |
| 102 | { |