egml_core/model/feature/
bounding_shape.rs1use crate::model::basic_types::NilReason;
2use crate::model::common::ApplyTransform;
3use crate::model::geometry::Envelope;
4use nalgebra::{Isometry3, Rotation3, Scale3, Transform3, Vector3};
5
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct BoundingShape {
8 envelope: Option<Envelope>,
9 nil_reason: Option<NilReason>,
10}
11
12impl BoundingShape {
13 pub fn new(envelope: Envelope) -> Self {
14 Self {
15 envelope: Some(envelope),
16 nil_reason: None,
17 }
18 }
19
20 pub fn new_unchecked(envelope: Option<Envelope>, nil_reason: Option<NilReason>) -> Self {
21 Self {
22 envelope,
23 nil_reason,
24 }
25 }
26
27 pub fn envelope(&self) -> Option<&Envelope> {
28 self.envelope.as_ref()
29 }
30
31 pub fn envelope_mut(&mut self) -> Option<&mut Envelope> {
32 self.envelope.as_mut()
33 }
34
35 pub fn nil(nil_reason: NilReason) -> Self {
36 Self {
37 envelope: None,
38 nil_reason: Some(nil_reason),
39 }
40 }
41}
42
43impl ApplyTransform for BoundingShape {
44 fn apply_transform(&mut self, transform: Transform3<f64>) {
45 if let Some(envelope) = self.envelope.as_mut() {
46 envelope.apply_transform(transform);
47 }
48 }
49
50 fn apply_isometry(&mut self, isometry: Isometry3<f64>) {
51 if let Some(envelope) = self.envelope.as_mut() {
52 envelope.apply_isometry(isometry);
53 }
54 }
55
56 fn apply_translation(&mut self, vector: Vector3<f64>) {
57 if let Some(envelope) = self.envelope.as_mut() {
58 envelope.apply_translation(vector);
59 }
60 }
61
62 fn apply_rotation(&mut self, rotation: Rotation3<f64>) {
63 if let Some(envelope) = self.envelope.as_mut() {
64 envelope.apply_rotation(rotation);
65 }
66 }
67
68 fn apply_scale(&mut self, scale: Scale3<f64>) {
69 if let Some(envelope) = self.envelope.as_mut() {
70 envelope.apply_scale(scale);
71 }
72 }
73}