-
Notifications
You must be signed in to change notification settings - Fork 62
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
base: main
Are you sure you want to change the base?
Changes from all commits
fca637e
e6461ef
6f5b520
403a089
0c503b6
b74e52b
d57de45
466a5cb
7bd2f75
765e37a
40bec4b
d90e876
0c5b469
743ef4e
62d399f
537991f
3759c3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider: Granted, to be valid, a geojson MUST have at least two coordinates. But this library is used to parse input that may be invalid, and I don't think we should be panic'ing in release builds for invalid input. I think this will surprise people in a bad way. Instead, returning either There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We talked about this above: #245 (comment), #245 (comment), #245 (comment). And see also georust/geo#1263 (comment). I'd personally choose a default of |
||
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_or_panic(&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_or_panic(&self, n: usize) -> Self::T { | ||
PointType::nth_or_panic(self, n) | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure who's driving this PR at this point, but it seems like this is still outstanding.