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

Update to geo-traits 0.2 #31

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rust-version = "1.82"

[dependencies]
byteorder = "1"
geo-traits = "0.1.1"
geo-traits = "0.2"
num_enum = "0.7"
thiserror = "1"

Expand All @@ -22,7 +22,7 @@ approx = "0.5.1"
bytes = "1.5.0"
criterion = { version = "0.5", features = ["html_reports"] }
geo-types = "0.7.13"
wkt = { git = "https://github.com/georust/wkt", branch = "kyle/geo-traits" }
wkt = { git = "https://github.com/georust/wkt", rev = "779e519d845309ac9616aa6438b987215e3c4327" }

[[bench]]
name = "parse"
Expand Down
2 changes: 1 addition & 1 deletion src/reader/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> CoordTrait for Coord<'a> {
self.dim
}

fn nth_unchecked(&self, n: usize) -> Self::T {
fn nth_or_panic(&self, n: usize) -> Self::T {
self.get_nth_unchecked(n)
}

Expand Down
11 changes: 9 additions & 2 deletions src/reader/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ impl<'a> Point<'a> {
// The space of the byte order + geometry type
let offset = offset + 5;
let coord = Coord::new(buf, byte_order, offset, dim);
let is_empty =
(0..coord.dim().size()).all(|coord_dim| coord.nth_unchecked(coord_dim).is_nan());
let is_empty = (0..coord.dim().size()).all(|coord_dim| {
{
// Safety:
// We just checked the number of dimensions, and coord_dim is less than
// coord.dim().size()
unsafe { coord.nth_unchecked(coord_dim) }
}
.is_nan()
});
Self {
coord,
dim,
Expand Down
5 changes: 4 additions & 1 deletion src/writer/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ pub(crate) fn write_coord<W: Write, B: ByteOrder>(
coord: &impl CoordTrait<T = f64>,
) -> WKBResult<()> {
for i in 0..coord.dim().size() {
writer.write_f64::<B>(coord.nth_unchecked(i))?;
// # Safety
// We just checked the number of dimensions in this coord
let val = unsafe { coord.nth_unchecked(i) };
writer.write_f64::<B>(val)?;
}

Ok(())
Expand Down
Loading