-
Notifications
You must be signed in to change notification settings - Fork 12
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
evanfields
wants to merge
3
commits into
GiovineItalia:master
Choose a base branch
from
evanfields:ef_zero_center
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,42 @@ | ||
using Hexagons | ||
using Test | ||
using Random: seed! | ||
using Statistics: mean | ||
|
||
convert(HexagonOffsetOddR, HexagonAxial(2, 4)) | ||
|
||
x, y = center(HexagonAxial(2, 3)) | ||
@test isapprox(x,7.06217782649107) | ||
@test isapprox(y,5.5) | ||
|
||
h = cube_round(23.5, 4.67) | ||
|
||
collect(vertices(HexagonAxial(2, 3))) | ||
# Test a few identities for the hexagon containing the point x, y | ||
function run_point_test(x, y) | ||
hex_cubic = cube_round(x, y) | ||
verts = collect(vertices(hex_cubic)) | ||
# x,y should be in the bounding box of the hexagon vertices | ||
@test minimum(v[1] for v in verts) <= x <= maximum(v[1] for v in verts) | ||
@test minimum(v[2] for v in verts) <= y <= maximum(v[2] for v in verts) | ||
# the center of the hexagon should be near its vertex mean | ||
mean_vert_x = mean(v[1] for v in verts) | ||
mean_vert_y = mean(v[2] for v in verts) | ||
hex_center = center(hex_cubic) | ||
@test isapprox(hex_center[1], mean_vert_x; atol = 1e-6) | ||
@test isapprox(hex_center[2], mean_vert_y; atol = 1e-6) | ||
# a string of type conversions should recover hex_cubic | ||
hex_axial = convert(HexagonAxial, hex_cubic) | ||
hex_offset = convert(HexagonOffsetOddR, hex_axial) | ||
other_hex_cubic = convert(HexagonCubic, hex_offset) | ||
@test other_hex_cubic == hex_cubic | ||
end | ||
|
||
test_points = [ | ||
(0, 0), | ||
(1, 1), | ||
(1, -1), | ||
(0, 47), | ||
(-4.7, 0), | ||
(1.234, 5.678), | ||
(1e6, 2e6), | ||
] | ||
# bunch of random test points | ||
seed!(1234) | ||
for _ in 1:1000 | ||
push!(test_points, (rand() * 100, rand() * 100)) | ||
end | ||
for point in test_points | ||
run_point_test(point...) | ||
end |
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.
There was a problem hiding this comment.
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.