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

Function test_rectangle

generative/noding/mod.rs:182–228  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180
181 #[test]
182 fn test_rectangle() {
183 // a tic-tac-toe pattern
184 let wkt = b"GEOMETRYCOLLECTION( LINESTRING(2 0, 2 8), LINESTRING(6 0, 6 8), LINESTRING(0 2, 8 2), LINESTRING(0 6, 8 6))";
185 let geoms = read_wkt_geometries(&wkt[..]);
186
187 let graph = node::<_, Undirected>(geoms);
188 assert_eq!(graph.node_count(), 12);
189 assert_eq!(graph.edge_count(), 12);
190
191 let nodes: Vec<_> = graph.node_weights().collect();
192 let expected = [
193 &Point::new(2.0, 0.0), // 0 - start left vertical
194 &Point::new(2.0, 2.0), // 1 - intersection
195 &Point::new(2.0, 6.0), // 2 - intersection
196 &Point::new(2.0, 8.0), // 3 - end left vertical
197 &Point::new(6.0, 0.0), // 4 - start right vertical
198 &Point::new(6.0, 2.0), // 5 - intersection
199 &Point::new(6.0, 6.0), // 6 - intersection
200 &Point::new(6.0, 8.0), // 7 - end left vertical
201 &Point::new(0.0, 2.0), // 8 - start bottom horizontal
202 &Point::new(8.0, 2.0), // 9
203 &Point::new(0.0, 6.0), // 10 - start top horizontal
204 &Point::new(8.0, 6.0), // 11
205 ];
206 assert_eq!(nodes, expected);
207
208 let mut edges = Vec::new();
209 for i in 0..graph.edge_count() {
210 let edge = graph.edge_endpoints(EdgeIndex::new(i)).unwrap();
211 edges.push((edge.0.index(), edge.1.index()))
212 }
213 let expected = [
214 (0, 1), // bottom left vertical dangle
215 (1, 5), // bottom inner horizontal
216 (1, 8), // bottom left horizontal dangle
217 (1, 2), // left inner vertical
218 (2, 6), // top inner horizontal
219 (2, 10), // top left horizontal dangle
220 (2, 3), // top left verticle dangle
221 (4, 5), // bottom right verticle dangle
222 (5, 9), // bottom right horizontal dangle
223 (5, 6), // right inner horizontal
224 (6, 11), // top right horizontal dangle
225 (6, 7), // top right verticle dangle
226 ];
227 assert_eq!(edges, expected);
228 }
229
230 #[test]
231 fn test_polygonize() {

Callers

nothing calls this directly

Calls 1

read_wkt_geometriesFunction · 0.85

Tested by

no test coverage detected