22 lines
842 B
TypeScript
22 lines
842 B
TypeScript
import type { Sprite } from '@/types/sprites';
|
|
import { getMaxDimensions } from './useSprites';
|
|
|
|
/**
|
|
* Calculate negative spacing to add to top-left of cells.
|
|
* Uses half the available space so spacing is equal on all sides.
|
|
*/
|
|
export function calculateNegativeSpacing(sprites: Sprite[], enabled: boolean): number {
|
|
if (!enabled || sprites.length === 0) return 0;
|
|
|
|
const { maxWidth, maxHeight } = getMaxDimensions(sprites);
|
|
const minWidth = Math.min(...sprites.map(s => s.width));
|
|
const minHeight = Math.min(...sprites.map(s => s.height));
|
|
|
|
// Available space is the gap between cell size and smallest sprite
|
|
const availableWidth = maxWidth - minWidth;
|
|
const availableHeight = maxHeight - minHeight;
|
|
|
|
// Use half to balance spacing equally on all sides
|
|
return Math.floor(Math.min(availableWidth, availableHeight) / 2);
|
|
}
|