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

Geometry.is_polygon_clockwise seems to return the opposite of expected results #49716

Open
davidscholberg opened this issue Jun 18, 2021 · 3 comments · May be fixed by #89635
Open

Geometry.is_polygon_clockwise seems to return the opposite of expected results #49716

davidscholberg opened this issue Jun 18, 2021 · 3 comments · May be fixed by #89635

Comments

@davidscholberg
Copy link

Godot version

v3.3.2.stable.official

System information

Windows 10, GLES3, GeForce GTX 1070/PCIe/SSE2

Issue description

The results of Geometry.is_polygon_clockwise seem consistent with a cartesian coordinate system where the Y axis grows upwards. However, I was under the impression that 2D graphics in Godot used a coordinate system where the Y axis grows downward, and since Geometry.is_polygon_clockwise is an inherently 2D function, the results given seem to be the opposite of what I would have expected.

Steps to reproduce

  1. Add the following line to any node script and observe that the output is True, which is not consistent with the 2D coordinate system that Godot uses with the Y axis growing downward.
print(str(Geometry.is_polygon_clockwise(PoolVector2Array([Vector2(-1, -1), Vector2(-1, 1), Vector2(1, 1), Vector2(1, -1)]))))

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Jun 18, 2021

cc @Xrayez

@Xrayez
Copy link
Contributor

Xrayez commented Jun 18, 2021

It looks like a bug to me. I have previously exposed this method to scripting in #28987, but I never really paid attention to result because nowadays I'm calculating polygon's signed area to determine the orientation in my code.

See also #30251 which can be added as an alternative to is_polygon_clockwise(), because orientation could be computed via area alone, and computing area will be more useful for other stuff, so we could remove is_polygon_clockwise() in Godot 4.0:

var clockwise = Geometry.polygon_area(polygon) < 0           # aka Hole
var counter_clockwise = Geometry.polygon_area(polygon) > 0   # aka Boundary

See also #53574 (comment).

@markopolojorgensen
Copy link

Just ran into this issue using godot 4.0.1. If is_polygon_clockwise is going to remain accessible via script, would it be better to change what it's returning or update documentation to let users know? I understand if it's low priority, seems like it's only affected three or four people in ~2 years.

exodrifter added a commit to exodrifter/godot that referenced this issue Jul 29, 2023
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This caused it to return the incorrect value, since Godot
treats the y-axis as being positive in the down direction.

All existing uses of `is_polygon_clockwise` have been updated
in a way which preserves the existing behavior with the comments being
updated to refer to the correct winding order.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Jul 29, 2023
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This caused it to return the incorrect value, since Godot
treats the y-axis as being positive in the down direction.

All existing uses of `is_polygon_clockwise` have been updated
in a way which preserves the existing behavior with the comments being
updated to refer to the correct winding order.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Jul 30, 2023
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This caused it to return the incorrect value, since Godot
treats the y-axis as being positive in the down direction.

All existing uses of `is_polygon_clockwise` have been updated
in a way which preserves the existing behavior with the comments being
updated to refer to the correct winding order.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Jan 15, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This caused it to return the incorrect value, since Godot
treats the y-axis as being positive in the down direction.

All existing uses of `is_polygon_clockwise` have been updated
in a way which preserves the existing behavior with the comments being
updated to refer to the correct winding order.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Feb 24, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This caused it to return the incorrect value, since Godot
treats the y-axis as being positive in the down direction.

All existing uses of `is_polygon_clockwise` have been updated
in a way which preserves the existing behavior with the comments being
updated to refer to the correct winding order.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 18, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 18, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
@exodrifter exodrifter linked a pull request Mar 18, 2024 that will close this issue
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 18, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 18, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 18, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 19, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 20, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 20, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 20, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
exodrifter added a commit to exodrifter/godot that referenced this issue Mar 20, 2024
When this was originally implemented in
16022da, the implementation treated the
vertices as being in a space where the y-axis is positive in the up
direction. This causes it to return the incorrect value for 2D games,
since Godot treats the y-axis as being positive in the down direction.

This change maintains compatibility with existing uses of
`is_polygon_clockwise` by adding an optional parameter which allows the
user to select which handedness their coordinate system uses. The
documentation for `is_polygon_clockwise` has also been updated to
describe the difference.

Fixes godotengine#49716.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants