Skip to content

Commit

Permalink
Update for latest geo-traits
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Oct 24, 2024
1 parent 9824207 commit b49bf35
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 50 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", rev = "b1364efe8b69eb109a520867df5b6a76a4645034" }
geo-traits = { git = "https://github.com/kylebarron/geo", rev = "2b776919d561547f2e2658f804ce42574869d44b" }
num-traits = "0.2"
serde = { version = "1.0", default-features = false, optional = true }
thiserror = "1.0.23"
Expand Down
16 changes: 3 additions & 13 deletions src/types/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use geo_traits::PointTrait;
use geo_traits::CoordTrait;

use crate::tokenizer::{PeekableTokens, Token};
use crate::types::Dimension;
Expand Down Expand Up @@ -98,7 +98,7 @@ where
}
}

impl<T: WktNum> PointTrait for Coord<T> {
impl<T: WktNum> CoordTrait for Coord<T> {
type T = T;

fn dim(&self) -> geo_traits::Dimensions {
Expand All @@ -118,11 +118,6 @@ 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,7 +145,7 @@ impl<T: WktNum> PointTrait for Coord<T> {
}
}

impl<T: WktNum> PointTrait for &Coord<T> {
impl<T: WktNum> CoordTrait for &Coord<T> {
type T = T;

fn dim(&self) -> geo_traits::Dimensions {
Expand All @@ -162,11 +157,6 @@ impl<T: WktNum> PointTrait for &Coord<T> {
}
}

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
14 changes: 7 additions & 7 deletions src/types/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use geo_traits::{LineStringTrait, PointTrait};
use geo_traits::{CoordTrait, LineStringTrait};

use crate::tokenizer::PeekableTokens;
use crate::types::coord::Coord;
Expand Down Expand Up @@ -65,7 +65,7 @@ where

impl<T: WktNum> LineStringTrait for LineString<T> {
type T = T;
type PointType<'a> = &'a Coord<T> where Self: 'a;
type CoordType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
Expand All @@ -76,18 +76,18 @@ impl<T: WktNum> LineStringTrait for LineString<T> {
}
}

fn num_points(&self) -> usize {
fn num_coords(&self) -> usize {
self.0.len()
}

unsafe fn point_unchecked(&self, i: usize) -> Self::PointType<'_> {
unsafe fn coord_unchecked(&self, i: usize) -> Self::CoordType<'_> {
&self.0[i]
}
}

impl<T: WktNum> LineStringTrait for &LineString<T> {
type T = T;
type PointType<'a> = &'a Coord<T> where Self: 'a;
type CoordType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
// TODO: infer dimension from empty WKT
Expand All @@ -98,11 +98,11 @@ impl<T: WktNum> LineStringTrait for &LineString<T> {
}
}

fn num_points(&self) -> usize {
fn num_coords(&self) -> usize {
self.0.len()
}

unsafe fn point_unchecked(&self, i: usize) -> Self::PointType<'_> {
unsafe fn coord_unchecked(&self, i: usize) -> Self::CoordType<'_> {
&self.0[i]
}
}
Expand Down
36 changes: 7 additions & 29 deletions src/types/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use geo_traits::PointTrait;
use geo_traits::{CoordTrait, PointTrait};

use crate::tokenizer::PeekableTokens;
use crate::types::coord::Coord;
Expand Down Expand Up @@ -70,6 +70,7 @@ where

impl<T: WktNum> PointTrait for Point<T> {
type T = T;
type CoordType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
if let Some(coord) = &self.0 {
Expand All @@ -80,25 +81,14 @@ impl<T: WktNum> PointTrait for Point<T> {
}
}

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

fn x(&self) -> Self::T {
self.0.as_ref().unwrap().x()
}

fn y(&self) -> Self::T {
self.0.as_ref().unwrap().y()
}

fn nth_unchecked(&self, n: usize) -> Self::T {
self.0.as_ref().unwrap().nth_unchecked(n)
fn coord(&self) -> Option<Self::CoordType<'_>> {
self.0.as_ref()
}
}

impl<T: WktNum> PointTrait for &Point<T> {
type T = T;
type CoordType<'a> = &'a Coord<T> where Self: 'a;

fn dim(&self) -> geo_traits::Dimensions {
if let Some(coord) = &self.0 {
Expand All @@ -109,20 +99,8 @@ impl<T: WktNum> PointTrait for &Point<T> {
}
}

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

fn x(&self) -> Self::T {
self.0.as_ref().unwrap().x()
}

fn y(&self) -> Self::T {
self.0.as_ref().unwrap().y()
}

fn nth_unchecked(&self, n: usize) -> Self::T {
self.0.as_ref().unwrap().nth_unchecked(n)
fn coord(&self) -> Option<Self::CoordType<'_>> {
self.0.as_ref()
}
}
#[cfg(test)]
Expand Down

0 comments on commit b49bf35

Please sign in to comment.