MCPcopy Create free account
hub / github.com/Notgnoshi/generative / polygonize

Function polygonize

generative/noding/mod.rs:45–76  ·  view source on GitHub ↗
(
    graph: &GeometryGraph<Direction>,
)

Source from the content-addressed store, hash-verified

43}
44
45pub 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)]
79mod tests {

Callers 3

test_polygonizeFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50

Calls 1

to_ffi_graphFunction · 0.85

Tested by 1

test_polygonizeFunction · 0.56