|
1 | 1 | use geo::{Area, Coord, Intersects, LineString, Polygon};
|
2 | 2 | use geojson::FeatureCollection;
|
3 |
| -use i_float::f64_point::F64Point; |
4 | 3 | 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; |
7 | 5 |
|
8 | 6 | use crate::MapModel;
|
9 | 7 |
|
@@ -80,42 +78,35 @@ impl MapModel {
|
80 | 78 | }
|
81 | 79 |
|
82 | 80 | // TODO Revisit some of this; conversions are now in geo
|
83 |
| - |
84 | 81 | 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()); |
94 | 83 |
|
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(); |
97 | 86 |
|
| 87 | + let splitters: Vec<_> = linestrings.iter().map(to_i_overlay_contour).collect(); |
| 88 | + let shapes = shape.slice_by(&splitters, FillRule::NonZero); |
98 | 89 | shapes.into_iter().map(to_geo_polygon).collect()
|
99 | 90 | }
|
100 | 91 |
|
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 { |
106 | 93 | let mut interiors: Vec<LineString> = rings.into_iter().map(to_geo_linestring).collect();
|
107 | 94 | let exterior = interiors.remove(0);
|
108 | 95 | Polygon::new(exterior, interiors)
|
109 | 96 | }
|
110 | 97 |
|
111 |
| -fn to_geo_linestring(pts: Vec<F64Point>) -> LineString { |
| 98 | +fn to_geo_linestring(pts: Vec<[f64; 2]>) -> LineString { |
112 | 99 | LineString(
|
113 | 100 | pts.into_iter()
|
114 |
| - .map(|pt| Coord { x: pt.x, y: pt.y }) |
| 101 | + .map(|pt| Coord { x: pt[0], y: pt[1] }) |
115 | 102 | .collect(),
|
116 | 103 | )
|
117 | 104 | }
|
118 | 105 |
|
| 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 | + |
119 | 110 | fn boundary_touches_any(polygon: &Polygon, linestrings: &Vec<LineString>) -> bool {
|
120 | 111 | // TODO At least consider an rtree to prune!
|
121 | 112 | linestrings
|
|
0 commit comments