Skip to content

pybind: Add S1Angle bindings - #562

Merged
jmr merged 5 commits into
google:masterfrom
deustis:deustis/s1angle_bindings
Apr 24, 2026
Merged

jmr merged 5 commits into
google:masterfrom
deustis:deustis/s1angle_bindings

Conversation

@deustis

@deustis deustis commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

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

deustis commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

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

Comment thread src/s2/s1angle.h Outdated
Comment thread src/python/s1angle_bindings.cc Outdated
Comment thread src/python/s1angle_bindings.cc Outdated
@deustis
deustis requested a review from jmr April 10, 2026 15:33
@deustis

deustis commented Apr 15, 2026

Copy link
Copy Markdown
Contributor Author

@jmr, I believe I've addressed your comments!

@jmr jmr left a comment

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.

Sorry, I noticed a few more things.

Comment thread src/python/s1angle_test.py Outdated

def test_repr(self):
a = s2.S1Angle.from_degrees(45.0)
self.assertEqual(repr(a), "S1Angle(45.0000000)")

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.

hmm. add assertEqual(a, S1Angle(45.0000000)) here. I don't think we have a float constructor. Use from_degrees and ideally control the number of trailing 0s.

@deustis deustis Apr 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not quite sure if this addresses your comment, but added test variations that show the input precision doesn't affect the output precision (since that's controlled by the C++ implementation)

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 we shouldn't be using the C++ operator here, but let's not block this PR any longer.

#578

Comment thread src/python/s1angle_test.py Outdated
Comment thread src/python/s1angle_bindings.cc
Comment thread src/python/module.cc
Comment thread src/python/s1angle_bindings.cc Outdated
Comment thread src/python/s1angle_bindings.cc
@jmr

jmr commented Apr 17, 2026

Copy link
Copy Markdown
Member

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

GH now supports stacked PRs. I'm not sure how well they work, or if they would be helpful in this case.

Comment thread src/python/s1angle_test.py Outdated
@deustis

deustis commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

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

GH now supports stacked PRs. I'm not sure how well they work, or if they would be helpful in this case.

Thanks... we'll just take these one at a time

- Make radians/degrees/e5/e6/e7 properties instead of methods
- Expose IsNormalized() and Normalize()
- Replace std::to_string with absl::StrCat (locale safety)
- Move sin/cos/tan from module-level functions to instance methods
- Organize module.cc into dependency tranches with comments
- Update README property rule
@deustis
deustis force-pushed the deustis/s1angle_bindings branch from 77385b2 to 34c27c7 Compare April 21, 2026 16:27
@deustis

deustis commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

@jmr, PTAL!

# Conflicts:
#	src/python/s1interval_bindings.cc
Comment thread src/python/s1interval_bindings.cc Outdated

@jmr jmr left a comment

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.

Good except for the extra #include.

@jmr
jmr merged commit ed696c0 into google:master Apr 24, 2026
13 checks passed
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