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

Fix offsets in ConvexHull while unsorted being improperly accounted for #7399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Geolykt
Copy link

@Geolykt Geolykt commented May 17, 2024

When using ConvexHull with sorted == false and offset != 0, an ArrayIndexOutOfBoundsException used to occur due to end not being reset properly. This commit fixes this behaviour.

Copy link
Member

@tommyettinger tommyettinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there's a test now, and there wasn't one before. I'll double-check ConvexHull and see if I spot anything else while we're at it. Approving in the meanwhile, since even just adding the test and checking some (maybe all!) of ConvexHull is worthwhile.


import com.badlogic.gdx.utils.FloatArray;

public class ConvexHullTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hooray, there's a test! The assertArraySimilar() seems a little strange, but I'm guessing that's required by the code we're testing here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right - It is a little bit strange, but I wanted to conform to the specification of the computePolygon method, which are rather lax in defining what the first point is (aside that the first point is the last point, but that does not help much) - so just in case the algorithm is slightly altered and the first point might change we just want to check whether the vertices are still anti-clockwise, but not make more assumptions.

Of course, one could make more assumptions (after all, in case of changes we can just revise those assumptions no problem and I don't think the code will contain any kind of randomness, but I did not check that myself) - but I feel like that is a bit inappropriate to do within tests.

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

Successfully merging this pull request may close these issues.

None yet

2 participants