|
1 | 1 | use std::collections::{HashSet, VecDeque};
|
2 | 2 |
|
3 |
| -use geo::{BoundingRect, Coord, Densify, LineString, MultiPolygon, Rect}; |
| 3 | +use geo::{BooleanOps, BoundingRect, Coord, Densify, LineString, MultiPolygon, Rect}; |
4 | 4 |
|
5 | 5 | use crate::{Cell, MapModel, Neighbourhood};
|
6 | 6 |
|
@@ -44,9 +44,7 @@ impl RenderCells {
|
44 | 44 | if let Some(slice) =
|
45 | 45 | slice_linestring(&road.linestring, interval.start, interval.end)
|
46 | 46 | {
|
47 |
| - // Walk along the center line. We could look at the road's thickness and fill |
48 |
| - // out points based on that, but the diffusion should take care of it. |
49 |
| - // TODO Clean up old comments like this |
| 47 | + // Walk along the center line |
50 | 48 | for pt in slice.densify(RESOLUTION_M / 2.0).0 {
|
51 | 49 | let grid_idx = grid.idx(
|
52 | 50 | ((pt.x - bounds.min().x) / RESOLUTION_M) as usize,
|
@@ -102,14 +100,24 @@ impl RenderCells {
|
102 | 100 | }
|
103 | 101 |
|
104 | 102 | if true {
|
105 |
| - finalize(grid, cell_colors, bounds) |
| 103 | + finalize( |
| 104 | + grid, |
| 105 | + cell_colors, |
| 106 | + bounds, |
| 107 | + &MultiPolygon::new(vec![boundary_polygon]), |
| 108 | + ) |
106 | 109 | } else {
|
107 | 110 | debug_grid(grid, cell_colors, bounds)
|
108 | 111 | }
|
109 | 112 | }
|
110 | 113 | }
|
111 | 114 |
|
112 |
| -fn finalize(main_grid: Grid<Option<usize>>, cell_colors: Vec<Color>, bounds: Rect) -> RenderCells { |
| 115 | +fn finalize( |
| 116 | + main_grid: Grid<Option<usize>>, |
| 117 | + cell_colors: Vec<Color>, |
| 118 | + bounds: Rect, |
| 119 | + boundary: &MultiPolygon, |
| 120 | +) -> RenderCells { |
113 | 121 | let mut result = RenderCells {
|
114 | 122 | polygons_per_cell: Vec::new(),
|
115 | 123 | colors: Vec::new(),
|
@@ -155,10 +163,12 @@ fn finalize(main_grid: Grid<Option<usize>>, cell_colors: Vec<Color>, bounds: Rec
|
155 | 163 | }
|
156 | 164 | assert_eq!(cell_polygons.len(), 1);
|
157 | 165 |
|
158 |
| - // TODO Sometimes one cell "leaks" out of the neighbourhood boundary. Not sure why. But we |
159 |
| - // can just clip the result. |
160 |
| - |
161 |
| - result.polygons_per_cell.push(cell_polygons.remove(0)); |
| 166 | + // Sometimes one cell "leaks" out of the neighbourhood boundary. Not sure why. But we can |
| 167 | + // just clip the result. |
| 168 | + let cell_polygon = cell_polygons.remove(0); |
| 169 | + result |
| 170 | + .polygons_per_cell |
| 171 | + .push(cell_polygon.intersection(boundary)); |
162 | 172 | result.colors.push(color);
|
163 | 173 | }
|
164 | 174 |
|
|
0 commit comments