Skip to content

pybind: Add S1Angle bindings#562

Open
deustis wants to merge 1 commit intogoogle:masterfrom
deustis:deustis/s1angle_bindings
Open

pybind: Add S1Angle bindings#562
deustis wants to merge 1 commit intogoogle:masterfrom
deustis:deustis/s1angle_bindings

Conversation

@deustis
Copy link
Copy Markdown
Contributor

@deustis deustis commented Apr 7, 2026

Add pybind11 bindings for S1Angle.

Also add S1Angle::IsNormalizedAngle() to s1angle.h for pre-validating
E5/E6/E7 conversions.

Supports downstream PRs for S2LatLng (deustis#2) and
S2CellId (deustis#3).

(Part of a series of addressing #524)

@deustis
Copy link
Copy Markdown
Contributor Author

deustis commented Apr 9, 2026

@jmr, ready for you review. Not sure why the CI is failing


// Returns true if the angle is in the normalized range (-180, 180]
// degrees, which is the valid input range for e5(), e6(), and e7().
bool IsNormalizedAngle() const;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "Angle" is implied based on the type. Why not call this IsNormalized and move it to just before the Normalized() declaration/definition?

.def("abs", &S1Angle::abs, "Return the absolute value of the angle")
.def("normalized", &S1Angle::Normalized,
"Return the angle normalized to the range (-180, 180] degrees")
.def("sin_cos", [](const S1Angle& self) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's Python. Are we really worried about this?

"Return the E7 representation (degrees * 1e7, rounded).\n\n"
"The angle must be in the normalized range (-180, 180] degrees.\n"
"Raises ValueError if out of range.")
.def("abs", &S1Angle::abs, "Return the absolute value of the angle")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support __abs__?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants