-
Notifications
You must be signed in to change notification settings - Fork 202
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 Point to Polygon and Point to LineString distance methods #61
Conversation
// final point in an odd-numbered exterior ring | ||
line_segment_distance(&self, chunk.first().unwrap(), chunk.first().unwrap()) | ||
} | ||
}; |
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.
Alternatively:
let dist = line_segment_distance(self, chunk[0], chunk.last().or(chunk[0]));
The slice returned by the chunks
iterator guarantees that element [0]
exists.
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.
Had to use unwrap_or
, but still ✨
Empty geometries are handled gracefully, and everything's documented. |
@@ -131,6 +131,12 @@ impl<T> Distance<T, Polygon<T>> for Point<T> | |||
} | |||
// minimum priority queue | |||
let mut dist_queue: BinaryHeap<Mindist<T>> = BinaryHeap::new(); | |||
// we've got interior rings | |||
if polygon.1.len() > 0 { |
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.
This outer if
isn't necessary. If it's empty, the for
loop won't iterate, which is fine.
Looks great! Awesome work @urschrei. I left a bunch of nits, but feel free to merge whenever 👍 |
These should probably be tested using a nearlyEquals functions
Given a vec of 1, 2, 3, 4 chunks(2) gives: 1, 2 3, 4 But that leaves out segment 2, 3 windows(2) gives: 1, 2 2, 3 3, 4 Which is what we want
Now that I've fixed my embarrassing |
(I have a working implementation of Polylabel ready to go, when this merges and releases) |
@aelita-mergebot r+ |
😱 Internal error: no commit found for PR |
@aelita-mergebot r+ |
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.
Thanks 🎉! |
62: deserialize point r=frewsxcv a=michaelkirk - [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md). - [n/a] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users. - > Add helper function for deserializing from WKT format into geo_types::Geometry I think the existing unreleased note pretty much covers it --- Addresses one little bit of georust/wkt#61, though leaves unanswered the bigger questions, around how to handle `GEOMETRYCOLLETION(POINT EMPTY)` etc. This might be controversial as it arguably muddies the water for addressing georust#61 more comprehensively. Please take a look at georust#61 for context. Co-authored-by: Michael Kirk <michael.code@endoftheworl.de>
64: Support 'POINT EMPTY' conversion to geo_types r=michaelkirk a=rmanoka - [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. --- closes georust#61 Co-authored-by: Rajsekar Manokaran <rajsekar@gmail.com>
This PR adds distance methods from a
Point
to:LineString
Polygon
To note:
Polygon
return0.0
Polygon
boundary return0.0
LineString
return0.0
LineString
returns0.0
Polygon
(shouldn't be possible, but we're handling it for now) returns0.0
BinaryHeap
implemented as a minimum priority queue with some floating-point-compatible comparator methods (see theOrd
andPartialOrd
impl
s onMindist
) – 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:
no handling of empty geometries yetno docs / doctests yetThis will close #59 if/when it merges.