// The world is drawn onto a grid of character cells, so these are the two lengths
// that tie the two grids together, and the only two the camera may not invent.
export const CELL = 12; // css px per character cell
export const CELL_WORLD = 2; // world units per character cell at zoom 1
export const ZOOM_MIN = 0.5; // furthest out: far enough to frame a whole system
export const ZOOM_MAX = 1.8; // closest in
// The galaxy map is the same camera over a much wider frame: a whole galaxy of
// ~6100 world units fits even a short window at ~167 world units to the cell, and
// the closest it goes still holds a third of the galaxy in view, so the map never
// zooms into the empty space between its own marks. The two ranges do not meet, so
// no zoom level drifts between the scenes.
export const GALAXY_MIN = 0.012;
export const GALAXY_MAX = 0.05;

// Snap a world point to the centre of the cell that holds it: a one-cell mark has
// to land on a glyph, not straddle four of them. The cell grid hangs off the
// camera, so it is half a cell out from it whenever the canvas holds an odd number
// of cells: `n` is that count, and passing it keeps the snap on the raster. Rows
// count the other way from a world y, so the vertical snap passes sign = -1.
export const snapCell = (v: number, c: number, wpc: number, n: number, sign = 1) =>
  c + sign * (Math.floor(((v - c) * sign) / wpc + n / 2) + 0.5 - n / 2) * wpc;
