Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bindings (top-level "ufuncs") for predicates, measurement, etc. #17

Open
5 of 11 tasks
benbovy opened this issue Mar 8, 2023 · 0 comments
Open
5 of 11 tasks
Labels
good first issue Good for newcomers

Comments

@benbovy
Copy link
Owner

benbovy commented Mar 8, 2023

Some features available in s2geography that could be implemented in spherely with relatively little effort (i.e., straightforward functions returning simple types like bool, float, etc.):

Predicates:

Measurement:

One example with intersects

s2geography API:

https://github.com/paleolimbot/s2geography/blob/764682d60f757383e5853a45a12404c84f3e5961/src/s2geography/predicates.h#L10-L12

spherely bindings:

m.def("intersects",
py::vectorize(Predicate(s2geog::s2_intersects)),
py::arg("a"),
py::arg("b"),
R"pbdoc(
Returns True if A and B share any portion of space.
Intersects implies that overlaps, touches and within are True.
Parameters
----------
a, b : :py:class:`Geography` or array_like
Geography object(s)
)pbdoc");

For predicates that are not directly implemented in s2geography but that can be easily derived from another predicate, it is possible to use a lambda, like for within:

m.def("within",
py::vectorize(Predicate([](const s2geog::ShapeIndexGeography& a_index,
const s2geog::ShapeIndexGeography& b_index,
const S2BooleanOperation::Options& options) {
return s2geog::s2_contains(b_index, a_index, options);
})),
py::arg("a"),
py::arg("b"),
R"pbdoc(
Returns True if A is completely inside B.
Parameters
----------
a, b : :py:class:`Geography` or array_like
Geography object(s)
)pbdoc");

Documentation:

https://github.com/benbovy/spherely/blob/main/docs/api.rst#predicates

Typing annotations:

intersects: _VFunc_Nin2_Nout1[Literal["intersects"], bool, bool]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant