Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement geo_traits for geojson types. #245

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ edition = "2018"

[features]
default = ["geo-types"]
geo-traits = ["dep:geo-traits", "dep:bytemuck"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about making this a default dependency? I wouldn't imagine it would add too much to compilation time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me! As long as we keep it optional


[dependencies]
serde = { version="~1.0", features = ["derive"] }
serde_json = "~1.0"
geo-types = { version = "0.7.13", features = ["serde"], optional = true }
geo-traits = { version = "0.1.0", optional = true }
bytemuck = { version = "1", features = ["derive"], optional = true }
thiserror = "1.0.20"
log = "0.4.17"

Expand Down
47 changes: 47 additions & 0 deletions src/geo_traits_impl/coord.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use super::PointType;
use geo_traits::Dimensions;

impl geo_traits::CoordTrait for PointType {
type T = f64;

fn dim(&self) -> Dimensions {
match self.0.len() {
0 | 1 => panic!("Position must have at least 2 dimensions"),
2 => Dimensions::Xy,
3 => Dimensions::Xyz,
_ => Dimensions::Unknown(self.0.len()),
}
}

fn x(&self) -> Self::T {
self.0[0]
}

fn y(&self) -> Self::T {
self.0[1]
}

fn nth_unchecked(&self, n: usize) -> Self::T {
self.0[n]
}
}

impl geo_traits::CoordTrait for &PointType {
type T = f64;

fn dim(&self) -> Dimensions {
PointType::dim(self)
}

fn x(&self) -> Self::T {
PointType::x(self)
}

fn y(&self) -> Self::T {
PointType::y(self)
}

fn nth_unchecked(&self, n: usize) -> Self::T {
PointType::nth_unchecked(self, n)
}
}
Loading