Repository navigation
Keep q + r + s at 0 in hexagon.lerp() and line() - #3003
Open
SwastikTripathi wants to merge 1 commit into
Open
SwastikTripathi wants to merge 1 commit into
SwastikTripathi wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3002.
hexagon.lerp()interpolatedq,randsseparately, andline()nudged all three, so for coordinates past about 20 the three floats could sum to a rounding error like 1.4e-14.HexTile.__post_init__only accepts a sum within 1e-14 of 0, soline()andHexTile.lerp_between()raisedAssertionError: q + r + s must be 0for most pairs of hexagons on a map of any real size.Both now build the tile from
qandrand derives = -q - r(a small_from_qrhelper), which makesq + r + sexactly 0. The values are the same as before up to that rounding, soround()and the line's hexes don't change.Tests:
test_hex_line_draw_far_apart: the line between (22, 47, -69) and (-42, -18, 60) starts and ends on them, hasdistance + 1hexes and steps one hex at a time, and a line to (5000, -1234, -3766) works too.test_hex_lerp_keeps_cube_sum:lerp_betweenat t = 0, 0.1, ..., 1 keeps the sum at 0.developmentand pass with the change.tests/unit/test_hexagon.pypasses (18 tests). With random hexagon pairs,line()failed for 51% of pairs with coordinates up to 50 and 99.9% up to 500 before, and 0 of 4000 after.ruff check,ruff format --checkandmypy arcade/hexagon.pyare clean. I added a line to the changelog.