From 45fbfae243a6864be54ef8665bcd23697e3e2863 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Fri, 1 May 2026 17:57:40 +0200 Subject: [PATCH] auto-git: [change] tests/domain/terrains.test.ts --- tests/domain/terrains.test.ts | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/domain/terrains.test.ts b/tests/domain/terrains.test.ts index b8cb35ca..4a4665fe 100644 --- a/tests/domain/terrains.test.ts +++ b/tests/domain/terrains.test.ts @@ -1,7 +1,9 @@ import { describe, expect, it } from "vitest"; import { + getTerrainBounds, getTerrainPaintWeightSampleOffset, + updateTerrainBoundsCacheAfterHeightPatch, resizeTerrainGrid, createTerrain } from "../../src/document/terrains"; @@ -61,3 +63,50 @@ describe("terrain grid resizing", () => { expect(terrain.heights).toEqual([0, 2, 4, 6]); }); }); + +describe("terrain bounds cache", () => { + it("updates cached bounds after in-place height patches", () => { + const terrain = createTerrain({ + id: "terrain-bounds-cache-grow", + position: { x: 0, y: 1, z: 0 }, + sampleCountX: 2, + sampleCountZ: 2, + cellSize: 1, + heights: [0, 1, 2, 3] + }); + + expect(getTerrainBounds(terrain).max.y).toBe(4); + + terrain.heights[0] = -5; + terrain.heights[1] = 6; + updateTerrainBoundsCacheAfterHeightPatch(terrain, [ + { index: 0, before: 0, after: -5 }, + { index: 1, before: 1, after: 6 } + ]); + + expect(getTerrainBounds(terrain)).toEqual({ + min: { x: 0, y: -4, z: 0 }, + max: { x: 1, y: 7, z: 1 } + }); + }); + + it("rescans cached bounds when the previous extremum is reduced", () => { + const terrain = createTerrain({ + id: "terrain-bounds-cache-rescan", + position: { x: 0, y: 0, z: 0 }, + sampleCountX: 2, + sampleCountZ: 2, + cellSize: 1, + heights: [0, 1, 2, 3] + }); + + expect(getTerrainBounds(terrain).max.y).toBe(3); + + terrain.heights[3] = 0.5; + updateTerrainBoundsCacheAfterHeightPatch(terrain, [ + { index: 3, before: 3, after: 0.5 } + ]); + + expect(getTerrainBounds(terrain).max.y).toBe(2); + }); +});