Skip to content

Commit 13c0ba9

Browse files
committed
rstar: impl RTreeObject for Arc and Rc
1 parent 5224382 commit 13c0ba9

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

rstar/src/object.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use alloc::rc::Rc;
2+
use alloc::sync::Arc;
3+
14
use crate::aabb::AABB;
25
use crate::envelope::Envelope;
36
use crate::point::{Point, PointExt};
@@ -232,3 +235,61 @@ where
232235
}
233236
}
234237
}
238+
239+
impl<T> RTreeObject for Arc<T>
240+
where
241+
T: RTreeObject + ?Sized,
242+
{
243+
type Envelope = T::Envelope;
244+
fn envelope(&self) -> Self::Envelope {
245+
(**self).envelope()
246+
}
247+
}
248+
249+
impl<T> PointDistance for Arc<T>
250+
where
251+
T: PointDistance + ?Sized,
252+
{
253+
fn distance_2(&self, point: &<Self::Envelope as Envelope>::Point) -> Distance<Self> {
254+
(**self).distance_2(point)
255+
}
256+
fn contains_point(&self, point: &<Self::Envelope as Envelope>::Point) -> bool {
257+
(**self).contains_point(point)
258+
}
259+
fn distance_2_if_less_or_equal(
260+
&self,
261+
point: &<Self::Envelope as Envelope>::Point,
262+
max_distance_2: Distance<Self>,
263+
) -> Option<Distance<Self>> {
264+
(**self).distance_2_if_less_or_equal(point, max_distance_2)
265+
}
266+
}
267+
268+
impl<T> RTreeObject for Rc<T>
269+
where
270+
T: RTreeObject + ?Sized,
271+
{
272+
type Envelope = T::Envelope;
273+
fn envelope(&self) -> Self::Envelope {
274+
(**self).envelope()
275+
}
276+
}
277+
278+
impl<T> PointDistance for Rc<T>
279+
where
280+
T: PointDistance + ?Sized,
281+
{
282+
fn distance_2(&self, point: &<Self::Envelope as Envelope>::Point) -> Distance<Self> {
283+
(**self).distance_2(point)
284+
}
285+
fn contains_point(&self, point: &<Self::Envelope as Envelope>::Point) -> bool {
286+
(**self).contains_point(point)
287+
}
288+
fn distance_2_if_less_or_equal(
289+
&self,
290+
point: &<Self::Envelope as Envelope>::Point,
291+
max_distance_2: Distance<Self>,
292+
) -> Option<Distance<Self>> {
293+
(**self).distance_2_if_less_or_equal(point, max_distance_2)
294+
}
295+
}

0 commit comments

Comments
 (0)