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

Hatching a polygon #37

Open
zdila opened this issue Jan 25, 2024 · 1 comment
Open

Hatching a polygon #37

zdila opened this issue Jan 25, 2024 · 1 comment

Comments

@zdila
Copy link

zdila commented Jan 25, 2024

I am trying to use this library also for hatching a polygon. With polygons without holes it works - for each hatching line I find intersections with a polygon and draw the segments. My initial code can be found at https://github.com/FreemapSlovakia/rustmap/blob/215c1c6c6929f16eef74b8aea5164c7cb6254ab7/src/draw.rs#L38 (disclaimer - it is work in progress and I am very new to Rust).

Unfortunately I don't know how to do it with polygons containing holes. I tried to search for Polygon struct that is capable to hold also holes but was not successful. Could you please help me with this?

@jbuckmccready
Copy link
Owner

For what you want to do with hatching I think you can do the following: find intersects with all the polylines (surrounding and holes) and then for each line order the intersect points by their position along the line and for each pair of points test if the midpoint between them is inside the hole it intersected with, if it is inside the hole discard it, otherwise keep it. You can test if the midpoint is inside a polyline by using the winding_number (method here), if the winding number is non-zero then the point is inside the hole polyline. The test is needed is to catch case when there is only single intersect with a hole otherwise you could just use all the lines (i1, i2), (i3, i4), (i5, i6), ....

NOTE: there may be a better way to do this, this is just first thing that came to mind that is pretty straight forward.

See the following image for visual (i1, i2, i3, ... are the intersect points ordered along the line).

image

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

No branches or pull requests

2 participants