22 #include "pybind11/pybind11.h"
34 using namespace pybind11::literals;
41 py::module::import(
"lsst.sphgeom.vector3d");
43 py::class_<UnitVector3d, std::shared_ptr<UnitVector3d>>
cls(mod,
47 py::implicitly_convertible<UnitVector3d, Vector3d>();
51 (UnitVector3d(*)(Vector3d
const &)) & UnitVector3d::orthogonalTo,
53 cls.def_static(
"orthogonalTo",
54 (UnitVector3d(*)(Vector3d
const &, Vector3d
const &)) &
55 UnitVector3d::orthogonalTo,
56 "vector1"_a,
"vector2"_a);
57 cls.def_static(
"orthogonalTo",
58 (UnitVector3d(*)(NormalizedAngle
const &)) &
59 UnitVector3d::orthogonalTo,
61 cls.def_static(
"northFrom", &UnitVector3d::northFrom,
"vector"_a);
64 cls.def_static(
"Z", &UnitVector3d::Z);
69 cls.def(py::init<>());
70 cls.def(py::init<UnitVector3d const &>(),
"unitVector"_a);
71 cls.def(py::init<Vector3d const &>(),
"vector"_a);
72 cls.def(py::init<double, double, double>(),
"x"_a,
"y"_a,
"z"_a);
73 cls.def(py::init<LonLat const &>(),
"lonLat"_a);
74 cls.def(py::init<Angle, Angle>(),
"lon"_a,
"lat"_a);
76 cls.def(
"__eq__", &UnitVector3d::operator==, py::is_operator());
77 cls.def(
"__ne__", &UnitVector3d::operator!=, py::is_operator());
79 (UnitVector3d(UnitVector3d::*)()
const) & UnitVector3d::operator-);
80 cls.def(
"__add__", &UnitVector3d::operator+, py::is_operator());
82 (Vector3d(UnitVector3d::*)(Vector3d
const &)
const) &
83 UnitVector3d::operator-,
85 cls.def(
"__mul__", &UnitVector3d::operator*, py::is_operator());
86 cls.def(
"__truediv__", &UnitVector3d::operator/, py::is_operator());
93 cls.def(
"cross", &UnitVector3d::cross);
94 cls.def(
"robustCross", &UnitVector3d::robustCross);
95 cls.def(
"cwiseProduct", &UnitVector3d::cwiseProduct);
96 cls.def(
"rotatedAround", &UnitVector3d::rotatedAround,
"axis"_a,
"angle"_a);
98 cls.def(
"__len__", [](UnitVector3d
const &
self) {
return py::int_(3); });
99 cls.def(
"__getitem__", [](UnitVector3d
const &
self, py::int_ i) {
100 return self(python::convertIndex(3, i));
103 cls.def(
"__str__", [](UnitVector3d
const &
self) {
104 return py::str(
"[{!s}, {!s}, {!s}]")
105 .format(
self.
x(),
self.
y(),
self.
z());
107 cls.def(
"__repr__", [](UnitVector3d
const &
self) {
108 return py::str(
"UnitVector3d({!r}, {!r}, {!r})")
109 .format(
self.
x(),
self.
y(),
self.
z());
121 cls.def(py::pickle([](UnitVector3d
const &
self) {
return py::make_tuple(
self.
x(),
self.
y(),
self.
z()); },
125 "; must be 3 for a UnitVector3d");
127 return new UnitVector3d(UnitVector3d::fromNormalized(
128 t[0].cast<double>(), t[1].cast<double>(), t[2].cast<double>()));