-
Notifications
You must be signed in to change notification settings - Fork 199
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
Crash in polygon.contains(linestring) #1268
Comments
JTS thinks The polygon's invalid:
|
If you "fix" the input Polygon (which will split it into a MultiPolygon with a little triangular outlier beneath the main geometry):
You'll get this result from JTS: |
I added https://github.com/dabreegster/georust_crash/blob/main/polygon.geojson. I'm not surprised that it's invalid; the left corner has an infinitely thin line and a second blob: At a glance, I don't see a public API to detect invalid polygons. If we had one, we could call it and immediately bail out from geomgraph operations, maybe? Or in any case, crashing is bad -- should |
There are third-party Rust (and cpp) libraries (of varying sophistication) available. Prepair is very good but is cpp, https://github.com/mthh/geo-validity-check wraps GEOS so probably isn't what you want. The downside is that a full validity check / repair is slow, so you probably wouldn't want to run the check by default. Which brings us back to questions about catching panics and / or returning In any case the sensible approach is probably to have a look at what Prepair / ST_MAKEVALID do and emulate that in pure Rust if possible. I believe both approaches are based on constrained Delaunay triangulations which are now available to us in |
This looks kinda rudimentary but may work for most cases, and is pure Rust and MIT: |
Thank you! In the very short term, I'll detect/repair using something pure Rust. In the slightly longer term, make https://github.com/dabreegster/route_snapper/ produce valid polygons by construction. The question remaining for here -- panicking on invalid inputs is quite bad. Catching panics is tricky from WASM last time I tried (though I think I saw some updated method that might work). I'd vote for returning |
I agree re: panics, and I think I'd rather break the API with a catch-panic-and-return- |
For anyone else who is curious, here is the line that caused the panic:
|
I'm traveling for a couple weeks and probably won't be able to look deeply into this until I return. As a rule I work to avoid crashing in release builds, but I'm pretty loose with debug_asserts. They can catch bugs while typically not endangering production usage. Are you seeing this |
Just in case there's confusion - this panic looks to be in the geomgraph code, not the boolops code. |
... Ah, good catch. Actually it doesn't crash in release mode, and the results look correct to me (functionally, linestring containment in the two pieces of the polygon is OK). I hadn't noticed because I've always been compiling in debug mode when I develop.
That seems reasonable for a self-contained library, but for a widely used one, it can make for a confusing developer experience! Any opinions on
|
My immediate feeling is that this seems to be pretty much what debug asserts are for, and having them results in fixing bugs. I can see how it’s confusing if you aren’t familiar with them though. Maybe this one in particular needs to be re-examined?FYI - it is possible to disable them at build time if you don’t like them.
|
This particular one did reveal invalid inputs, which are nice to flag. Maybe then the resolution to this issue is just a docstring update to the tune of |
Before we go that route, we should decide if we should instead return a |
To reproduce, clone https://github.com/dabreegster/georust_crash and
cargo run
. The input coordinates are Euclidean, relative to a 0,0 origin. I tried a few online WKT viewers, but all of them need some kind of CRS. I'll try the JTS one later and try to understand the problem.The text was updated successfully, but these errors were encountered: