clipper2_sys/int64/
poly_tree_64.rs1use crate::{
2 clipper_delete_path64, clipper_path64_size, clipper_polytree64_count,
3 clipper_polytree64_get_child, clipper_polytree64_is_hole, clipper_polytree64_polygon, malloc,
4 ClipperPolyTree64, Path64, Paths64,
5};
6
7#[derive(Debug)]
8pub struct PolyTree64 {
9 pub(crate) childs: Vec<Self>,
10 pub(crate) is_hole: bool,
11 pub(crate) polygon: Path64,
12}
13
14impl PolyTree64 {
15 pub(crate) fn from(ptr: *mut ClipperPolyTree64) -> Self {
16 let is_hole: bool;
17 let polygon: Path64;
18 let childs: Vec<Self>;
19 unsafe {
20 is_hole = clipper_polytree64_is_hole(ptr) == 1;
21 let mem = malloc(clipper_path64_size());
22 let polygon_prt = clipper_polytree64_polygon(mem, ptr);
23 polygon = Path64::from(polygon_prt);
24 clipper_delete_path64(polygon_prt);
25 let count = clipper_polytree64_count(ptr);
26 childs = (0..count)
27 .map(|i| {
28 let tree_ptr = clipper_polytree64_get_child(ptr, i);
29 Self::from(tree_ptr as *mut ClipperPolyTree64)
30 })
31 .collect();
32 }
33 Self {
34 childs: childs,
35 is_hole: is_hole,
36 polygon: polygon,
37 }
38 }
39}
40
41impl PolyTree64 {
42 pub fn get_childs(&mut self) -> &mut Vec<Self> {
43 &mut self.childs
44 }
45
46 pub fn is_hole(&self) -> bool {
47 self.is_hole
48 }
49
50 pub fn get_hole_paths(&self) -> Paths64 {
51 let mut paths = Paths64::new(&vec![]);
52 for child in &self.childs {
53 if child.is_hole {
54 paths.add_path(child.get_polygon());
55 }
56 }
57 paths
58 }
59
60 pub fn get_polygon(&self) -> Path64 {
61 self.polygon.clone()
62 }
63}