22 #include "pybind11/pybind11.h" 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());
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);
75 PyAngle clsAngle(mod,
"Angle");
77 clsAngle.def(py::init<double, AngleUnit>(), py::arg(
"val"), py::arg(
"units") =
radians);
78 clsAngle.def(py::init<>());
80 declareAngleComparisonOperators<Angle>(clsAngle);
81 declareAngleComparisonOperators<double>(clsAngle);
82 declareAngleComparisonOperators<int>(clsAngle);
84 clsAngle.def(
"__mul__", [](
Angle const&
self,
double other) {
return self *
other; }, py::is_operator());
85 clsAngle.def(
"__mul__", [](
Angle const&
self,
int other) {
return self *
other; }, py::is_operator());
86 clsAngle.def(
"__rmul__", [](
Angle const&
self,
double other) {
return self *
other; }, py::is_operator());
87 clsAngle.def(
"__rmul__", [](
Angle const&
self,
int other) {
return self *
other; }, py::is_operator());
88 clsAngle.def(
"__imul__", [](
Angle&
self,
double other) {
return self *=
other; });
89 clsAngle.def(
"__imul__", [](
Angle&
self,
int other) {
return self *=
other; });
90 clsAngle.def(
"__add__", [](
Angle const&
self,
Angle const& other) {
return self +
other; },
92 clsAngle.def(
"__sub__", [](
Angle const&
self,
Angle const& other) {
return self -
other; },
94 clsAngle.def(
"__neg__", [](
Angle const&
self) {
return -
self; }, py::is_operator());
95 clsAngle.def(
"__iadd__", [](
Angle&
self,
Angle const& other) {
return self +=
other; });
96 clsAngle.def(
"__isub__", [](
Angle&
self,
Angle const& other) {
return self -=
other; });
97 clsAngle.def(
"__truediv__", [](
Angle const&
self,
double other) {
return self /
other; },
100 clsAngle.def(
"__truediv__", [](
Angle const&
self,
Angle const& other) {
101 throw py::type_error(
"unsupported operand type(s) for /: 'Angle' and 'Angle'");
104 clsAngle.def(
"__float__", &Angle::operator
double);
105 clsAngle.def(
"__abs__", [](
Angle const&
self) {
return std::abs(
self.asRadians()) *
radians; });
107 clsAngle.def(
"__reduce__", [clsAngle](
Angle const&
self) {
108 return py::make_tuple(clsAngle, py::make_tuple(py::cast(
self.asRadians())));
128 mod.attr(
"PI") = py::float_(
PI);
129 mod.attr(
"TWOPI") = py::float_(
TWOPI);
130 mod.attr(
"HALFPI") = py::float_(
HALFPI);
132 mod.attr(
"SQRTPI") = py::float_(
SQRTPI);
133 mod.attr(
"INVSQRTPI") = py::float_(
INVSQRTPI);
134 mod.attr(
"ROOT2") = py::float_(
ROOT2);
142 mod.def(
"isAngle", isAngle<Angle>);
143 mod.def(
"isAngle", isAngle<double>);
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 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.
AngleUnit constexpr radians
constant with units of radians
Angle wrapCtr() const noexcept
Wrap this angle to the range [-π, π).
constexpr double radToArcsec(double x) noexcept
double constexpr ONE_OVER_PI
PYBIND11_PLUGIN(cameraSys)
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
ItemVariant const * other
constexpr double asArcminutes() const noexcept
Return an Angle's value in arcminutes.
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
double constexpr PI
The ratio of a circle's circumference to diameter.