22 #include "pybind11/pybind11.h"
30 using namespace pybind11::literals;
37 py::class_<LonLat, std::shared_ptr<LonLat>>
cls(mod,
"LonLat");
39 cls.def_static(
"fromDegrees", &LonLat::fromDegrees);
40 cls.def_static(
"fromRadians", &LonLat::fromRadians);
41 cls.def_static(
"latitudeOf", &LonLat::latitudeOf);
42 cls.def_static(
"longitudeOf", &LonLat::longitudeOf);
44 cls.def(py::init<>());
45 cls.def(py::init<LonLat const &>());
46 cls.def(py::init<NormalizedAngle, Angle>(),
"lon"_a,
"lat"_a);
47 cls.def(py::init<Vector3d const &>(),
"vector"_a);
49 cls.def(
"__eq__", &LonLat::operator==, py::is_operator());
50 cls.def(
"__nq__", &LonLat::operator!=, py::is_operator());
52 cls.def(
"getLon", &LonLat::getLon);
53 cls.def(
"getLat", &LonLat::getLat);
55 cls.def(
"__len__", [](LonLat
const &
self) {
return py::int_(2); });
56 cls.def(
"__getitem__", [](LonLat
const &
self, py::object
key) {
57 auto t = py::make_tuple(
self.getLon(),
self.getLat());
58 return t.attr(
"__getitem__")(
key);
60 cls.def(
"__iter__", [](LonLat
const &
self) {
61 auto t = py::make_tuple(
self.getLon(),
self.getLat());
62 return t.attr(
"__iter__")();
65 cls.def(
"__str__", [](LonLat
const &
self) {
66 return py::str(
"[{!s}, {!s}]")
67 .format(
self.getLon().asRadians(),
self.getLat().asRadians());
69 cls.def(
"__repr__", [](LonLat
const &
self) {
70 return py::str(
"LonLat.fromRadians({!r}, {!r})")
71 .format(
self.getLon().asRadians(),
self.getLat().asRadians());
73 cls.def(
"__reduce__", [
cls](LonLat
const &
self) {
74 return py::make_tuple(
cls,
75 py::make_tuple(
self.getLon(),
self.getLat()));