TOPdesk/grid.scad

22 lines
905 B
OpenSCAD

// functions for easy grid creation
function grid(num_x, num_y, step_x, step_y) = [
for(
x = [0 : GRID_SIZE * step_x : GRID_SIZE * step_x * (num_x - 1)],
y = [0 : GRID_SIZE * step_y : GRID_SIZE * step_y * (num_y - 1)]
) [x, y]
];
// Number of elements spaced out by <step> grid units on a given <length>
// PS: yes, /2 *2 can be killed, but is more explanatory
function grid_elements(length, step=1) = floor((length - ((MODULE_THICKNESS / 2) * 2)) / (GRID_SIZE * step));
// How many grid units are needed to fit <length> within it
function grid_units_length(length) = ceil(length / GRID_SIZE) + 1;
// What length a grid spans in a single dimension
function grid_length(num, step=1) = (num - step) * GRID_SIZE;
// Margin to center a grid of <num> * <step> units in one dimension on length
function grid_margin(length, num, step) = (length - grid_length(num * step, step)) / 2;