Files
SpineViewer/tests/visible-bounds.test.js
2026-09-19 11:15:44 +08:00

20 lines
674 B
JavaScript

'use strict';
const assert = require('node:assert/strict');
const { findAlphaBounds, toWorldBounds } = require('../js/spine-visible-bounds');
const pixels = new Uint8Array(10 * 8 * 4);
for (let y = 2; y < 6; y++) {
for (let x = 3; x < 8; x++) pixels[(y * 10 + x) * 4 + 3] = 255;
}
assert.deepEqual(findAlphaBounds(pixels, 10, 8), { left: 3, top: 2, right: 8, bottom: 6 });
assert.deepEqual(toWorldBounds({ left: 3, top: 2, right: 8, bottom: 6 }, 10, 8, 2, 20, 30), {
x: 19,
y: 29,
width: 2.5,
height: 2,
});
assert.equal(findAlphaBounds(new Uint8Array(10 * 8 * 4), 10, 8), null);
console.log('PASS: visible alpha pixels map back to the correct Spine world bounds');