Grid with a different number of points per side
hellcastter opened this issue · 0 comments
hellcastter commented
It seems like current implementation has no opportunity to create an evenly spaced grid, or just a grid with a different number of points per side. I came up with this solution.
def build_point_grid(n_per_x_side: int, n_per_y_side: int, n_layers: int, scale_per_layer: int) -> np.ndarray:
"""Generates a 2D grid of points evenly spaced"""
x_min, x_max = 0, 1
y_min, y_max = 0, 1
points_list = []
for _ in range(n_layers + 1):
x_offset = (x_max - x_min) / (2 * n_per_x_side)
y_offset = (y_max - y_min) / (2 * n_per_y_side)
points_x = np.linspace(x_min + x_offset, x_max - x_offset, n_per_x_side)
points_y = np.linspace(y_min + y_offset, y_max - y_offset, n_per_y_side)
points_grid = np.stack(np.meshgrid(points_x, points_y), axis=-1)
points = points_grid.reshape(-1, 2)
points_list.append(points)
n_per_x_side //= scale_per_layer
n_per_y_side //= scale_per_layer
return points_list
I think it's good to add this to implementation and change points_per_side to points_per_side (int or tuple[2] or None)