From 031df7a4451132d6798ae98e42a7a37b3859ec35 Mon Sep 17 00:00:00 2001 From: xm Date: Tue, 17 Jan 2023 20:54:33 +0100 Subject: [PATCH 1/8] get_hex_line return a wrongly shaped array when the line distance is one hex or below --- hexy/hexy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hexy/hexy.py b/hexy/hexy.py index 7733440..72ce693 100644 --- a/hexy/hexy.py +++ b/hexy/hexy.py @@ -124,7 +124,7 @@ def get_hex_line(hex_start, hex_end): """ hex_distance = get_cube_distance(hex_start, hex_end) if hex_distance < 1: - return np.array([hex_start]) + return hex_start.copy() # Set up linear system to compute linearly interpolated cube points bottom_row = np.array([i / hex_distance for i in np.arange(hex_distance)]) From c7b52c557222b6f36daf3f479bc235e68c20a9b4 Mon Sep 17 00:00:00 2001 From: xm Date: Tue, 17 Jan 2023 20:58:05 +0100 Subject: [PATCH 2/8] semicolons wound pythonystas very badly, save the pythonistas --- test/test_hex_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_hex_line.py b/test/test_hex_line.py index bebe436..b17b829 100644 --- a/test/test_hex_line.py +++ b/test/test_hex_line.py @@ -12,10 +12,10 @@ def test_get_hex_line(): start = np.array([-3, 3, 0]) end = np.array([1, 1, -2]) print(hx.get_hex_line(start, end)) - print(expected); + print(expected) assert(np.array_equal( hx.get_hex_line(start, end), - expected)); + expected)) if __name__ == "__main__": test_get_hex_line() From 8a72660feb50914785c441d4148e3306f35e6e26 Mon Sep 17 00:00:00 2001 From: xm Date: Tue, 17 Jan 2023 21:03:53 +0100 Subject: [PATCH 3/8] Adding test for the one hex line case --- test/test_hex_line.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_hex_line.py b/test/test_hex_line.py index b17b829..5e5d815 100644 --- a/test/test_hex_line.py +++ b/test/test_hex_line.py @@ -16,6 +16,11 @@ def test_get_hex_line(): assert(np.array_equal( hx.get_hex_line(start, end), expected)) + # testing one hex line special case + one_hex_line = hx.get_hex_line(start, start) + assert(np.array_equal(one_hex_line, start)) + assert id(start) != id(one_hex_line) + if __name__ == "__main__": test_get_hex_line() From 8ab7f3bcb450fa644f3fdd953aa97af6e3835482 Mon Sep 17 00:00:00 2001 From: xm Date: Tue, 17 Jan 2023 21:04:19 +0100 Subject: [PATCH 4/8] Duplicate get_spiral test code in test_selection --- test/test_selections.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/test_selections.py b/test/test_selections.py index 842356a..95ca98b 100644 --- a/test/test_selections.py +++ b/test/test_selections.py @@ -47,22 +47,6 @@ def test_get_spiral(): _assert_np_array_equal(actual_array, expected_array) -def test_get_spiral(): - start_radius = 2 - end_radius = 4 - expected = [] - for r in range(start_radius, end_radius + 1): - expected += _get_linear_combinations(hx.W, hx.NW, r) + \ - _get_linear_combinations(hx.NW, hx.NE, r) + \ - _get_linear_combinations(hx.NE, hx.E, r) + \ - _get_linear_combinations(hx.E, hx.SE, r) + \ - _get_linear_combinations(hx.SE, hx.SW, r) + \ - _get_linear_combinations(hx.SW, hx.W, r) - - actual_array = hx.get_spiral([0, 0, 0], start_radius, end_radius) - expected_array = np.array(expected) - _assert_np_array_equal(actual_array, expected_array) - def test_get_disk(): expected = [[0, 0, 0]] From dd3a0e1e6c85b27db9e0dcd271e85c96269c93ec Mon Sep 17 00:00:00 2001 From: xm Date: Tue, 17 Jan 2023 21:06:34 +0100 Subject: [PATCH 5/8] semicolons wound pythonystas very badly, really, they do... save the pythonistas --- test/test_rounding.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_rounding.py b/test/test_rounding.py index 7db7298..8ffc365 100644 --- a/test/test_rounding.py +++ b/test/test_rounding.py @@ -5,12 +5,12 @@ def test_cube_round(): test_coords = np.array([ [1.1, -1.4, 0.3], [3.3, 2.3, -5.4], - ]); + ]) expected_coords = np.array([ [1, -1, 0], [3, 2, -5], - ]); + ]) assert(np.array_equal(hx.cube_round(test_coords), expected_coords)) @@ -18,11 +18,11 @@ def test_axial_round(): test_coords = np.array([ [1.1, -1.4], [3.3, 2.3], - ]); + ]) expected_coords = np.array([ [1, -1], [3, 2], - ]); + ]) assert(np.array_equal(hx.axial_round(test_coords), expected_coords)) From b120a5a874864e5797e4b0bcff6d325d0d3eedf5 Mon Sep 17 00:00:00 2001 From: xm Date: Sat, 28 Jan 2023 12:27:39 +0100 Subject: [PATCH 6/8] Add investigative TODO --- hexy/hexy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hexy/hexy.py b/hexy/hexy.py index 72ce693..931a753 100644 --- a/hexy/hexy.py +++ b/hexy/hexy.py @@ -115,7 +115,7 @@ def get_spiral(center, radius_start=1, radius_end=2): return np.array(hex_area) -def get_hex_line(hex_start, hex_end): +def get_hex_line(hex_start, hex_end): # TODO start and end seems to not be commutative, why ? """ Get hexes on line from hex_start to hex_end. :param hex_start: The hex where the line starts. From ace07daea1d4f3b5af022d2f67e78eb795efec80 Mon Sep 17 00:00:00 2001 From: xm Date: Sat, 28 Jan 2023 13:44:31 +0100 Subject: [PATCH 7/8] In the case of a line reduced to a dot we have to return a 2D array of hexes not just the hex --- hexy/hexy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hexy/hexy.py b/hexy/hexy.py index 931a753..09444b8 100644 --- a/hexy/hexy.py +++ b/hexy/hexy.py @@ -124,7 +124,7 @@ def get_hex_line(hex_start, hex_end): # TODO start and end seems to not be commu """ hex_distance = get_cube_distance(hex_start, hex_end) if hex_distance < 1: - return hex_start.copy() + return np.array([hex_start.copy()]) # Set up linear system to compute linearly interpolated cube points bottom_row = np.array([i / hex_distance for i in np.arange(hex_distance)]) From 0f90b4e963734bbb3e1353c416b9251b439c851f Mon Sep 17 00:00:00 2001 From: xm Date: Sat, 11 Feb 2023 15:28:22 +0100 Subject: [PATCH 8/8] Forget to fix test, assumption was made that returning a one hex line or a many hex line should return a numpy array shapped the same (i.e. dimension 2)) --- test/test_base_map.py | 0 test/test_hex_line.py | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/test_base_map.py diff --git a/test/test_base_map.py b/test/test_base_map.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_hex_line.py b/test/test_hex_line.py index 5e5d815..b80712d 100644 --- a/test/test_hex_line.py +++ b/test/test_hex_line.py @@ -18,7 +18,8 @@ def test_get_hex_line(): expected)) # testing one hex line special case one_hex_line = hx.get_hex_line(start, start) - assert(np.array_equal(one_hex_line, start)) + assert len(one_hex_line) == 1 + assert(np.array_equal(one_hex_line[0], start)) assert id(start) != id(one_hex_line)