Update lib/extramath.js

Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com>
This commit is contained in:
Namhyeon Go 2025-08-20 17:29:44 +09:00 committed by GitHub
parent 1dd02f7a75
commit 8ff12c9883
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -105,16 +105,25 @@ function clusteredCellsDensity(numbers, size, minDensity) {
return density >= minDensity;
}
function estimateTileStartPosition(index, tiles, spreadSize, gap) {
function estimateTileStartPosition(index, tiles, spreadSize, gap) {
if (typeof tiles !== 'number' || tiles <= 0) return null;
if (typeof spreadSize !== 'number' || !isFinite(spreadSize)) return null;
if (typeof gap !== 'number' || !isFinite(gap) || gap < 0) gap = 0;
if (typeof index !== 'number' || !isFinite(index) || index % 1 !== 0 || index < 1) return null;
var totalSlots = tiles * tiles;
if (index > totalSlots) return null;
var tileSize = (spreadSize - gap * (tiles - 1)) / tiles;
if (!isFinite(tileSize)) return null;
var i = index - 1;
var col = i % tiles;
var row = Math.floor(i / tiles);
return {
x: col * (tileSize + gap),
y: row * (tileSize + gap)
return {
x: Math.max(0, col) * (tileSize + gap),
y: Math.max(0, row) * (tileSize + gap)
};
}