From 534e8edc6e3d9f699ced02eaf5ade14888165750 Mon Sep 17 00:00:00 2001 From: shaurya2k06 Date: Fri, 17 Jul 2026 13:27:58 +0530 Subject: [PATCH] pybind: Wire up S2Cell.get_cap_bound() PR #646 claimed to resolve the TODO in s2cell_bindings.cc by binding S2Cell.get_cap_bound() now that S2Cap is registered before S2Cell in the module initialization order, but the actual .def() call was never added; the TODO comment and missing binding remained. Bind S2Cell::GetCapBound and update the TODO to note that only get_rect_bound() is still deferred pending S2LatLngRect bindings. Signed-off-by: shaurya2k06 --- src/python/s2cell_bindings.cc | 10 ++++++---- src/python/s2cell_test.py | 8 ++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/python/s2cell_bindings.cc b/src/python/s2cell_bindings.cc index ea9cb0c7..4431f577 100644 --- a/src/python/s2cell_bindings.cc +++ b/src/python/s2cell_bindings.cc @@ -9,6 +9,7 @@ #include "absl/hash/hash.h" #include "absl/strings/str_cat.h" #include "s2/s1chord_angle.h" +#include "s2/s2cap.h" #include "s2/s2cell.h" #include "s2/s2cell_id.h" #include "s2/s2latlng.h" @@ -190,6 +191,9 @@ void bind_s2cell(py::module& m) { "Return a list of S2CellIds whose union covers this cell.\n\n" "For a single S2Cell, this always returns a list containing\n" "just this cell's id.") + .def("get_cap_bound", &S2Cell::GetCapBound, + "Return a bounding cap for this cell.") + // get_rect_bound() is deferred until S2LatLngRect is bound. .def("contains", py::overload_cast( &S2Cell::Contains, py::const_), py::arg("cell"), @@ -245,8 +249,6 @@ void bind_s2cell(py::module& m) { .value("LEFT_EDGE", S2Cell::kLeftEdge) .export_values(); - // TODO: The following S2Cell methods are not yet bound because they depend - // on types that have not been bound yet: - // - get_cap_bound() -> S2Cap - // - get_rect_bound() -> S2LatLngRect + // TODO: get_rect_bound() is not yet bound because it depends on + // S2LatLngRect, which has not been bound yet. } diff --git a/src/python/s2cell_test.py b/src/python/s2cell_test.py index 15fed657..d293ea0f 100644 --- a/src/python/s2cell_test.py +++ b/src/python/s2cell_test.py @@ -256,6 +256,14 @@ def test_cell_union_bound(self): self.assertEqual(len(bound), 1) self.assertEqual(bound[0], cell.id) + def test_get_cap_bound(self): + cell = s2.S2Cell.from_face(0) + bound = cell.get_cap_bound() + # The bounding cap must contain the cell's center and all vertices. + self.assertTrue(bound.contains_point(cell.center())) + for k in range(4): + self.assertTrue(bound.contains_point(cell.vertex(k))) + def test_contains_cell(self): face = s2.S2Cell.from_face(0) child = s2.S2Cell(face.id.child(0))