vox_geometry_rust/
constant_vector_field3.rs

1/*
2 * // Copyright (c) 2021 Feng Yang
3 * //
4 * // I am making my contributions/submissions to this project solely in my
5 * // personal capacity and am not conveying any rights to any intellectual
6 * // property of any third parties.
7 */
8
9use crate::vector3::Vector3D;
10use crate::field3::Field3;
11use crate::vector_field3::VectorField3;
12use std::sync::{RwLock, Arc};
13
14/// # 3-D constant vector field.
15pub struct ConstantVectorField3 {
16    _value: Vector3D,
17}
18
19impl ConstantVectorField3 {
20    /// Constructs a constant vector field with given \p value.
21    pub fn new(value: Option<Vector3D>) -> ConstantVectorField3 {
22        return ConstantVectorField3 {
23            _value: value.unwrap_or(Vector3D::new_default())
24        };
25    }
26
27    /// Returns builder fox ConstantVectorField3.
28    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
41/// Shared pointer for the ConstantVectorField3 type.
42pub type ConstantVectorField3Ptr = Arc<RwLock<ConstantVectorField3>>;
43
44///
45/// # Front-end to create ConstantVectorField3 objects step by step.
46///
47pub struct Builder {
48    _value: Vector3D,
49}
50
51impl Builder {
52    /// Returns builder with value.
53    pub fn with_value(&mut self, value: Vector3D) -> &mut Self {
54        self._value = value;
55        return self;
56    }
57
58    /// Builds ConstantVectorField3.
59    pub fn build(&mut self) -> ConstantVectorField3 {
60        return ConstantVectorField3::new(Some(self._value));
61    }
62
63    /// Builds shared pointer of ConstantVectorField3 instance.
64    pub fn make_shared(&mut self) -> ConstantVectorField3Ptr {
65        return ConstantVectorField3Ptr::new(RwLock::new(self.build()));
66    }
67
68    /// constructor
69    pub fn new() -> Builder {
70        return Builder {
71            _value: Vector3D::new_default()
72        };
73    }
74}