Skip to content

Commit

Permalink
update for latest trait
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Oct 16, 2024
1 parent 38ef757 commit 9824207
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"

[dependencies]
geo-types = { version = "0.7.8", optional = true }
geo-traits = { git = "https://github.com/kylebarron/geo", branch = "kyle/geo-traits-crate" }
geo-traits = { git = "https://github.com/kylebarron/geo", rev = "b1364efe8b69eb109a520867df5b6a76a4645034" }
num-traits = "0.2"
serde = { version = "1.0", default-features = false, optional = true }
thiserror = "1.0.23"
Expand Down
26 changes: 18 additions & 8 deletions src/types/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ impl<T: WktNum> PointTrait for Coord<T> {

fn dim(&self) -> geo_traits::Dimensions {
match (self.z.is_some(), self.m.is_some()) {
(true, true) => geo_traits::Dimensions::XYZM,
(true, false) => geo_traits::Dimensions::XYZ,
(false, true) => geo_traits::Dimensions::XYM,
(false, false) => geo_traits::Dimensions::XYM,
(true, true) => geo_traits::Dimensions::Xyzm,
(true, false) => geo_traits::Dimensions::Xyz,
(false, true) => geo_traits::Dimensions::Xym,
(false, false) => geo_traits::Dimensions::Xy,
}
}

Expand All @@ -118,6 +118,11 @@ impl<T: WktNum> PointTrait for Coord<T> {
self.y
}

fn is_empty(&self) -> bool {
// the Coord is never empty; the Point contains an `Option<Coord>` and thus may be empty.
false
}

fn nth_unchecked(&self, n: usize) -> Self::T {
let has_z = self.z.is_some();
let has_m = self.m.is_some();
Expand Down Expand Up @@ -150,13 +155,18 @@ impl<T: WktNum> PointTrait for &Coord<T> {

fn dim(&self) -> geo_traits::Dimensions {
match (self.z.is_some(), self.m.is_some()) {
(true, true) => geo_traits::Dimensions::XYZM,
(true, false) => geo_traits::Dimensions::XYZ,
(false, true) => geo_traits::Dimensions::XYM,
(false, false) => geo_traits::Dimensions::XY,
(true, true) => geo_traits::Dimensions::Xyzm,
(true, false) => geo_traits::Dimensions::Xyz,
(false, true) => geo_traits::Dimensions::Xym,
(false, false) => geo_traits::Dimensions::Xy,
}
}

fn is_empty(&self) -> bool {
// the Coord is never empty; the Point contains an `Option<Coord>` and thus may be empty.
false
}

fn x(&self) -> Self::T {
self.x
}
Expand Down
3 changes: 2 additions & 1 deletion src/types/geometrycollection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ impl<T: WktNum> GeometryCollectionTrait for GeometryCollection<T> {
type GeometryType<'a> = &'a Wkt<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ impl<T: WktNum> LineStringTrait for LineString<T> {
type PointType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand All @@ -89,8 +90,9 @@ impl<T: WktNum> LineStringTrait for &LineString<T> {
type PointType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/multilinestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ impl<T: WktNum> MultiLineStringTrait for MultiLineString<T> {
type LineStringType<'a> = &'a LineString<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand All @@ -98,8 +99,9 @@ impl<T: WktNum> MultiLineStringTrait for &MultiLineString<T> {
type LineStringType<'a> = &'a LineString<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/multipoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ impl<T: WktNum> MultiPointTrait for MultiPoint<T> {
type PointType<'a> = &'a Point<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand All @@ -94,8 +95,9 @@ impl<T: WktNum> MultiPointTrait for &MultiPoint<T> {
type PointType<'a> = &'a Point<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/multipolygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ impl<T: WktNum> MultiPolygonTrait for MultiPolygon<T> {
type PolygonType<'a> = &'a Polygon<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand All @@ -103,8 +104,9 @@ impl<T: WktNum> MultiPolygonTrait for &MultiPolygon<T> {
type PolygonType<'a> = &'a Polygon<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down
14 changes: 12 additions & 2 deletions src/types/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ impl<T: WktNum> PointTrait for Point<T> {
if let Some(coord) = &self.0 {
coord.dim()
} else {
geo_traits::Dimensions::XY
// TODO: infer dimension from empty WKT
geo_traits::Dimensions::Xy
}
}

fn is_empty(&self) -> bool {
self.0.is_none()
}

fn x(&self) -> Self::T {
self.0.as_ref().unwrap().x()
}
Expand All @@ -99,10 +104,15 @@ impl<T: WktNum> PointTrait for &Point<T> {
if let Some(coord) = &self.0 {
coord.dim()
} else {
geo_traits::Dimensions::XY
// TODO: infer dimension from empty WKT
geo_traits::Dimensions::Xy
}
}

fn is_empty(&self) -> bool {
self.0.is_none()
}

fn x(&self) -> Self::T {
self.0.as_ref().unwrap().x()
}
Expand Down
6 changes: 4 additions & 2 deletions src/types/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ impl<T: WktNum> PolygonTrait for Polygon<T> {
type RingType<'a> = &'a LineString<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand All @@ -102,8 +103,9 @@ impl<T: WktNum> PolygonTrait for &Polygon<T> {
type RingType<'a> = &'a LineString<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
if self.0.is_empty() {
geo_traits::Dimensions::XY
geo_traits::Dimensions::Xy
} else {
self.0[0].dim()
}
Expand Down

0 comments on commit 9824207

Please sign in to comment.