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

How best to calculate Point to Polygon distance? #59

Closed
urschrei opened this issue Aug 17, 2016 · 2 comments · Fixed by #61
Closed

How best to calculate Point to Polygon distance? #59

urschrei opened this issue Aug 17, 2016 · 2 comments · Fixed by #61

Comments

@urschrei
Copy link
Member

I'm working on an algorithm that requires calculating the minimum signed distance from a Point to a Polygon exterior (negative implies that the point lies inside the Polygon / polygon.contains(point) is true).
I can't see a good way to do this, currently – I've implemented point-line-distance in simplify, but that's for segments, and there's currently no way to get Polygon exterior ring segments. Or is there? If anyone can think of an approach here, or point to an existing implementation I'd be very grateful (and I'll implement it ASAP)

@frewsxcv
Copy link
Member

currently – I've implemented point-line-distance in simplify

This is a tangential thought, but maybe we could move this point-line-distance implementation into the Distance trait? e.g. impl<T> Distance<T, LineString<T>> for Point<T> where T: Float

there's currently no way to get Polygon exterior ring segments

Can't you get the exterior ring segments from the first value in a Polygon? (see #60). Or maybe I'm misreading something here.

@urschrei
Copy link
Member Author

Hmm I think you're right. RE moving pld to Distance, I'll have a look at that this week.

ghost pushed a commit that referenced this issue Aug 25, 2016
Merge #61 a=@urschrei r=@frewsxcv
________________________________________________________________________

This PR adds distance methods from a `Point` to:
- a `LineString`
- a `Polygon`

To note:
- Points **inside a `Polygon`** return `0.0`
- Points on a **`Polygon` boundary** return `0.0`
- Points **on a `LineString`** return `0.0`
- distance to an **empty `LineString`** returns `0.0`
- distance to an **empty `Polygon`** (shouldn't be possible, but we're handling it for now) returns `0.0`
- I'm using a [`BinaryHeap`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html) implemented as a minimum priority queue with some floating-point-compatible comparator methods (see the `Ord` and `PartialOrd` `impl`s on `Mindist`) – I just adapted the linked example to use partial ordering. Please chime in if this is Bad, or if you can think of a better design.

Also WIP because:
- <s>no handling of empty geometries yet</s>
- <s>no docs / doctests yet</s>

This will close #59 if/when it merges.
@ghost ghost closed this as completed in #61 Aug 25, 2016
nyurik pushed a commit to nyurik/geo that referenced this issue Mar 19, 2022
59: impl serde::Deserialize for Wkt and Geometry (and helper function) r=michaelkirk a=woshilapin

- [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md).
- [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users.
---



Co-authored-by: Jean SIMARD <woshilapin@tuziwo.info>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants