vox_geometry_rust/
constant_vector_field3.rs1use crate::vector3::Vector3D;
10use crate::field3::Field3;
11use crate::vector_field3::VectorField3;
12use std::sync::{RwLock, Arc};
13
14pub struct ConstantVectorField3 {
16 _value: Vector3D,
17}
18
19impl ConstantVectorField3 {
20 pub fn new(value: Option<Vector3D>) -> ConstantVectorField3 {
22 return ConstantVectorField3 {
23 _value: value.unwrap_or(Vector3D::new_default())
24 };
25 }
26
27 pub fn builder() -> Builder {
29 return Builder::new();
30 }
31}
32
33impl Field3 for ConstantVectorField3 {}
34
35impl VectorField3 for ConstantVectorField3 {
36 fn sample(&self, _: &Vector3D) -> Vector3D {
37 return self._value;
38 }
39}
40
41pub type ConstantVectorField3Ptr = Arc<RwLock<ConstantVectorField3>>;
43
44pub struct Builder {
48 _value: Vector3D,
49}
50
51impl Builder {
52 pub fn with_value(&mut self, value: Vector3D) -> &mut Self {
54 self._value = value;
55 return self;
56 }
57
58 pub fn build(&mut self) -> ConstantVectorField3 {
60 return ConstantVectorField3::new(Some(self._value));
61 }
62
63 pub fn make_shared(&mut self) -> ConstantVectorField3Ptr {
65 return ConstantVectorField3Ptr::new(RwLock::new(self.build()));
66 }
67
68 pub fn new() -> Builder {
70 return Builder {
71 _value: Vector3D::new_default()
72 };
73 }
74}