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

Geometry2D Union generates invalid Polygon2D/Self-intersection Inconsistency #99745

Open
RobertBColton opened this issue Nov 27, 2024 · 2 comments

Comments

@RobertBColton
Copy link
Contributor

RobertBColton commented Nov 27, 2024

Tested versions

Reproducible in 4.3 and back in 3.x

System information

Godot v4.3.stable - Windows 10.0.22631 - GLES3 (Compatibility) - NVIDIA GeForce RTX 4050 Laptop GPU (NVIDIA; 32.0.15.6070) - Intel(R) Core(TM) Ultra 7 155H (22 Threads)

Issue description

So I've been experimenting with Polygon2D in the editor and managed to create some shapes that will disappear.
I'm not quite sure what the issue is since the polygon does not intersect itself, but if we move any of the points then it will reappear.

Image
Image

Steps to reproduce

Copy these points into a Polygon2D and notice it doesn't render:

polygon = PackedVector2Array(450, 300, 550, 300, 550, 450, 600, 450, 600, 300, 550, 300, 550, 250, 700.68, 249, 700, 450, 700.68, 506, 449.68, 500)

Minimal reproduction project (MRP)

I gave the points to the Polygon2D in reproduce steps.

@smix8
Copy link
Contributor

smix8 commented Nov 27, 2024

Polygon2D is a single outline with no holes that gets converted to a "real" polygon afterward.
That outline is invalid because vertex1 and vertex5 overlap / cause self intersection / hole creation.

@RobertBColton
Copy link
Contributor Author

RobertBColton commented Nov 27, 2024

Imo, the visual inconsistency in the editor and engine is still a bug and confusing to the user. If you move only point 8 (emphasis eight) to the right or left, all other points ceteris paribus, it will appear/disappear. In other words, if both are invalid (because v1 and v5 still overlap), then both of them should not be drawn.

Further, I feel that if it is kept the same, continues to be treated as "undefined behavior", then it should absolutely be documented in the manual. The other big issue is that nowhere in the manual is self-intersection explained. I feel at the very least a sentence could be added.

It would also be nice to just have a few examples in the manual how to fix a self-intersecting polygon. Perhaps also include a function in the engine that allows us to test whether or not a polygon is self-intersecting. Maybe a warning label in editor too, "this polygon is self-intersecting and may not render."

Finally, I want to explain how I got here. I was using Geometry2D.merge_polygons with axis-aligned rectangles to paint a terrain. They were snapped to a grid and I only accepted the merge when the return size was equal to 1 (no holes). Sometimes the polygons generated do not appear such as the above polygon which was in fact created as a result of this (I deleted a few points to simplify the shape for sharing). I feel like it is an issue that merge_polygons will generate polygons with holes in them that can't render properly.

@RobertBColton RobertBColton changed the title Invisible Simple Polygon2D Geometry2D Union generates invalid Polygon2D/Self-intersection Inconsistency Nov 27, 2024
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