8 #include <pybind11/operators.h>
9 #include <pybind11/pybind11.h>
14 using namespace pybind11::literals;
17 #define DEFINE_VECTOR2TPL_TYPE(cppname, pyname, type_) \
18 py::class_<cppname>(cccorelib, pyname) \
20 .def(py::init<type_, type_>()) \
21 .def_readwrite("x", &cppname::x) \
22 .def_readwrite("y", &cppname::y) \
23 .def("norm2", &cppname::norm2) \
24 .def("norm", &cppname::norm) \
25 .def("normalize", &cppname::normalize) \
26 .def("dot", &cppname::dot) \
27 .def("cross", &cppname::cross) \
29 [](const cppname &self, unsigned index) \
33 throw py::index_error(); \
37 .def(py::self += py::self) \
38 .def(py::self -= py::self) \
39 .def(py::self *= type_()) \
42 [](cppname &self, type_ val) \
44 if (val == static_cast<type_>(0.0)) \
46 throw std::runtime_error("Division by 0"); \
51 .def(py::self + py::self) \
52 .def(py::self - py::self) \
53 .def(py::self *type_()) \
56 [](cppname &self, type_ val) \
58 if (val == static_cast<type_>(0.0)) \
60 throw std::runtime_error("Division by 0"); \
66 [](const cppname &self) \
68 return std::string("<") + pyname + "(" + std::to_string(self.x) + ", " + \
69 std::to_string(self.y) + ")>"; \
72 #define DEFINE_TUPLE3TPL(cppname, pyname, type_) \
73 py::class_<cppname>(cccorelib, pyname) \
75 .def(py::init<type_, type_, type_>()) \
76 .def_readwrite("x", &cppname::x) \
77 .def_readwrite("y", &cppname::y) \
78 .def_readwrite("z", &cppname::z) \
79 .def(py::self -= py::self) \
80 .def(py::self += py::self) \
81 .def(py::self *= type_()) \
84 [](cppname &self, type_ val) \
86 if (val == static_cast<type_>(0.0)) \
88 throw std::runtime_error("Division by 0"); \
93 .def(py::self - py::self) \
94 .def(py::self + py::self) \
95 .def(py::self *type_()) \
98 [](cppname &self, type_ val) \
100 if (val == static_cast<type_>(0.0)) \
102 throw std::runtime_error("Division by 0"); \
107 .def("__getitem__", \
108 [](const cppname &self, unsigned index) \
119 throw py::index_error("index out of range"); \
123 #define DEFINE_CCVECTOR3(cppname, pyname, type_) \
124 py::class_<cppname, Tuple3Tpl<type_>>(cccorelib, pyname) \
126 .def(py::init<type_, type_, type_>()) \
127 .def("__mul__", [](const cppname &self, PointCoordinateType val) { return self * val; }) \
128 .def("__sub__", [](const cppname &self, const cppname &other) { return self - other; }) \
129 .def("__div__", &cppname::operator/) \
130 .def("__add__", [](const cppname &self, const cppname &other) { return self + other; }) \
132 [](const cppname &self) \
134 return std::string("<") + pyname + "(" + std::to_string(self.x) + ", " + \
135 std::to_string(self.y) + ", " + std::to_string(self.z) + ")>"; \
144 using uchar =
unsigned char;
145 using uint =
unsigned int;
#define DEFINE_VECTOR2TPL_TYPE(cppname, pyname, type_)
#define DEFINE_TUPLE3TPL(cppname, pyname, type_)
void define_CCGeom(py::module &cccorelib)
#define DEFINE_CCVECTOR3(cppname, pyname, type_)
float PointCoordinateType
Type of the coordinates of a (N-D) point.