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

Add M-dim bindings #600

Merged
merged 20 commits into from
Jan 10, 2025
Merged

Add M-dim bindings #600

merged 20 commits into from
Jan 10, 2025

Conversation

JmsPae
Copy link
Contributor

@JmsPae JmsPae commented Jan 3, 2025

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

This PR seeks to add bindings for GDAL functions relating to higher-dimension geometry, in particular Measured geometry, with some other minor fixes/additions.

Added methods for Geometry:

  • add_point_zm
  • add_point_m
  • set_point_zm
  • set_point_m
  • get_point_zm
  • get_point_vec_zm
  • iso_wkt
  • iso_wkb

Considering renaming get_point_vec_zm to get_point_zm_vec, though neither exactly roll off the tongue.

Also modified the Debug impl. for Geometry to use iso_wkt in cases of measured geometry.

@JmsPae JmsPae marked this pull request as ready for review January 3, 2025 20:00
@JmsPae JmsPae changed the title Add Measure-dim. support Add M-dim bindings Jan 3, 2025
}
Ok(wkb)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe instead of a separate function, modifying the original wkb/wkt methods would be nicer, though that would be a breaking change.

src/vector/geometry.rs Outdated Show resolved Hide resolved
src/vector/geometry.rs Outdated Show resolved Hide resolved
src/vector/geometry.rs Outdated Show resolved Hide resolved
src/vector/geometry.rs Outdated Show resolved Hide resolved
@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

Quick r? @weiznich if you have time.

Copy link
Contributor

@weiznich weiznich left a comment

Choose a reason for hiding this comment

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

Looks ok for me beside the inconsistencies around the index type. Those are not critical, but it would be nice to see them addressed.

src/vector/geometry.rs Show resolved Hide resolved
src/vector/geometry.rs Show resolved Hide resolved
JmsPae and others added 2 commits January 10, 2025 18:16
@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

I noticed those, but they match the existing get_point and set_point.

But in #581 I went the other way around (i32 to usize)..

CHANGES.md Outdated Show resolved Hide resolved
JmsPae and others added 2 commits January 10, 2025 18:37
Altered Geometry Debug Impl.

Co-authored-by: Laurențiu Nicola <[email protected]>
@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

I noticed those, but they match the existing get_point and set_point.

But in #581 I went the other way around (i32 to usize)..

Should I just harmonize all these methods to use u32 where appropriate?

@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

I mean, u32 feels worse than both since it doesn't match the C type (and you can pass in a value larger than i32::MAX which overflows), and it doesn't play that well with idiomatic Rust code, which probably has an usize around.

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

We could do a checked conversion from usize to i32/c_int (eg. try_from) but then we'd have to make the methods fallible, which also isn't that great.

src/vector/geometry.rs Outdated Show resolved Hide resolved
Copy link
Member

@lnicola lnicola left a comment

Choose a reason for hiding this comment

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

LGTM with one last nit. No strong opinion on the i32 / usize thing though 🤷.

@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

PS: please squash at the end.

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

LGTM with one last nit. No strong opinion on the i32 / usize thing though 🤷.

IMHO it makes more sense to go with i32 if we're not (for now) making the methods fallible. I don't think the corresponding C functions do anything if you supply an index outside the range of points, which doesn't really give us a reason to throw any Err's unless we want to do any extra checks ourselves.

@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

Yeah, the GDAL functions log an error and return 0 (for GetPoint), so we'd have to check. But you still have to cast:

let points = todo!().
for (idx, p) in points.into_iter().enumerate() {
    geom.set_point_2d(idx as i32, p); // ugly, annoying for a new Rust user, and Clippy complains on clippy::pedantic
}

It's not too bad, though, more of a paper cut.

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

Something should probably be done, though it's starting to feel more out of scope for this PR. Otherwise, we can create a new Error type (the IntConversionError is too vague), make all the get/set methods fallible and accept usize/u32/whatever instead.

@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

Yeah, okay, let's leave them like this or use i32 for both (updating the changelog). But then what to do about #581?

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

This was probably a larger can of worms than we thought, eh?

I'm going to leave things as is for now and someone (maybe me in the not-so-distant future) can have a crack at a half-way decent solution.

I'll convert everything in geometry.rs to i32 since we're already meddling with it.

Never mind, that messed with way too much for this PR.

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

I feel like I have nothing else to add, so feel free to send it whenever.

@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

Yeah, can you please squash everything together?

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

There, pretty sure I've squashed everything now

@lnicola lnicola merged commit 7bbccb7 into georust:master Jan 10, 2025
@lnicola
Copy link
Member

lnicola commented Jan 10, 2025

That was cute 😂, but for future reference: https://www.baeldung.com/ops/git-squash-commits.

@JmsPae
Copy link
Contributor Author

JmsPae commented Jan 10, 2025

That was cute 😂, but for future reference: https://www.baeldung.com/ops/git-squash-commits.

Ye, realized that, apologies.

Pretty sure this was also my first PR merge so now I know, and knowing is half the battle etc.

@lnicola
Copy link
Member

lnicola commented Jan 11, 2025

Pretty sure this was also my first PR merge

It was really well-done, I wouldn't have guessed, good job! 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants