-
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
Split a polygon by linestrings #7
Comments
Currently, structures like LineString are not supported. I have some ideas on how to implement them, but it will take time to explore fully, so I don't expect to add this feature in the near future. For now, you can achieve this by creating a thin polygon with 2px height. It's a dirty hack, but must work. |
Thanks for the quick reply. I've been thinking about ways of implementing this, and have come up with:
I think I've attempted some parts of this before, but gotten stuck on floating point issues (from bad input geometry with self-intersections; but the application I have in mind now would be much better) and the clockwise ordering. But reading through https://ishape-rust.github.io/iShape-js/overlay/extract/extract_shapes.html and your use of fixed-precision vectors, I think something like this could work. As I have time, I'll try something like this and keep you posted, in case the result is useful to adapt here. |
Current logic is using sweep line algorithm for splitting edges. No need to fix it.
For adding split lines we need only add some marker enum or bool value to Segment is it a special segment. One thing to be care here, it's current logic delete all segments with count: ShapeCount == 0. Must not do it for special segment. Probably better to add marker dirctly to ShapeCount struct. a < b always! (a.x < b.x || a.x == b.x && a.y < b.y)
winding count
after splitting and filling steps we get a graph:
And for Next, we need to rework This could be useful both for slicing and filtering such lines. However, I’m not sure what else we can do with these LineStrings. May be I’m missing some use cases, which makes it hard for me to plan an optimal API for them. |
I prototyped over the weekend and got an edge splitter to work, and started on extracting faces from a planar graph, but there are bugs with sorting the edges clockwise (that I know how to fix, just need more time). I don't understand iOverlay well enough to follow most of what you wrote, but I'm sure your implementation is going to wind up much more general and nice. I can help with use cases though. In https://github.com/a-b-street/ltn and some other applications (mesh density image from TfL's doc, page 15), a large area needs to be partitioned by a bunch of "main" roads and "severances" such as rivers and railways: A use case for #6, clipping a linestring to a polygon (or maybe it's easier to frame this as "split a linestring by a polygon", If it's helpful to generate some "real world" inputs, I can do it easily from OpenStreetMap data from different places. If so, I assume Euclidean space is necessary. Is GeoJSON (with Euclidean coordinates) a useful format for you to work with, or do you prefer something else for encoding lists of points? |
Edit: it's kind of a diversion, but if you'd like to explore my prior approach of tracing around road boundaries and gluing them together to make large areas, it's still online:
This approach of building up areas "bottom-up" is unfortunately brittle. The same problems can be solved by dividing a large area by the "important" linestrings, and that problem might be very nicely solvable here |
How hard would it be to support splitting a polygon by one or more linestrings? I could approximate this today by first buffering the linestring into a very thin polygon (using something like https://github.com/jbuckmccready/cavalier_contours) and then using
difference
. But it'd be quite useful to avoid the buffering step and have the resulting pieces fit together without any gaps.The text was updated successfully, but these errors were encountered: