| 17 | using namespace mitk; |
| 18 | |
| 19 | void InitVector2D(py::module_& m) |
| 20 | { |
| 21 | py::class_<Vector2D>(m, "Vector2D", |
| 22 | R"(2D vector in world coordinates. |
| 23 | |
| 24 | A pair of double-precision scalars representing a direction or offset. |
| 25 | Distinct from :py:class:`Point2D`: a vector encodes a displacement and is |
| 26 | unaffected by translations of the coordinate system. |
| 27 | )") |
| 28 | .def(py::init<>(), |
| 29 | "Construct a zero vector (0, 0).") |
| 30 | .def(py::init<ScalarType, ScalarType>(), py::arg("x"), py::arg("y"), |
| 31 | R"(Construct a vector with the given components. |
| 32 | |
| 33 | Args: |
| 34 | x: X component. |
| 35 | y: Y component. |
| 36 | )") |
| 37 | .def("__getitem__", [](const Vector2D& p, size_t i) { return p[i]; }, |
| 38 | "Return the i-th component (0 = x, 1 = y).") |
| 39 | .def("__setitem__", [](Vector2D& p, size_t i, ScalarType v) { p[i] = v; }, |
| 40 | "Set the i-th component.") |
| 41 | .def_property("x", |
| 42 | [](const Vector2D& p) { return p[0]; }, |
| 43 | [](Vector2D& p, ScalarType v) { p[0] = v; }, |
| 44 | "X component.") |
| 45 | .def_property("y", |
| 46 | [](const Vector2D& p) { return p[1]; }, |
| 47 | [](Vector2D& p, ScalarType v) { p[1] = v; }, |
| 48 | "Y component.") |
| 49 | .def("__repr__", |
| 50 | [](const Vector2D& p) { |
| 51 | return "<Vector2D [" |
| 52 | + std::to_string(p[0]) + ", " |
| 53 | + std::to_string(p[1]) + "]>"; |
| 54 | }); |
| 55 | } |
| 56 | |
| 57 | void InitVector3D(py::module_& m) |
| 58 | { |