,
}
pub fn triangulate(opts: TrianglulateOpts
) -> Result
@@ -40,6 +41,12 @@ where
P: IntoIterator- ,
{
let mut switches = Vec::new();
+ switches.push("p");
+ switches.push("c");
+ switches.push("z");
+ switches.push("A");
+ switches.push("e");
+ switches.push("n");
if opts.voronoi {
switches.push("v");
}
@@ -78,21 +85,31 @@ where
)
};
- println!("Triangulated.");
+ println!("Triangulated {}.", output.numberoftriangles);
- let flat_point_list = unsafe {
- Vec::from_raw_parts(
- output.pointlist,
- output.numberofpoints as usize * 2,
- output.numberofpoints as usize * 2,
- )
- };
- let point_list = flat_point_list
+ let point_list = point_list_from_flat_point_list(
+ output.pointlist,
+ output.numberofpoints as usize * 2,
+ );
+
+ let voronoi_point_list = point_list_from_flat_point_list(
+ vorout.pointlist,
+ vorout.numberofpoints as usize * 2,
+ );
+
+ Ok(TriangulateResult {
+ point_list,
+ voronoi_point_list,
+ })
+}
+
+fn point_list_from_flat_point_list(ptr: *mut f64, len: usize) -> Vec {
+ let flat_point_list = unsafe { Vec::from_raw_parts(ptr, len, len) };
+ flat_point_list
.chunks(2)
.map(|points| Point {
x: points[0],
y: points[1],
})
- .collect::>();
- Ok(TriangulateResult { point_list })
+ .collect::>()
}