-
Notifications
You must be signed in to change notification settings - Fork 199
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
Implement RTreeObject for Geometry enum #984
base: main
Are you sure you want to change the base?
Conversation
It makes me (only a little) itchy that we now have a separate, mostly equivalent, implementation of bounding_rect for geometry in geo and now in geo_types for the RTree integration. I had a quick go at seeing what it'd look like to share a backing implementation here, based on your branch: https://github.com/georust/geo/tree/mkirk/rtreeobject On the one hand, that approach is not a small endeavor. On the other hand, it's nice to dedupe the implementations and also, IMO solves at least the majority of the need for new tests since the existing bounding_rect has decent testing. It's not clear to me which is better, so if you prefer to have the duplicated implementation, I'm on board. |
Whoops, I left comments on the commit rather than in the PR. Let me know if you want me to recreate them: 93dce71 |
I vastly prefer the shared version, so that's incorporated now. In terms of tests, I want to make sure we're testing
1 is probably a bit trickier. |
type Envelope = ::$rstar::AABB<Point<T>>; | ||
|
||
fn envelope(&self) -> Self::Envelope { | ||
let bounding_rect = self.iter().fold( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now that we have the BoundingRect
trait in geo-types, I was thinking that the impl for Geometry
and all enum members (including GeometryCollection here) could be something like:
fn envelope(&self) -> Self::Envelope {
self.bounding_rect()
.map(|geo_rect| geo_rect_to_rstar_aabb(geo_rect))
.unwrap_or(|| Envelope::new_empty())
}
And for the types whose bounding_rect is not-optional (like point, line, triangle, rect):
fn envelope(&self) -> Self::Envelope {
geo_rect_to_rstar_aabb(self.bounding_rect())
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get as far as testing whether it would work out though 😬
I have just realised that we also need to impl |
Are you sure we need to implement PointDistance for everything? I'm AFK so can't easily verify, but I seem to recall we could get some useful functionality with only the RTreeObject impl. Like maybe we could get "intersection candidates", but not "nearest neighbor", which still seems like useful progress. |
It certainly works, but everything other than the envelope-based queries require |
Let me know if I can help contribute to this PR as it would be very helpful. |
Given #1029 it can be quite simple to implement impl PointDistance for Geometry {
fn distance_2(
&self,
point: &<Self::Envelope as rstar::Envelope>::Point,
) -> <<Self::Envelope as rstar::Envelope>::Point as rstar::Point>::Scalar {
let pnt = geo_types::point!(geo_types::coord!{x: point[0], y: point[1]});
let d = &self.geom.euclidean_distance(&pnt);
d.powi(2)
}
} |
This avoids duplicating its functionality, as it's required in order to make all geometry types and the Geometry enum RStar compatible
Also tidy up rstar::Point impl for geo_types::Point
9366b58
to
607a6dd
Compare
It's been a long time, but the problem with this approach is that |
@urschrei thanks for explaining! Perhaps, it could be feature gated in geo_types? |
It's not a feature issue, it's a circular dependency issue: there are no algorithms in |
Fixes #982
Still draft as I haven't written any tests yet.
CHANGES.md
if knowledge of this change could be valuable to users.