-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from RedFT/more_readable_get_disk
get_disk function is more readable now
- Loading branch information
Showing
1 changed file
with
6 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,31 +64,26 @@ def get_ring(center, radius): | |
|
||
def get_disk(center, radius): | ||
""" | ||
Retrieves the locations of all the hexes within certain distance from a hexagon. | ||
Retrieves the locations of all the hexes within `radius` hexes from a hexagon. | ||
:param center: The location of the hexagon to get the neighbors of. | ||
:param radius: The distance from `center` of the hexes we want. | ||
:return: An array of locations of the hexes that are within `radius` units away from `center`. | ||
""" | ||
hex_set = [] | ||
for x in range(-radius, radius + 1): | ||
for y in range(max(-radius, -(x + radius)), min(radius + 1, -x + radius + 1)): | ||
z = -x - y | ||
hex_set.append(np.array([x, y, z])) | ||
return np.array(hex_set) + center | ||
return get_spiral(center, 0, radius) | ||
|
||
|
||
def get_spiral(center, radius_start=1, radius_end=2): | ||
""" | ||
Retrieves all hexes that are `radius` hexes away from the `center`. | ||
Retrieves all hexes that are between `radius_start` and `radius_end` hexes away from the `center`. | ||
:param center: The location of the center hex. | ||
:param radius_start: The distance from center. We want all hexes greater than or equal to this distance. | ||
:param radius_end: The distance from center. We want all hexes within this distance from `center`. | ||
:return: An array of locations of the hexes that are within `radius` hexes away from `center`. | ||
""" | ||
hex_area = get_ring(center, 0) | ||
for i in range(radius_start, radius_end + 1): | ||
hex_area = get_ring(center, radius_start) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
RedFT
Author
Owner
|
||
for i in range(radius_start + 1, radius_end + 1): | ||
hex_area = np.append(hex_area, get_ring(center, i), axis=0) | ||
return hex_area | ||
return np.array(hex_area) | ||
|
||
|
||
def get_hex_line(hex_start, hex_end): | ||
|
That one got me. I was relying on the example code (RedFT/HexyExamples/) using
get_spiral(center, 1, n)
, and suddenly index0, 0, 0
ceased to exists.