Skip to content

Commit dc42679

Browse files
michaelkirkdabreegster
authored andcommitted
Update i_overlay to match geo.
Note: this "minor" version bump of i_overlay introduces breaking changes. The i_overlay maintainer intentionally does not follow semver, so I've pegged the versions more conservatively, ensuring we only update explicitly.
1 parent f3b8c91 commit dc42679

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

backend/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ contour = "0.12.0"
1515
fast_paths = "1.0.0"
1616
geo = "0.29.1"
1717
geojson = { git = "https://github.com/georust/geojson", features = ["geo-types"] }
18-
i_overlay = { version = "1.7.4", default-features = false }
18+
# Note: i_overlay doesn't follow semver, and only guarantees non-breaking across patch versions.
19+
# https://github.com/iShape-Rust/iOverlay?tab=readme-ov-file#versioning-policy
20+
# So we pin to a minor version.
21+
i_overlay = { version = ">=1.9.4,<1.10.0", default-features = false }
1922
i_float = "1.3.1"
2023
log = "0.4.20"
2124
osm-reader = { git = "https://github.com/a-b-street/osm-reader" }

backend/src/auto_boundaries.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use geo::{Area, Coord, Intersects, LineString, Polygon};
22
use geojson::FeatureCollection;
3-
use i_float::f64_point::F64Point;
43
use i_overlay::core::fill_rule::FillRule;
5-
use i_overlay::f64::string::F64StringOverlay;
6-
use i_overlay::string::rule::StringRule;
4+
use i_overlay::float::slice::FloatSlice;
75

86
use crate::MapModel;
97

@@ -80,42 +78,35 @@ impl MapModel {
8078
}
8179

8280
// TODO Revisit some of this; conversions are now in geo
83-
8481
fn split_polygon(polygon: Polygon, linestrings: Vec<LineString>) -> Vec<Polygon> {
85-
let mut overlay = F64StringOverlay::new();
86-
overlay.add_shape_path(polygon.exterior().coords().map(to_pt).collect());
87-
for ls in linestrings {
88-
overlay.add_string_lines(
89-
ls.lines()
90-
.map(|l| [to_pt(&l.start), to_pt(&l.end)])
91-
.collect(),
92-
);
93-
}
82+
let mut shape = to_i_overlay_contour(polygon.exterior());
9483

95-
let graph = overlay.into_graph(FillRule::NonZero);
96-
let shapes = graph.extract_shapes(StringRule::Slice);
84+
// geo Polygon's are explicitly closed LineStrings, but i_overlay Polygon's are not.
85+
shape.pop();
9786

87+
let splitters: Vec<_> = linestrings.iter().map(to_i_overlay_contour).collect();
88+
let shapes = shape.slice_by(&splitters, FillRule::NonZero);
9889
shapes.into_iter().map(to_geo_polygon).collect()
9990
}
10091

101-
fn to_pt(pt: &Coord) -> F64Point {
102-
F64Point::new(pt.x, pt.y)
103-
}
104-
105-
fn to_geo_polygon(rings: Vec<Vec<F64Point>>) -> Polygon {
92+
fn to_geo_polygon(rings: Vec<Vec<[f64; 2]>>) -> Polygon {
10693
let mut interiors: Vec<LineString> = rings.into_iter().map(to_geo_linestring).collect();
10794
let exterior = interiors.remove(0);
10895
Polygon::new(exterior, interiors)
10996
}
11097

111-
fn to_geo_linestring(pts: Vec<F64Point>) -> LineString {
98+
fn to_geo_linestring(pts: Vec<[f64; 2]>) -> LineString {
11299
LineString(
113100
pts.into_iter()
114-
.map(|pt| Coord { x: pt.x, y: pt.y })
101+
.map(|pt| Coord { x: pt[0], y: pt[1] })
115102
.collect(),
116103
)
117104
}
118105

106+
fn to_i_overlay_contour(line_string: &LineString) -> Vec<[f64; 2]> {
107+
line_string.coords().map(|c| [c.x, c.y]).collect()
108+
}
109+
119110
fn boundary_touches_any(polygon: &Polygon, linestrings: &Vec<LineString>) -> bool {
120111
// TODO At least consider an rtree to prune!
121112
linestrings

0 commit comments

Comments
 (0)