23 #include "pybind11/pybind11.h"
27 namespace py = pybind11;
34 using PyAngle = py::class_<Angle>;
35 using PyAngleUnit = py::class_<AngleUnit>;
37 template <
typename OtherT>
38 void declareAngleComparisonOperators(PyAngle&
cls) {
39 cls.def(
"__eq__", [](
Angle const&
self, OtherT
const& other) {
return self == other; },
41 cls.def(
"__ne__", [](
Angle const&
self, OtherT
const& other) {
return self != other; },
43 cls.def(
"__le__", [](
Angle const&
self, OtherT
const& other) {
return self <= other; },
45 cls.def(
"__ge__", [](
Angle const&
self, OtherT
const& other) {
return self >= other; },
47 cls.def(
"__lt__", [](
Angle const&
self, OtherT
const& other) {
return self < other; }, py::is_operator());
48 cls.def(
"__gt__", [](
Angle const&
self, OtherT
const& other) {
return self > other; }, py::is_operator());
52 py::module mod(
"angle");
56 PyAngleUnit clsAngleUnit(mod,
"AngleUnit");
58 clsAngleUnit.def(
"__eq__", [](AngleUnit
const&
self, AngleUnit
const& other) {
return self == other; },
60 clsAngleUnit.def(
"__ne__", [](AngleUnit
const&
self, AngleUnit
const& other) {
return !(
self == other); },
62 clsAngleUnit.def(
"_mul", [](AngleUnit
const&
self,
double other) {
return other *
self; },
64 clsAngleUnit.def(
"_rmul", [](AngleUnit
const&
self,
double other) {
return other *
self; },
66 mod.attr(
"radians") = py::cast(
radians);
67 mod.attr(
"degrees") = py::cast(
degrees);
68 mod.attr(
"hours") = py::cast(
hours);
74 PyAngle clsAngle(mod,
"Angle");
76 clsAngle.def(py::init<double, AngleUnit>(), py::arg(
"val"), py::arg(
"units") =
radians);
77 clsAngle.def(py::init<>());
79 declareAngleComparisonOperators<Angle>(clsAngle);
80 declareAngleComparisonOperators<double>(clsAngle);
81 declareAngleComparisonOperators<int>(clsAngle);
83 clsAngle.def(
"__mul__", [](
Angle const&
self,
double other) {
return self * other; }, py::is_operator());
84 clsAngle.def(
"__mul__", [](
Angle const&
self,
int other) {
return self * other; }, py::is_operator());
85 clsAngle.def(
"__rmul__", [](
Angle const&
self,
double other) {
return self * other; }, py::is_operator());
86 clsAngle.def(
"__rmul__", [](
Angle const&
self,
int other) {
return self * other; }, py::is_operator());
87 clsAngle.def(
"__imul__", [](
Angle&
self,
double other) {
return self *= other; });
88 clsAngle.def(
"__imul__", [](
Angle&
self,
int other) {
return self *= other; });
89 clsAngle.def(
"__add__", [](
Angle const&
self,
Angle const& other) {
return self + other; },
91 clsAngle.def(
"__sub__", [](
Angle const&
self,
Angle const& other) {
return self - other; },
93 clsAngle.def(
"__neg__", [](
Angle const&
self) {
return -
self; }, py::is_operator());
94 clsAngle.def(
"__iadd__", [](
Angle&
self,
Angle const& other) {
return self += other; });
95 clsAngle.def(
"__isub__", [](
Angle&
self,
Angle const& other) {
return self -= other; });
96 clsAngle.def(
"__truediv__", [](
Angle const&
self,
double other) {
return self / other; },
99 clsAngle.def(
"__truediv__", [](
Angle const&
self,
Angle const& other) {
100 throw py::type_error(
"unsupported operand type(s) for /: 'Angle' and 'Angle'");
103 clsAngle.def(
"__float__", &Angle::operator
double);
104 clsAngle.def(
"__abs__", [](
Angle const&
self) {
return std::abs(
self.asRadians()) *
radians; });
106 clsAngle.def(
"__reduce__", [clsAngle](
Angle const&
self) {
107 return py::make_tuple(clsAngle, py::make_tuple(py::cast(
self.asRadians())));
110 auto streamStr = [](
Angle const&
self) {
111 std::stringstream buffer;
115 clsAngle.def(
"__str__", streamStr);
116 clsAngle.def(
"__repr__", streamStr);
131 mod.attr(
"PI") = py::float_(
PI);
132 mod.attr(
"TWOPI") = py::float_(
TWOPI);
133 mod.attr(
"HALFPI") = py::float_(
HALFPI);
135 mod.attr(
"SQRTPI") = py::float_(
SQRTPI);
136 mod.attr(
"INVSQRTPI") = py::float_(
INVSQRTPI);
137 mod.attr(
"ROOT2") = py::float_(
ROOT2);
145 mod.def(
"isAngle", isAngle<Angle>);
146 mod.def(
"isAngle", isAngle<double>);
AngleUnit constexpr arcminutes
constant with units of arcminutes
lsst::afw::geom::Angle Angle
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
constexpr double masToRad(double x) noexcept
AngleUnit constexpr radians
constant with units of radians
AngleUnit constexpr degrees
constant with units of degrees
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
double constexpr ONE_OVER_PI
double constexpr PI
The ratio of a circle's circumference to diameter.
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
AngleUnit constexpr hours
constant with units of hours
constexpr double degToRad(double x) noexcept
AngleUnit constexpr arcseconds
constant with units of arcseconds
constexpr double radToArcsec(double x) noexcept
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double radToDeg(double x) noexcept
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
constexpr double arcsecToRad(double x) noexcept
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
constexpr double radToMas(double x) noexcept
constexpr double asHours() const noexcept
Return an Angle's value in hours.