vox_geometry_rust/
surface_to_implicit3.rs1use crate::surface3::*;
10use crate::transform3::Transform3;
11use crate::implicit_surface3::ImplicitSurface3;
12use crate::vector3::Vector3D;
13use crate::bounding_box3::BoundingBox3D;
14use crate::ray3::Ray3D;
15use std::sync::{RwLock, Arc};
16
17pub struct SurfaceToImplicit3 {
27 _surface: Surface3Ptr,
28
29 pub surface_data: Surface3Data,
31}
32
33impl SurfaceToImplicit3 {
34 pub fn new(
36 surface: Surface3Ptr,
37 transform: Option<Transform3>,
38 is_normal_flipped: Option<bool>) -> SurfaceToImplicit3 {
39 return SurfaceToImplicit3 {
40 _surface: surface,
41 surface_data: Surface3Data::new(transform, is_normal_flipped),
42 };
43 }
44
45 pub fn builder() -> Builder {
47 return Builder::new();
48 }
49
50 pub fn surface(&self) -> Surface3Ptr {
52 return self._surface.clone();
53 }
54}
55
56impl Surface3 for SurfaceToImplicit3 {
57 fn closest_point_local(&self, other_point: &Vector3D) -> Vector3D {
58 return self._surface.read().unwrap().closest_point(other_point);
59 }
60
61 fn bounding_box_local(&self) -> BoundingBox3D {
62 return self._surface.read().unwrap().bounding_box();
63 }
64
65 fn closest_intersection_local(&self, ray: &Ray3D) -> SurfaceRayIntersection3 {
66 return self._surface.read().unwrap().closest_intersection(ray);
67 }
68
69 fn closest_normal_local(&self, other_point: &Vector3D) -> Vector3D {
70 return self._surface.read().unwrap().closest_normal(other_point);
71 }
72
73 fn intersects_local(&self, ray: &Ray3D) -> bool {
74 return self._surface.read().unwrap().intersects(ray);
75 }
76
77 fn closest_distance_local(&self, other_point: &Vector3D) -> f64 {
78 return self._surface.read().unwrap().closest_distance(other_point);
79 }
80
81 fn update_query_engine(&self) {
82 self._surface.read().unwrap().update_query_engine();
83 }
84
85 fn is_bounded(&self) -> bool {
86 return self._surface.read().unwrap().is_bounded();
87 }
88
89 fn is_valid_geometry(&self) -> bool {
90 return self._surface.read().unwrap().is_valid_geometry();
91 }
92
93 fn view(&self) -> &Surface3Data {
94 return &self.surface_data;
95 }
96}
97
98impl ImplicitSurface3 for SurfaceToImplicit3 {
99 fn signed_distance_local(&self, other_point: &Vector3D) -> f64 {
100 let x = self._surface.read().unwrap().closest_point(other_point);
101 let inside = self._surface.read().unwrap().is_inside(other_point);
102 return match inside {
103 true => -x.distance_to(*other_point),
104 false => x.distance_to(*other_point)
105 };
106 }
107
108 fn is_inside_local(&self, other_point: &Vector3D) -> bool {
109 return self._surface.read().unwrap().is_inside(other_point);
110 }
111}
112
113pub type SurfaceToImplicit3Ptr = Arc<RwLock<SurfaceToImplicit3>>;
115
116pub struct Builder {
120 _surface: Option<Surface3Ptr>,
121
122 _surface_data: Surface3Data,
123}
124
125impl Builder {
126 pub fn with_surface(&mut self, surface: Surface3Ptr) -> &mut Self {
128 self._surface = Some(surface);
129 return self;
130 }
131
132 pub fn build(&mut self) -> SurfaceToImplicit3 {
134 return SurfaceToImplicit3::new(self._surface.as_ref().unwrap().clone(),
135 Some(self._surface_data.transform.clone()),
136 Some(self._surface_data.is_normal_flipped));
137 }
138
139 pub fn make_shared(&mut self) -> SurfaceToImplicit3Ptr {
141 return SurfaceToImplicit3Ptr::new(RwLock::new(self.build()));
142 }
143
144 pub fn new() -> Builder {
146 return Builder {
147 _surface: None,
148 _surface_data: Surface3Data::new(None, None),
149 };
150 }
151}
152
153impl SurfaceBuilderBase3 for Builder {
154 fn view(&mut self) -> &mut Surface3Data {
155 return &mut self._surface_data;
156 }
157}