1use crate::*;
26
27#[derive(Debug, PartialEq, PartialOrd, Default, Clone, Hash, Eq, Ord)]
30pub struct FilterSphere {
32 sphere: Sphere,
33}
34
35impl FilterSphere {
36 pub fn new(sphere: Sphere) -> Self {
38 FilterSphere { sphere }
39 }
40}
41
42impl IsND for FilterSphere {
43 fn n_dimensions() -> usize {
44 Sphere::n_dimensions()
45 }
46
47 fn position_nd(&self, dimension: usize) -> Result<f64> {
48 self.sphere.position_nd(dimension)
49 }
50}
51
52impl Is3D for FilterSphere {
53 #[inline(always)]
54 fn x(&self) -> f64 {
55 self.sphere.x()
56 }
57
58 #[inline(always)]
59 fn y(&self) -> f64 {
60 self.sphere.y()
61 }
62
63 #[inline(always)]
64 fn z(&self) -> f64 {
65 self.sphere.y()
66 }
67}
68
69impl IsBuildableND for FilterSphere {
70 #[inline(always)]
71 fn new_nd(coords: &[f64]) -> Result<Self> {
72 Ok(FilterSphere::new(Sphere::new_nd(coords)?))
73 }
74
75 #[inline(always)]
76 fn from_nd<P>(&mut self, other: P) -> Result<()>
77 where
78 P: IsBuildableND,
79 {
80 self.sphere.from_nd(other)
81 }
82}
83
84impl IsBuildable3D for FilterSphere {
85 #[inline(always)]
86 fn new(x: f64, y: f64, z: f64) -> Self {
87 FilterSphere::new(Sphere::new(x, y, z))
88 }
89
90 #[inline(always)]
91 fn from<P>(&mut self, other: &P)
92 where
93 P: Is3D,
94 {
95 self.sphere.from(other)
96 }
97}
98
99impl IsEditableND for FilterSphere {
100 fn set_position(&mut self, dimension: usize, val: f64) -> Result<()> {
101 self.sphere.set_position(dimension, val)
102 }
103}
104
105impl IsEditable3D for FilterSphere {
106 #[inline(always)]
107 fn set_x(&mut self, val: f64) {
108 self.sphere.set_x(val);
109 }
110
111 #[inline(always)]
112 fn set_y(&mut self, val: f64) {
113 self.sphere.set_y(val);
114 }
115
116 #[inline(always)]
117 fn set_z(&mut self, val: f64) {
118 self.sphere.set_z(val);
119 }
120}
121
122impl HasBoundingBox3D for FilterSphere {
123 fn bounding_box(&self) -> BoundingBox3D {
124 self.sphere.bounding_box()
125 }
126}
127
128impl HasBoundingBox3DMaybe for FilterSphere {
129 fn bounding_box_maybe(&self) -> Result<BoundingBox3D> {
130 self.sphere.bounding_box_maybe()
131 }
132}
133
134impl<T> IsFilter<T> for FilterSphere
135where
136 T: Is3D,
137{
138 fn is_allowed(&self, p: &T) -> bool {
139 dist_3d(p, &self.sphere.center) <= self.sphere.radius.get()
140 }
141}
142
143impl IsScalable for FilterSphere {
144 fn scale(&mut self, factor: Positive) {
145 self.sphere.scale(factor);
146 }
147}