test(cull): add unit test for bounds rebuild on level switch

This commit is contained in:
troytt 2026-09-17 05:48:51 +00:00
parent 4ea77e2c00
commit 80c74a6b95
1 changed files with 24 additions and 0 deletions

View File

@ -77,6 +77,30 @@ describe('视口剔除', () => {
expect(intersects(buildBounds([drawable(120, 0, 1, 1)]), 0, view)).toBe(true)
expect(intersects(buildBounds([drawable(140, 0, 1, 1)]), 0, view)).toBe(false)
})
test('换关卡时重建包围盒避免越界误剔除', () => {
// 模拟从 57x41 关卡(2337 个图元)切换到 80x80 关卡(6400 个图元)
const smallLevelDrawables = Array.from({ length: 2337 }, (_, i) => drawable(i * 10, 0, 80, 40))
const largeLevelDrawables = Array.from({ length: 6400 }, () => drawable(0, 0, 80, 40))
const view = viewportRect(0, 0, 1280, 720, 1)
// 旧实现未重建 bounds,largeLevel 使用 smallLevel 的 stale bounds
const staleBounds = buildBounds(smallLevelDrawables)
let visibleWithStaleBounds = 0
for (let i = 0; i < largeLevelDrawables.length; i += 1) {
if (intersects(staleBounds, i, view)) visibleWithStaleBounds += 1
}
expect(visibleWithStaleBounds).toBeLessThanOrEqual(2337)
// 修复后重建 bounds,所有落在视口内的图元正确通过剔除
const freshBounds = buildBounds(largeLevelDrawables)
let visibleWithFreshBounds = 0
for (let i = 0; i < largeLevelDrawables.length; i += 1) {
if (intersects(freshBounds, i, view)) visibleWithFreshBounds += 1
}
expect(visibleWithFreshBounds).toBe(6400)
})
})
/** 资源包位置;缺资源时整组测试跳过而不是报红。 */