20 lines
718 B
TypeScript
20 lines
718 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));
|
|
|
|
const availableWidth = maxWidth - minWidth;
|
|
const availableHeight = maxHeight - minHeight;
|
|
|
|
return Math.floor(Math.min(availableWidth, availableHeight) / 2);
|
|
}
|