Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/python/s2cell_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<const S2Cell&>(
&S2Cell::Contains, py::const_),
py::arg("cell"),
Expand Down Expand Up @@ -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.
}
8 changes: 8 additions & 0 deletions src/python/s2cell_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down