-
-
Notifications
You must be signed in to change notification settings - Fork 7
update geo #185
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
update geo #185
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| use anyhow::Result; | ||
| use geo::{Euclidean, Length, Line, LineInterpolatePoint, Point, Polygon}; | ||
| use geo::line_measures::InterpolatableLine; | ||
| use geo::{Euclidean, Line, Point, Polygon}; | ||
| use geojson::GeoJson; | ||
| use itertools::Itertools; | ||
|
|
||
|
|
@@ -211,20 +212,15 @@ impl Road { | |
| /// Returns a point on the road this far away from the intersection. If the road is too short, | ||
| /// clamps at the other end of the road. | ||
| fn pt_from_intersection(&self, meters_away: f64, i: IntersectionID) -> Point { | ||
| let len = Euclidean.length(&self.linestring); | ||
|
|
||
| if len > meters_away { | ||
| let pct = if self.src_i == i { | ||
| meters_away / len | ||
| } else { | ||
| 1.0 - (meters_away / len) | ||
| }; | ||
| return self.linestring.line_interpolate_point(pct).unwrap(); | ||
| if self.src_i == i { | ||
| self.linestring | ||
| .point_at_distance_from_start(&Euclidean, meters_away) | ||
| .unwrap() | ||
| } else { | ||
| self.linestring | ||
| .point_at_distance_from_end(&Euclidean, meters_away) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a good use of the new api - we're using Note that this method already clamps the output to the linestring. |
||
| .unwrap() | ||
| } | ||
|
|
||
| // If not, just take the other endpoint | ||
| let pct = if self.src_i == i { 1.0 } else { 0.0 }; | ||
| self.linestring.line_interpolate_point(pct).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.
This is the new api from georust/geo#1321 - it's more explicit about metric space, and also has some new APIs which you can see further down.