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

Origin-center grids by default; fix a type conversion; update tests #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

evanfields
Copy link

  • Update the tests to ensure some basic behavior. The test coverage is still quite minimal, but nonetheless expanded relative to master. And I think all the behavior tested for should be uncontroversial.
  • Set the default x and y offset for center to be 0, not 1. This means that the zero index hexagon (e.g. HexagonCubic(0, 0, 0)) will be centered at the xy origin. This should fix both inconsistency in cube_round #13 and hexbin misalignment Gadfly.jl#1497 .
  • Fix axial to cubic conversion. The current master has
function convert(::Type{HexagonCubic}, hex::HexagonAxial)
    HexagonCubic(hex.q, hex.r, -hex.q - hex.r)
end

compare to Amit Patel's reference:

function axial_to_cube(hex):
    var x = hex.q
    var z = hex.r
    var y = -x-z
    return Cube(x, y, z)

i.e. the -q-r term should become the cubic y (second argument), but current master puts this term in cubic z.

h_best = neighbor
end
end
h_best
Copy link
Author

Choose a reason for hiding this comment

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

As far as I can tell, this section is no longer necessary with center's default offset at zero, not 1. The redblobgames references doesn't describe this neighbor check code. Seems like this latter loop was previously necessary because all hexagons were shifted by (-1,-1) in Cartesian space, so the shifted hexagon that contains a Cartesian point might not be the unshifted hexagon that contains that point.

With this shift behavior removed, nearest_cubic_hexagon is already returning the correct (0-centered) hexagon for the input point.

@evanfields
Copy link
Author

@bjarthur apologies for the pestering tag but looks like you have merge privileges here and this would fix the downstream Gadfly bug. Let me know if you'd like any changes!

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.

1 participant