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 a clip_polygon_2d_with_polyline() method #2567

Open
dryluggage opened this issue Apr 7, 2021 · 1 comment
Open

Add a clip_polygon_2d_with_polyline() method #2567

dryluggage opened this issue Apr 7, 2021 · 1 comment

Comments

@dryluggage
Copy link

Describe the project you are working on

n/a

Describe the problem or limitation you are having in your project

you are able to cut polylines with polygons but there isnt a function to cut polygons with polylines

Describe the feature / enhancement and how it helps to overcome the problem or limitation

a function that will cut the polygon with the polyline and returns the resulting polygons if the polyline is cuts straigt though a square polygon it will create 2 polygons if the line is some crazy shape it will create more

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

the clip_polygon_2d_with_polyline takes the polygon and polyline and returns the polygon/s

If this enhancement will not be used often, can it be worked around with a few lines of script?

you can offset_polyline2d to make a polygon from the polyline and then clip both polygons but it isnt as elegant and has its limitations if you have a polyline that is shaped like the outline of a closed circle and its being offset instead of making the polygon the outline it will fill the outline and create a big shape and will just cut a hole into the other

Is there a reason why this should be core and not an add-on in the asset library?

Because the reverse is already implemented there already is an clip_polyline_with_polygon_2d function so just for the symetry

@Calinou Calinou changed the title add clip_polygon_2d_with_polyline function Add a clip_polygon_2d_with_polyline() method Apr 7, 2021
@Xrayez
Copy link
Contributor

Xrayez commented Apr 7, 2021

Godot uses Clipper for polygon boolean operations. It does support clipping polylines with polygons, but I don't see an equivalent method for doing the opposite.

If you look at the discussion at Clipper repository, the author says it's not possible to do this either:

It's not possible to use lines or polylines to clip polygons. However, as a
workaround, you could convert a line/polyline into a polygon before clipping.

So, not sure if it's not possible at all or not possible to do in Clipper, but according the proposed solutions there, it would likely require significant workarounds over a feature which is not supported, as suggested above.

However, if this proposal gains plenty of support and use cases, then it will be worth implementing. I may post a GDScript solution for the mentioned workaround if I'll need this myself at some point. 🙂

I don't know whether other polygon boolean libraries support this either. I think that the authors would already implement such a feature in case it's trivial, but apparently not.

Describe the project you are working on

n/a

It's not necessarily the project you need to describe, there must be concrete cases where a particular feature is needed. What do you need this for in your project?

I personally think that the suggested workaround is an acceptable solution for game development needs (like Fruit Ninja®).

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

No branches or pull requests

3 participants