-
Notifications
You must be signed in to change notification settings - Fork 10
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
within #19
Comments
@mapsam - Absolutely ^ , using boost::geometry::within is a good plan for now. Just be aware that |
@artemp thanks for noting that closet_point uses boost::geometry::within internally - seeing that it sets the distance to |
@mapsam that feels like a good solution to me. One thing I noticed about the spatial-algorithms/include/mapbox/geometry/algorithms/closest_point_impl.hpp Lines 64 to 86 in 5dfca06
spatial-algorithms/include/mapbox/geometry/algorithms/closest_point_impl.hpp Lines 33 to 56 in 5dfca06
cpinfo.distance == 0.0 if the query point is within any one part of a multipolygon and it will check all polygon parts before returning. Does this seem like the correct behavior for your use case? One performance issue I see is that if the first part of a multipolygon is directly hit (cpinfo.distance == 0.0), we still process the others, which is unlikely needed.
|
@springmeyer looks like you're reading that correctly to me. I wonder if closest_point_impl can break out of the loop if it gets a hit? Although, this means it wouldn't take into account any overlapping geometries in a multipolygon (is that allowed?). |
Yes, that could work - @artemp thoughts? Something like this perhaps? diff --git a/include/mapbox/geometry/algorithms/closest_point_impl.hpp b/include/mapbox/geometry/algorithms/closest_point_impl.hpp
index 2103c77..94411cb 100644
--- a/include/mapbox/geometry/algorithms/closest_point_impl.hpp
+++ b/include/mapbox/geometry/algorithms/closest_point_impl.hpp
@@ -72,6 +72,10 @@ struct closest_point
{
first = false;
result = std::move(operator()(geom));
+ // early return if exact hit
+ if (result.distance == 0.0) {
+ return result;
+ }
}
else
{ Note: probably need to use an epsilon since comparing floating point numbers is not ideal.
From a generic From a vector tile perspective overlapping geometries would be invalid, so I don't think this would need supported (and breaking early would be fine). |
Yep, great catch! Because we're assuming that geometries are valid and simple in OGC sense - ^ early return is totally justified. /cc @mapsam @springmeyer |
the same applies to |
…iPolygon and LineString forming MultiLineString can not intersect (only touch) we can return early in case point within Polygon/LineString (#19)
@springmeyer - |
@artemp I'm wondering if I can use intersection.hpp to perform a "within"-esque operation?I'd like to basically get a boolean response if two geometries intersect - in my case a point-in-polygon operation "is this point within this polygon?"
Looks like boost has a within function - perhaps I'll use this for now?
refs: mapbox/vtquery#36
The text was updated successfully, but these errors were encountered: