-
Notifications
You must be signed in to change notification settings - Fork 3
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
First wave of function bindings update. #7
base: master
Are you sure you want to change the base?
Conversation
Tests are still missing.
Thank you for undertaking this work! Concerning the style, I usually run Anything that's OK for rustfmt is OK for me (and it avoids discussing a style guide). |
You are right for the formatting, it's because I use a different one from the official to ease the coding. I will add some tests today. Side question: did you create the shapes in the test by hand, or is it an export from Blender or else ? |
I'm not sure what information you want. So far WKB wasn't supported (but it seems like a good idea to support it). The same goes for VTK and OBJ (although it's not necessarily a priority). I guess VTK / OBJ writer could be defined the same way than the WKT writer, with something like the (totally untested) following: pub fn geometry_as_vtk(&self) -> -> Result<String> {
let mut ptr = MaybeUninit::<*mut c_char>::uninit();
let mut length: usize = 0;
unsafe {
sfcgal_geometry_as_vtk(self.c_geom.as_ref(), ptr.as_mut_ptr(), &mut length);
Ok(_c_string_with_size(ptr.assume_init(), length))
}
} |
Yep, I will implement that today this way |
If I remember correctly, some of them are coming from SFCGAL test suite and other may have been created by hand (or reuse examples seen on the Web such as in the PostGIS examples and stuff like that). |
Nice, I will dig into it, it will ease my life :) BTW, I saw they are about to merge 3D alpha shape. This is a killer feature. I will keep you updated when it's there if you wish. I will pre implement it here and leave it commented. This way, minimal work for you :) |
Last point to discuss: some algorithms need a specific type to work. I solved this by using this type of matching. I think I can expand that on most of the functions, because it avoids a ffi roundtrip in case the preconditions don't hold, with a clearer error message. That's ok for you ? |
OK for me, thanks!
Just had a quick look and I guess it's a good idea for functions that we know will fail on the C API side. let res = some_sfcgeometry_of_type_point.line_substring(12., 20.);
println!("{:?}", res); returns While others (such as the |
For the latter case, are you against a cfg feature that would enable the users to choose to bail early ? That way, people have the option to choose how "tight" the api is ? I can implement it if you let me. |
I deduce that you prefer to fail early (avoiding the FFI round trip)? I was just thinking of possible use cases (where a user has - really simple example - a Vec of geometries of mixed types, and accumulates their volumes to calculate the sum, knowing that it returns 0.0 for geometries whose volume can't be calculated would avoid having to deal with Err's that would be returned by the method, allowing you to always unwrap...). |
Let's do without cfg feature and choose to match the preconditions indicated in the documentation on the Rust side, without doing the FFI round trip, even for the few functions (like “orientation” or “volume”) that don't return an error on the C API side even when the precondition doesn't hold. This will probably lead to a clearer API / better user experience. |
Ok! |
Cleaned the formatting issues. Added some utils functions.
useless FFI roundtrips. Each precondition is set in a macros_rule.
Sorry I slightly modified the src/geometry.rs file to make clippy happy after slightly improving the CI workflows, so you'll need to merge the latest master version into your PR branch. |
Hi,
What's your opinion on 1) ? |
Tests are still missing.
Confirmation needed:
Do we follow the same strategy as wkb and al ?