Skip to content

Commit

Permalink
ensure grid is properly tiled
Browse files Browse the repository at this point in the history
  • Loading branch information
rhayes777 committed Nov 11, 2024
1 parent 99ab78c commit c126627
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
17 changes: 6 additions & 11 deletions autoarray/structures/triangles/abstract_coordinate_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,18 @@ def for_limits_and_scale(
scale: float = 1.0,
**_,
):
x_shift = int(2 * x_min / scale)
y_shift = int(y_min / (HEIGHT_FACTOR * scale))

coordinates = []
x = x_min
while x < x_max:
y = y_min
while y < y_max:
coordinates.append([x, y])
y += scale
x += scale

x_mean = (x_min + x_max) / 2
y_mean = (y_min + y_max) / 2
for x in range(x_shift, int(2 * x_max / scale) + 1):
for y in range(y_shift - 1, int(y_max / (HEIGHT_FACTOR * scale)) + 2):
coordinates.append([x, y])

return cls(
coordinates=np.array(coordinates),
side_length=scale,
x_offset=x_mean,
y_offset=y_mean,
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,21 @@ def test_triangles_touch():
np.array([[0, 0], [0, 1]]),
)
assert max(triangles.triangles[0][:, 1]) == min(triangles.triangles[1][:, 1])


def test_from_grid_regression():
triangles = CoordinateArrayTriangles.for_limits_and_scale(
x_min=-4.75,
x_max=4.75,
y_min=-4.75,
y_max=4.75,
scale=0.5,
)

x = triangles.vertices[:, 0]
assert min(x) <= -4.75
assert max(x) >= 4.75

y = triangles.vertices[:, 1]
assert min(y) <= -4.75
assert max(y) >= 4.75

0 comments on commit c126627

Please sign in to comment.