Repository navigation
Distances in metres are measured flat in a layer's own projected system (#2032 C2e-3) #2674
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
Changes from all commits
661f492
4a4732b
efefaa3
2ac72c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,10 @@ | |
| //! Between vertices, those edges cut at most 0.031% of the distance inside the circle in the | ||
| //! projection plane. A short corner can have a step approaching 5.625° when the backend rounds | ||
| //! its segment count down, cutting at most 0.125% inside, on top of the projection error. | ||
| //! | ||
| //! In a run in a projected system's own plane ([`crate::convert::Plane::Own`], #2032 C2e-3), a | ||
| //! feature is buffered there as it is, the distance measured flat in the system's unit | ||
| //! ([`crate::convert::own_length`]), as distances are in a projected system. | ||
|
|
||
| use geo::{ | ||
| BooleanOps, Buffer, Contains, Coord as GC, CoordsIter, LineString, MultiLineString, MultiPolygon, Orient, Point, Polygon, | ||
|
|
@@ -431,12 +435,18 @@ fn point(c: Coord, metres: f64) -> MultiPolygon<f64> { | |
| if !c.is_finite() { | ||
| return MultiPolygon::new(vec![]); | ||
| } | ||
| if let Some(d) = crate::convert::own_length(metres) { | ||
| return Point::new(c.x, c.y).buffer_with_style(buffer_style(d)); | ||
| } | ||
| let plane = Plane::new(c, c.x); | ||
| plane.back(&Point::new(0.0, 0.0).buffer_with_style(buffer_style(metres)), metres) | ||
| } | ||
|
|
||
| /// A line's buffer: in one projection centred on it when it fits, else in stretches. | ||
| fn lines(parts: &[Vec<Coord>], metres: f64) -> MultiPolygon<f64> { | ||
| if let Some(d) = crate::convert::own_length(metres) { | ||
| return MultiLineString::new(parts.iter().map(|p| crate::convert::ring(p)).collect()).buffer_with_style(buffer_style(d)); | ||
|
Contributor
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.
Category: quality
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. Fixed in 4a4732b: |
||
| } | ||
| let all: Vec<Coord> = parts.iter().flatten().copied().collect(); | ||
| let Some(centre) = spherical_centre(&all) else { return MultiPolygon::new(vec![]) }; | ||
| if fits(&all, centre) { | ||
|
|
@@ -451,7 +461,6 @@ fn lines(parts: &[Vec<Coord>], metres: f64) -> MultiPolygon<f64> { | |
| /// outline's buffer (in stretches) added or, inward, taken away. | ||
| fn polygons(polys: &[Vec<Vec<Coord>>], metres: f64) -> MultiPolygon<f64> { | ||
| let all: Vec<Coord> = polys.iter().flatten().flatten().copied().collect(); | ||
| let Some(centre) = spherical_centre(&all) else { return MultiPolygon::new(vec![]) }; | ||
| let shape = |ring: &dyn Fn(&[Coord]) -> LineString<f64>| { | ||
| MultiPolygon::new( | ||
| polys | ||
|
|
@@ -464,6 +473,10 @@ fn polygons(polys: &[Vec<Vec<Coord>>], metres: f64) -> MultiPolygon<f64> { | |
| .collect(), | ||
| ) | ||
| }; | ||
| if let Some(d) = crate::convert::own_length(metres) { | ||
| return shape(&|r| crate::convert::ring(r)).buffer_with_style(buffer_style(d)); | ||
| } | ||
| let Some(centre) = spherical_centre(&all) else { return MultiPolygon::new(vec![]) }; | ||
| if fits(&all, centre) { | ||
| let plane = Plane::new(centre, all.first().map_or(centre.x, |c| c.x)); | ||
| return plane.back(&shape(&|r| plane.line(r)).buffer_with_style(buffer_style(metres)), metres); | ||
|
|
||
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.
The own-plane branches of
point,linesandpolygonshand coordinates straight togeo's buffer with no bound. The lon/lat path folds and clamps first, and Simplify refuses coordinates past 1e150. The PR says a run that fails is caught byanalysis::run, but a caught panic still counts as a crash under the Never-crash rule. I could not confirm whethergeopanics or returns garbage for coordinates near or above 1e150 in a feet or km system, so this is unverified. No test inheld_layers.rsuses absurd projected coordinates:distance_tools_take_junk_in_the_held_systemcovers only NaN and a normal UTM place. Suggest either refusing such coordinates with a notice, as Simplify does, or adding a hostile-coordinate test on these paths.Category: bug