Skip to content

pybind: Add S1ChordAngle bindings#5

Closed
deustis wants to merge 3 commits into
masterfrom
deustis/s1chord_angle_bindings
Closed

pybind: Add S1ChordAngle bindings#5
deustis wants to merge 3 commits into
masterfrom
deustis/s1chord_angle_bindings

Conversation

@deustis
Copy link
Copy Markdown
Owner

@deustis deustis commented May 7, 2026

Summary

  • Adds pybind11 bindings for S1ChordAngle: default / two-point / S1Angle constructors, factory methods (from_radians, from_degrees, from_e5/6/7, fast_upper_bound_from, from_length2, zero, right, straight, infinity, negative), properties (length2, radians, degrees, e5/6/7), predicates (is_zero, is_negative, is_infinity, is_special, is_valid), geometric ops (to_angle, sin/cos/tan, sin2, successor, predecessor, plus_error, s2_point_constructor_max_error, s1_angle_constructor_max_error).
  • Operators: ==, !=, <, >, <=, >=, +, -, +=, -=, __hash__, __repr__, __str__. Arithmetic pre-validates that neither operand is Negative() or Infinity(), matching the C++ !is_special() precondition.
  • Two-point constructor rejects non-unit-length inputs with ValueError (in C++ this is an ABSL_DCHECK; the pybind convention is to surface preconditions as exceptions).
  • 46 unit tests.

Unblocks

Once this lands, the distance methods on S2Cell that were deferred in #4 (PR google#593 stack) can be filled in as a follow-up: get_distance(point), get_distance(a, b), get_distance(cell), get_boundary_distance, get_max_distance(*), is_distance_less*, is_max_distance_less*.

Stack

Stacked on deustis/s2cell_bindings (draft PR #4), which is stacked on deustis/s2cell_id_bindings (upstream PR google#593).

Test plan

  • bazel test //python/... — all 10 suites pass (46 new S1ChordAngle tests, existing suites still green).

@deustis deustis force-pushed the deustis/s2cell_bindings branch 3 times, most recently from a9a433c to 1fc4db2 Compare May 12, 2026 22:52
Binds S1ChordAngle with constructors, factory methods (from_radians,
from_degrees, from_e5/6/7, fast_upper_bound_from, from_length2, zero,
right, straight, infinity, negative), properties (length2, radians,
degrees, e5/6/7), predicates (is_zero, is_negative, is_infinity,
is_special, is_valid), geometric ops (to_angle, sin/cos/tan, sin2,
successor, predecessor, plus_error, error bounds), arithmetic
(+, -, +=, -=) with pre-validation that rejects Negative()/Infinity()
operands, comparisons, hash, and __repr__/__str__.

Unblocks the deferred distance methods on S2Cell (GetDistance,
GetMaxDistance, IsDistanceLess, etc.) which can be added in a follow-up.

Stacked on deustis/s2cell_bindings.
@deustis deustis force-pushed the deustis/s1chord_angle_bindings branch from 9fbf526 to 7f453b3 Compare May 13, 2026 03:11
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc
Comment thread src/python/s1chord_angle_bindings.cc Outdated
Comment thread src/python/s1chord_angle_bindings.cc
Comment thread src/python/s1chord_angle_bindings.cc Outdated
@deustis deustis changed the base branch from deustis/s2cell_bindings to master May 13, 2026 03:53
- Use S2::IsUnitLength for unit-length validation, matching the C++
  DCHECK exactly; add s2pointutil.h include
- Drop fast_upper_bound_from, from_length2, from_e5/e6/e7 factory methods
- Drop length2 property, sin2, successor, predecessor, plus_error,
  and error-bound accessor bindings
- Update tests accordingly, replacing length2 assertions with
  radians/degrees/comparisons
Comment thread src/python/s1chord_angle_test.py Outdated
- Guard sin/cos/tan against special values (negative/infinity) to
  prevent DCHECK in C++; add test_sin_cos_tan_special_raises
- Guard e5/e6/e7 properties against special values; negative() would
  silently return a meaningless integer without this guard; add
  test_e5_e6_e7_special_raises
- Rename MaybeThrowSpecialForArithmetic -> MaybeThrowIfSpecial
- Update error messages to use Python-style lowercase names (negative(),
  infinity())
- Switch __hash__ from std::hash<double> to absl::Hash<double>; add
  absl/hash BUILD dep
- Fix test_str and test_repr to assert exact values
- Fix test_constructor_from_antipodal_points to use assertEqual(straight())
- Add test_to_angle_special_values and test_str_negative_sentinel
@deustis deustis closed this May 13, 2026
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.

1 participant