geoarrow_array/scalar/coord/
combined.rs1use geo_traits::CoordTrait;
2
3use crate::eq::coord_eq;
4use crate::scalar::{InterleavedCoord, SeparatedCoord};
5
6#[derive(Debug, Clone)]
10pub enum Coord<'a> {
11 Separated(SeparatedCoord<'a>),
13 Interleaved(InterleavedCoord<'a>),
15}
16
17impl Coord<'_> {
18 pub(crate) fn is_nan(&self) -> bool {
20 match self {
21 Coord::Separated(c) => c.is_nan(),
22 Coord::Interleaved(c) => c.is_nan(),
23 }
24 }
25}
26
27impl PartialEq for Coord<'_> {
28 fn eq(&self, other: &Self) -> bool {
29 coord_eq(self, other)
30 }
31}
32
33impl PartialEq<InterleavedCoord<'_>> for Coord<'_> {
34 fn eq(&self, other: &InterleavedCoord<'_>) -> bool {
35 coord_eq(self, other)
36 }
37}
38
39impl PartialEq<SeparatedCoord<'_>> for Coord<'_> {
40 fn eq(&self, other: &SeparatedCoord<'_>) -> bool {
41 coord_eq(self, other)
42 }
43}
44
45impl CoordTrait for Coord<'_> {
46 type T = f64;
47
48 fn dim(&self) -> geo_traits::Dimensions {
49 match self {
50 Coord::Interleaved(c) => c.dim(),
51 Coord::Separated(c) => c.dim(),
52 }
53 }
54
55 fn nth_or_panic(&self, n: usize) -> Self::T {
56 match self {
57 Coord::Interleaved(c) => c.nth_or_panic(n),
58 Coord::Separated(c) => c.nth_or_panic(n),
59 }
60 }
61
62 fn x(&self) -> Self::T {
63 match self {
64 Coord::Interleaved(c) => c.x(),
65 Coord::Separated(c) => c.x(),
66 }
67 }
68
69 fn y(&self) -> Self::T {
70 match self {
71 Coord::Interleaved(c) => c.y(),
72 Coord::Separated(c) => c.y(),
73 }
74 }
75}
76
77impl CoordTrait for &Coord<'_> {
78 type T = f64;
79
80 fn dim(&self) -> geo_traits::Dimensions {
81 match self {
82 Coord::Interleaved(c) => c.dim(),
83 Coord::Separated(c) => c.dim(),
84 }
85 }
86
87 fn nth_or_panic(&self, n: usize) -> Self::T {
88 match self {
89 Coord::Interleaved(c) => c.nth_or_panic(n),
90 Coord::Separated(c) => c.nth_or_panic(n),
91 }
92 }
93
94 fn x(&self) -> Self::T {
95 match self {
96 Coord::Interleaved(c) => c.x(),
97 Coord::Separated(c) => c.x(),
98 }
99 }
100
101 fn y(&self) -> Self::T {
102 match self {
103 Coord::Interleaved(c) => c.y(),
104 Coord::Separated(c) => c.y(),
105 }
106 }
107}