Fix for negative spacing

This commit is contained in:
2025-11-18 21:11:26 +01:00
parent f7a01e6c92
commit 57d62db219
4 changed files with 32 additions and 40 deletions

View File

@@ -0,0 +1,21 @@
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);
}