1use std::marker::PhantomData;
2
3#[cfg(feature = "geo-types")]
4use geo_types::{Coord, CoordNum, Rect};
5
6use crate::{CoordTrait, UnimplementedCoord};
7
8pub trait RectTrait: crate::GeometryTrait {
13 type CoordType<'a>: 'a + CoordTrait<T = <Self as crate::GeometryTrait>::T>
15 where
16 Self: 'a;
17
18 fn min(&self) -> Self::CoordType<'_>;
20
21 fn max(&self) -> Self::CoordType<'_>;
23}
24
25#[cfg(feature = "geo-types")]
26impl<T: CoordNum> RectTrait for Rect<T> {
27 type CoordType<'b>
28 = Coord<T>
29 where
30 Self: 'b;
31
32 fn min(&self) -> Self::CoordType<'_> {
33 Rect::min(*self)
34 }
35
36 fn max(&self) -> Self::CoordType<'_> {
37 Rect::max(*self)
38 }
39}
40
41#[cfg(feature = "geo-types")]
42impl<'a, T: CoordNum + 'a> RectTrait for &'a Rect<T> {
43 type CoordType<'b>
44 = Coord<T>
45 where
46 Self: 'b;
47
48 fn min(&self) -> Self::CoordType<'_> {
49 Rect::min(**self)
50 }
51
52 fn max(&self) -> Self::CoordType<'_> {
53 Rect::max(**self)
54 }
55}
56
57pub struct UnimplementedRect<T>(PhantomData<T>);
62
63impl<T> RectTrait for UnimplementedRect<T> {
64 type CoordType<'a>
65 = UnimplementedCoord<Self::T>
66 where
67 Self: 'a;
68
69 fn min(&self) -> Self::CoordType<'_> {
70 unimplemented!()
71 }
72
73 fn max(&self) -> Self::CoordType<'_> {
74 unimplemented!()
75 }
76}