| 43 | } |
| 44 | |
| 45 | pub fn polygonize<Direction: petgraph::EdgeType>( |
| 46 | graph: &GeometryGraph<Direction>, |
| 47 | ) -> (Vec<Polygon>, Vec<LineString>) { |
| 48 | let ffi_graph = cxxbridge::to_ffi_graph(graph); |
| 49 | let result = cxxbridge::polygonize(&ffi_graph); |
| 50 | |
| 51 | let mut polys = Vec::new(); |
| 52 | polys.reserve_exact(result.polygons.len()); |
| 53 | for coordseq in result.polygons { |
| 54 | let coords: Vec<_> = coordseq |
| 55 | .vec |
| 56 | .into_iter() |
| 57 | .map(|c| Coord { x: c.x, y: c.y }) |
| 58 | .collect(); |
| 59 | let exterior = LineString::new(coords); |
| 60 | let interiors = Vec::new(); |
| 61 | polys.push(Polygon::new(exterior, interiors)); |
| 62 | } |
| 63 | |
| 64 | let mut dangles = Vec::new(); |
| 65 | dangles.reserve_exact(result.dangles.len()); |
| 66 | for coordseq in result.dangles { |
| 67 | let coords: Vec<_> = coordseq |
| 68 | .vec |
| 69 | .into_iter() |
| 70 | .map(|c| Coord { x: c.x, y: c.y }) |
| 71 | .collect(); |
| 72 | dangles.push(LineString::new(coords)); |
| 73 | } |
| 74 | |
| 75 | (polys, dangles) |
| 76 | } |
| 77 | |
| 78 | #[cfg(test)] |
| 79 | mod tests { |