geoarrow_array/scalar/
specialization.rs1use geo_traits::GeometryTrait;
4
5use crate::scalar::*;
6
7macro_rules! impl_specialization {
8 ($geometry_type:ident, $trait_name:ident) => {
9 impl GeometryTrait for $geometry_type<'_> {
10 type T = f64;
11 type PointType<'b>
12 = Point<'b>
13 where
14 Self: 'b;
15 type LineStringType<'b>
16 = LineString<'b>
17 where
18 Self: 'b;
19 type PolygonType<'b>
20 = Polygon<'b>
21 where
22 Self: 'b;
23 type MultiPointType<'b>
24 = MultiPoint<'b>
25 where
26 Self: 'b;
27 type MultiLineStringType<'b>
28 = MultiLineString<'b>
29 where
30 Self: 'b;
31 type MultiPolygonType<'b>
32 = MultiPolygon<'b>
33 where
34 Self: 'b;
35 type GeometryCollectionType<'b>
36 = GeometryCollection<'b>
37 where
38 Self: 'b;
39 type RectType<'b>
40 = Rect<'b>
41 where
42 Self: 'b;
43 type LineType<'b>
44 = geo_traits::UnimplementedLine<f64>
45 where
46 Self: 'b;
47 type TriangleType<'b>
48 = geo_traits::UnimplementedTriangle<f64>
49 where
50 Self: 'b;
51
52 fn dim(&self) -> geo_traits::Dimensions {
53 self.native_dim().into()
54 }
55
56 fn as_type(
57 &self,
58 ) -> geo_traits::GeometryType<
59 '_,
60 Self::PointType<'_>,
61 Self::LineStringType<'_>,
62 Self::PolygonType<'_>,
63 Self::MultiPointType<'_>,
64 Self::MultiLineStringType<'_>,
65 Self::MultiPolygonType<'_>,
66 Self::GeometryCollectionType<'_>,
67 Self::RectType<'_>,
68 Self::TriangleType<'_>,
69 Self::LineType<'_>,
70 > {
71 geo_traits::GeometryType::$geometry_type(self)
72 }
73 }
74
75 impl GeometryTrait for &'_ $geometry_type<'_> {
76 type T = f64;
77 type PointType<'b>
78 = Point<'b>
79 where
80 Self: 'b;
81 type LineStringType<'b>
82 = LineString<'b>
83 where
84 Self: 'b;
85 type PolygonType<'b>
86 = Polygon<'b>
87 where
88 Self: 'b;
89 type MultiPointType<'b>
90 = MultiPoint<'b>
91 where
92 Self: 'b;
93 type MultiLineStringType<'b>
94 = MultiLineString<'b>
95 where
96 Self: 'b;
97 type MultiPolygonType<'b>
98 = MultiPolygon<'b>
99 where
100 Self: 'b;
101 type GeometryCollectionType<'b>
102 = GeometryCollection<'b>
103 where
104 Self: 'b;
105 type RectType<'b>
106 = Rect<'b>
107 where
108 Self: 'b;
109 type LineType<'b>
110 = geo_traits::UnimplementedLine<f64>
111 where
112 Self: 'b;
113 type TriangleType<'b>
114 = geo_traits::UnimplementedTriangle<f64>
115 where
116 Self: 'b;
117
118 fn dim(&self) -> geo_traits::Dimensions {
119 self.native_dim().into()
120 }
121
122 fn as_type(
123 &self,
124 ) -> geo_traits::GeometryType<
125 '_,
126 Self::PointType<'_>,
127 Self::LineStringType<'_>,
128 Self::PolygonType<'_>,
129 Self::MultiPointType<'_>,
130 Self::MultiLineStringType<'_>,
131 Self::MultiPolygonType<'_>,
132 Self::GeometryCollectionType<'_>,
133 Self::RectType<'_>,
134 Self::TriangleType<'_>,
135 Self::LineType<'_>,
136 > {
137 geo_traits::GeometryType::$geometry_type(self)
138 }
139 }
140 };
141}
142
143impl_specialization!(Point, PointTrait);
144impl_specialization!(LineString, LineStringTrait);
145impl_specialization!(Polygon, PolygonTrait);
146impl_specialization!(MultiPoint, MultiPointTrait);
147impl_specialization!(MultiLineString, MultiLineStringTrait);
148impl_specialization!(MultiPolygon, MultiPolygonTrait);
149impl_specialization!(GeometryCollection, GeometryCollectionTrait);
150impl_specialization!(Rect, RectTrait);