geoarrow_array/scalar/
rect.rs1use geo_traits::RectTrait;
2use geoarrow_schema::Dimension;
3
4use crate::array::SeparatedCoordBuffer;
5use crate::eq::rect_eq;
6use crate::scalar::SeparatedCoord;
7
8#[derive(Debug, Clone)]
12pub struct Rect<'a> {
13 lower: &'a SeparatedCoordBuffer,
14 upper: &'a SeparatedCoordBuffer,
15 pub(crate) geom_index: usize,
16}
17
18impl<'a> Rect<'a> {
19 pub(crate) fn new(
20 lower: &'a SeparatedCoordBuffer,
21 upper: &'a SeparatedCoordBuffer,
22 geom_index: usize,
23 ) -> Self {
24 Self {
25 lower,
26 upper,
27 geom_index,
28 }
29 }
30
31 pub(crate) fn native_dim(&self) -> Dimension {
32 self.lower.dim
33 }
34}
35
36impl<'a> RectTrait for Rect<'a> {
37 type CoordType<'b>
38 = SeparatedCoord<'a>
39 where
40 Self: 'b;
41
42 fn min(&self) -> Self::CoordType<'_> {
43 self.lower.value(self.geom_index)
44 }
45
46 fn max(&self) -> Self::CoordType<'_> {
47 self.upper.value(self.geom_index)
48 }
49}
50
51impl<'a> RectTrait for &Rect<'a> {
52 type CoordType<'b>
53 = SeparatedCoord<'a>
54 where
55 Self: 'b;
56
57 fn min(&self) -> Self::CoordType<'_> {
58 self.lower.value(self.geom_index)
59 }
60
61 fn max(&self) -> Self::CoordType<'_> {
62 self.upper.value(self.geom_index)
63 }
64}
65
66impl<G: RectTrait<T = f64>> PartialEq<G> for Rect<'_> {
67 fn eq(&self, other: &G) -> bool {
68 rect_eq(self, other)
69 }
70}