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