22 #include "pybind11/pybind11.h"
38 template <
typename OtherT>
39 void declareAngleComparisonOperators(
PyAngle& cls) {
40 cls.def(
"__eq__", [](
Angle const&
self, OtherT
const& other) {
return self == other; },
42 cls.def(
"__ne__", [](
Angle const&
self, OtherT
const& other) {
return self != other; },
44 cls.def(
"__le__", [](
Angle const&
self, OtherT
const& other) {
return self <= other; },
46 cls.def(
"__ge__", [](
Angle const&
self, OtherT
const& other) {
return self >= other; },
48 cls.def(
"__lt__", [](
Angle const&
self, OtherT
const& other) {
return self < other; }, py::is_operator());
49 cls.def(
"__gt__", [](
Angle const&
self, OtherT
const& other) {
return self > other; }, py::is_operator());
54 void wrapAngle(utils::python::WrapperCollection & wrappers) {
57 [](
auto & mod,
auto & cls)
mutable {
58 cls.def(
"__eq__", [](AngleUnit const& self, AngleUnit const& other) { return self == other; },
60 cls.def(
"__ne__", [](
AngleUnit const&
self,
AngleUnit const& other) {
return !(
self == other); },
62 cls.def(
"_mul", [](
AngleUnit const&
self,
double other) {
return other *
self; },
64 cls.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);
76 PyAngle(wrappers.module,
"Angle"),
77 [](
auto & mod,
auto & cls)
mutable {
78 cls.def(py::init<double, AngleUnit>(), py::arg(
"val"), py::arg(
"units") =
radians);
79 cls.def(py::init<>());
80 declareAngleComparisonOperators<Angle>(cls);
81 declareAngleComparisonOperators<double>(cls);
82 declareAngleComparisonOperators<int>(cls);
83 cls.def(
"__mul__", [](
Angle const&
self,
double other) {
return self * other; },
85 cls.def(
"__mul__", [](
Angle const&
self,
int other) {
return self * other; },
87 cls.def(
"__rmul__", [](
Angle const&
self,
double other) {
return self * other; },
89 cls.def(
"__rmul__", [](
Angle const&
self,
int other) {
return self * other; },
91 cls.def(
"__imul__", [](
Angle&
self,
double other) {
return self *= other; });
92 cls.def(
"__imul__", [](
Angle&
self,
int other) {
return self *= other; });
93 cls.def(
"__add__", [](
Angle const&
self,
Angle const& other) {
return self + other; },
95 cls.def(
"__sub__", [](
Angle const&
self,
Angle const& other) {
return self - other; },
97 cls.def(
"__neg__", [](
Angle const&
self) {
return -
self; }, py::is_operator());
98 cls.def(
"__iadd__", [](
Angle&
self,
Angle const& other) {
return self += other; });
99 cls.def(
"__isub__", [](
Angle&
self,
Angle const& other) {
return self -= other; });
100 cls.def(
"__truediv__", [](
Angle const&
self,
double other) {
return self / other; },
103 cls.def(
"__truediv__", [](
Angle const&
self,
Angle const& other) {
104 throw py::type_error(
"unsupported operand type(s) for /: 'Angle' and 'Angle'");
106 cls.def(
"__float__", &Angle::operator
double);
109 cls.def(
"__reduce__", [cls](
Angle const&
self) {
110 return py::make_tuple(cls, py::make_tuple(py::cast(
self.asRadians())));
125 mod.def(
"isAngle", isAngle<Angle>);
126 mod.def(
"isAngle", isAngle<double>);
131 [](
auto & mod)
mutable {
132 mod.attr(
"PI") = py::float_(
PI);
133 mod.attr(
"TWOPI") = py::float_(
TWOPI);
134 mod.attr(
"HALFPI") = py::float_(
HALFPI);
136 mod.attr(
"SQRTPI") = py::float_(
SQRTPI);
137 mod.attr(
"INVSQRTPI") = py::float_(
INVSQRTPI);
138 mod.attr(
"ROOT2") = py::float_(
ROOT2);
A class representing an angle.
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asHours() const noexcept
Return an Angle's value in hours.
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
constexpr double asMilliarcseconds() const noexcept
Return an Angle's value in milliarcseconds.
constexpr double asArcseconds() const noexcept
Return an Angle's value in arcseconds.
Angle wrapNear(Angle const &refAng) const noexcept
Wrap this angle to a value x such that -π ≤ x - refAng ≤ π, approximately.
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
A class used to convert scalar POD types such as double to Angle.
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
constexpr double arcsecToRad(double x) noexcept
void wrapAngle(utils::python::WrapperCollection &wrappers)
constexpr double radToMas(double x) noexcept
constexpr double PI
The ratio of a circle's circumference to diameter.
constexpr AngleUnit arcseconds
constant with units of arcseconds
constexpr AngleUnit degrees
constant with units of degrees
constexpr double radToDeg(double x) noexcept
constexpr double masToRad(double x) noexcept
constexpr double radToArcsec(double x) noexcept
constexpr AngleUnit hours
constant with units of hours
constexpr AngleUnit milliarcseconds
constant with units of milliarcseconds
py::class_< Angle > PyAngle
constexpr double degToRad(double x) noexcept
constexpr double ONE_OVER_PI
constexpr AngleUnit radians
constant with units of radians
py::class_< AngleUnit > PyAngleUnit
constexpr AngleUnit arcminutes
constant with units of arcminutes
Angle abs(Angle const &a)
A base class for image defects.