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());
57 [](
auto & mod,
auto &
cls)
mutable {
58 cls.def(
"__eq__", [](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; },
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; });
97 cls.def(
"__neg__", [](
Angle const&
self) {
return -
self; }, py::is_operator());
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);
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);
constexpr double asAngularUnits(AngleUnit const &units) const noexcept
Return an Angle's value in the specified units.
AngleUnit constexpr arcminutes
constant with units of arcminutes
Angle abs(Angle const &a)
void wrapAngle(utils::python::WrapperCollection &wrappers)
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
constexpr double asRadians() const noexcept
Return an Angle's value in radians.
constexpr double asDegrees() const noexcept
Return an Angle's value in degrees.
AngleUnit constexpr hours
constant with units of hours
constexpr double radToDeg(double x) noexcept
Angle separation(Angle const &other) const noexcept
The signed difference between two Angles.
ItemVariant const * other
AngleUnit constexpr radians
constant with units of radians
A class representing an angle.
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double radToArcsec(double x) noexcept
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
double constexpr ONE_OVER_PI
py::class_< Angle > PyAngle
AngleUnit constexpr degrees
constant with units of degrees
A base class for image defects.
constexpr double asHours() const noexcept
Return an Angle's value in hours.
AngleUnit constexpr arcseconds
constant with units of arcseconds
constexpr double degToRad(double x) noexcept
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.
constexpr double asMilliarcseconds() const noexcept
Return an Angle's value in milliarcseconds.
constexpr double radToMas(double x) noexcept
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
py::class_< AngleUnit > PyAngleUnit
Angle wrap() const noexcept
Wrap this angle to the range [0, 2π).
AngleUnit constexpr milliarcseconds
constant with units of milliarcseconds
constexpr double masToRad(double x) noexcept
constexpr double arcsecToRad(double x) noexcept
A helper class for subdividing pybind11 module across multiple translation units (i.e.
double constexpr PI
The ratio of a circle's circumference to diameter.
A class used to convert scalar POD types such as double to Angle.
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...