38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
#![allow(missing_docs)]
|
|
|
|
use glam::DVec2;
|
|
use road_parceling::{subdivide_all, RoadGraph, SubdivisionParams};
|
|
|
|
fn main() {
|
|
let r = 100.0;
|
|
let third = std::f64::consts::TAU / 3.0;
|
|
let mut g = RoadGraph::new();
|
|
let center = g.add_node(DVec2::new(0.0, 0.0));
|
|
let p1 = g.add_node(DVec2::new(r * 0.0_f64.cos(), r * 0.0_f64.sin()));
|
|
let p2 = g.add_node(DVec2::new(r * third.cos(), r * third.sin()));
|
|
let p3 = g.add_node(DVec2::new(r * (2.0 * third).cos(), r * (2.0 * third).sin()));
|
|
g.add_road(center, p1).unwrap();
|
|
g.add_road(center, p2).unwrap();
|
|
g.add_road(center, p3).unwrap();
|
|
g.add_road(p1, p2).unwrap();
|
|
g.add_road(p2, p3).unwrap();
|
|
g.add_road(p3, p1).unwrap();
|
|
g.rebuild_topology().unwrap();
|
|
let params = SubdivisionParams::default();
|
|
let parcels = subdivide_all(&g, ¶ms).unwrap();
|
|
println!("p1 = {:?}", g.node_position(p1));
|
|
println!("p2 = {:?}", g.node_position(p2));
|
|
println!("p3 = {:?}", g.node_position(p3));
|
|
println!("center = {:?}", g.node_position(center));
|
|
println!("\n{} parcels:", parcels.len());
|
|
for (i, (id, p)) in parcels.iter().enumerate() {
|
|
println!(
|
|
" [{}] id={:?} centroid={:?} verts={:?}",
|
|
i,
|
|
id,
|
|
p.polygon().centroid(),
|
|
p.vertices()
|
|
);
|
|
}
|
|
}
|