26 #include <type_traits>
28 #include "pybind11/pybind11.h"
29 #include "pybind11/stl.h"
30 #include "ndarray/pybind11.h"
39 using namespace py::literals;
53 template <
typename PyClass>
57 cls.def(
"__repr__", [](Class
const&
self) {
59 os <<
"lsst.afw.geom." <<
self;
62 cls.def_static(
"getClassPrefix", &Class::getClassPrefix);
68 template <
typename PyClass>
71 cls.def(
"getNPoints", &Class::getNPoints);
72 cls.def(
"dataFromPoint", &Class::dataFromPoint);
73 cls.def(
"dataFromArray", &Class::dataFromArray);
74 cls.def(
"arrayFromData", &Class::arrayFromData);
75 cls.def(
"pointFromData", &Class::pointFromData);
81 template <
typename PyClass>
85 cls.def(
"makeFrame", [](Class
const&
self) {
86 auto frame =
self.makeFrame();
92 template <
typename SelfClass,
typename OtherClass,
typename PyClass>
93 std::enable_if_t<std::is_base_of<SelfClass, OtherClass>::value> addEquals(
PyClass&
cls) {
94 cls.def(
"__eq__", &SelfClass::operator==);
95 cls.def(
"__ne__", &SelfClass::operator!=);
98 template <
typename SelfClass,
typename OtherClass,
typename PyClass>
99 std::enable_if_t<!std::is_base_of<SelfClass, OtherClass>::value> addEquals(
PyClass&
cls) {
100 cls.def(
"__eq__", [](SelfClass
const&
self, OtherClass
const&
other) {
return false; });
101 cls.def(
"__ne__", [](SelfClass
const&
self, OtherClass
const&
other) {
return true; });
104 template <
typename SelfClass,
typename PyClass>
106 addEquals<SelfClass, GenericEndpoint>(
cls);
107 addEquals<SelfClass, Point2Endpoint>(
cls);
108 addEquals<SelfClass, SpherePointEndpoint>(
cls);
115 template <
typename Po
int,
typename Array>
117 using Class = BaseEndpoint<Point, Array>;
118 std::string const pyClassName =
"_BaseEndpoint" + suffix;
120 py::class_<Class, std::shared_ptr<Class>>
cls(mod, pyClassName.
c_str());
122 cls.def_property_readonly(
"nAxes", &Class::getNAxes);
123 addDataConverters(
cls);
125 cls.def(
"normalizeFrame", &Class::normalizeFrame);
126 addAllEquals<Class>(
cls);
131 template <
typename Po
int>
133 using Class = BaseVectorEndpoint<Point>;
134 using Array =
typename Class::Array;
135 std::string const pyClassName =
"_BaseVectorEndpoint" + suffix;
137 declareBaseEndpoint<Point, Array>(mod, suffix);
139 py::class_<Class, std::shared_ptr<Class>, BaseEndpoint<Point, Array>>
cls(mod, pyClassName.
c_str());
141 addDataConverters(
cls);
145 void declareGenericEndpoint(
py::module& mod) {
146 using Class = GenericEndpoint;
147 using Point =
typename Class::Point;
148 using Array =
typename Class::Array;
150 declareBaseEndpoint<Point, Array>(mod,
"Generic");
152 py::class_<Class, std::shared_ptr<Class>, BaseEndpoint<Point, Array>>
cls(mod,
"GenericEndpoint");
154 cls.def(py::init<int>(),
"nAxes"_a);
161 using Class = Point2Endpoint;
162 using Point =
typename Class::Point;
164 std::string const pyClassName = pointNumStr +
"Endpoint";
166 declareBaseVectorEndpoint<Point>(mod, pointNumStr);
168 py::class_<Class, std::shared_ptr<Class>, BaseVectorEndpoint<Point>>
cls(mod, pyClassName.
c_str());
170 cls.def(py::init<>());
173 cls.def(
"normalizeFrame", &Class::normalizeFrame);
178 void declareSpherePointEndpoint(
py::module& mod) {
179 using Class = SpherePointEndpoint;
180 using Point =
typename Class::Point;
182 declareBaseVectorEndpoint<Point>(mod,
"SpherePoint");
184 py::class_<Class, std::shared_ptr<Class>, BaseVectorEndpoint<Point>>
cls(mod,
"SpherePointEndpoint");
186 cls.def(py::init<>());
190 cls.def(
"normalizeFrame", &Class::normalizeFrame);
195 py::module::import(
"lsst.geom");
197 declareGenericEndpoint(mod);
198 declarePoint2Endpoint(mod);
199 declareSpherePointEndpoint(mod);