LSSTApplications  20.0.0
LSSTDataManagementBasePackage
normalizedAngle.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * See COPYRIGHT file at the top of the source tree.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #include "pybind11/pybind11.h"
23 
24 #include "lsst/sphgeom/LonLat.h"
26 #include "lsst/sphgeom/Vector3d.h"
27 
28 namespace py = pybind11;
29 using namespace pybind11::literals;
30 
31 namespace lsst {
32 namespace sphgeom {
33 namespace {
34 
35 PYBIND11_MODULE(normalizedAngle, mod) {
36  py::module::import("lsst.sphgeom.angle");
37 
38  py::class_<NormalizedAngle> cls(mod, "NormalizedAngle");
39  // Provide the equivalent of the NormalizedAngle to Angle C++ cast
40  // operator in Python
41  py::implicitly_convertible<NormalizedAngle, Angle>();
42 
43  cls.def_static("nan", &NormalizedAngle::nan);
44  cls.def_static("fromDegrees", &NormalizedAngle::fromDegrees);
45  cls.def_static("fromRadians", &NormalizedAngle::fromRadians);
46  cls.def_static("between", &NormalizedAngle::between, "a"_a, "b"_a);
47  cls.def_static("center", &NormalizedAngle::center, "a"_a, "b"_a);
48 
49  cls.def(py::init<>());
50  cls.def(py::init<NormalizedAngle const &>());
51  cls.def(py::init<Angle const &>());
52  cls.def(py::init<double>(), "radians"_a);
53  cls.def(py::init<LonLat const &, LonLat const &>(), "a"_a, "b"_a);
54  cls.def(py::init<Vector3d const &, Vector3d const &>(), "a"_a, "b"_a);
55 
56  cls.def("__eq__", &NormalizedAngle::operator==, py::is_operator());
57  cls.def("__ne__", &NormalizedAngle::operator!=, py::is_operator());
58  cls.def("__lt__", &NormalizedAngle::operator<, py::is_operator());
59  cls.def("__gt__", &NormalizedAngle::operator>, py::is_operator());
60  cls.def("__le__", &NormalizedAngle::operator<=, py::is_operator());
61  cls.def("__ge__", &NormalizedAngle::operator>=, py::is_operator());
62 
63  cls.def("__neg__",
64  (Angle(NormalizedAngle::*)() const) & NormalizedAngle::operator-);
65  cls.def("__add__", &NormalizedAngle::operator+, py::is_operator());
66  cls.def("__sub__",
67  (Angle(NormalizedAngle::*)(Angle const &) const) &
68  NormalizedAngle::operator-,
69  py::is_operator());
70  cls.def("__mul__", &NormalizedAngle::operator*, py::is_operator());
71  cls.def("__rmul__", &NormalizedAngle::operator*, py::is_operator());
72  cls.def("__truediv__",
73  (Angle(NormalizedAngle::*)(double) const) &
74  NormalizedAngle::operator/,
75  py::is_operator());
76  cls.def("__truediv__",
77  (double (NormalizedAngle::*)(Angle const &) const) &
78  NormalizedAngle::operator/,
79  py::is_operator());
80 
81  cls.def("asDegrees", &NormalizedAngle::asDegrees);
82  cls.def("asRadians", &NormalizedAngle::asRadians);
83  cls.def("isNan", &NormalizedAngle::isNan);
84  cls.def("getAngleTo", &NormalizedAngle::getAngleTo);
85 
86  cls.def("__str__", [](NormalizedAngle const &self) {
87  return py::str("{!s}").format(self.asRadians());
88  });
89  cls.def("__repr__", [](NormalizedAngle const &self) {
90  return py::str("NormalizedAngle({!r})").format(self.asRadians());
91  });
92 
93  cls.def("__reduce__", [cls](NormalizedAngle const &self) {
94  return py::make_tuple(cls, py::make_tuple(self.asRadians()));
95  });
96 }
97 
98 } // <anonymous>
99 } // sphgeom
100 } // lsst
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
lsst::afw::table::Angle
lsst::geom::Angle Angle
Definition: misc.h:33
Vector3d.h
This file declares a class for representing vectors in ℝ³.
lsst::ip::isr::between
std::string between(std::string &s, char ldelim, char rdelim)
Definition: Isr.cc:100
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LonLat.h
This file contains a class representing spherical coordinates.
pybind11
Definition: _GenericMap.cc:40
NormalizedAngle.h
This file declares a class for representing normalized angles.
lsst::afw::cameraGeom::PYBIND11_MODULE
PYBIND11_MODULE(camera, mod)
Definition: camera.cc:133