mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 10:00:57 +00:00
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:
parent
1dd02f7a75
commit
8ff12c9883
|
|
@ -106,15 +106,24 @@ function clusteredCellsDensity(numbers, size, minDensity) {
|
|||
}
|
||||
|
||||
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)
|
||||
x: Math.max(0, col) * (tileSize + gap),
|
||||
y: Math.max(0, row) * (tileSize + gap)
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user