egml_core/operations/
geometry.rs1use crate::model::geometry::{DirectPosition, Envelope};
2use nalgebra::Isometry3;
3
4pub trait Geometry {
5 fn points(&self) -> Vec<&DirectPosition>;
6
7 fn apply_transform(&mut self, m: &Isometry3<f64>);
8
9 fn get_lower_corner(&self) -> DirectPosition {
10 let x_min = self
11 .points()
12 .iter()
13 .min_by(|a, b| a.x().partial_cmp(&b.x()).unwrap())
14 .unwrap()
15 .x();
16 let y_min = self
17 .points()
18 .iter()
19 .min_by(|a, b| a.y().partial_cmp(&b.y()).unwrap())
20 .unwrap()
21 .y();
22 let z_min = self
23 .points()
24 .iter()
25 .min_by(|a, b| a.z().partial_cmp(&b.z()).unwrap())
26 .unwrap()
27 .z();
28
29 DirectPosition::new(x_min, y_min, z_min).unwrap()
30 }
31
32 fn get_upper_corner(&self) -> DirectPosition {
33 let x_max = self
34 .points()
35 .iter()
36 .max_by(|a, b| a.x().partial_cmp(&b.x()).unwrap())
37 .unwrap()
38 .x();
39 let y_max = self
40 .points()
41 .iter()
42 .max_by(|a, b| a.y().partial_cmp(&b.y()).unwrap())
43 .unwrap()
44 .y();
45 let z_max = self
46 .points()
47 .iter()
48 .max_by(|a, b| a.z().partial_cmp(&b.z()).unwrap())
49 .unwrap()
50 .z();
51
52 DirectPosition::new(x_max, y_max, z_max).unwrap()
53 }
54
55 fn envelope(&self) -> Envelope {
56 let lower = self.get_lower_corner();
57 let upper = self.get_upper_corner();
58
59 Envelope::new(lower, upper).expect("Must be constructable with a valid geometry.")
60 }
61}