Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Compare the frozen walker within rounding error, not bit for bit

Claude70d5d7ca0641
diff --git a/test/near.ts b/test/near.ts
new file mode 100644
index 0000000..249110c
--- /dev/null
+++ b/test/near.ts
@@ -0,0 +1,21 @@
+import assert from "node:assert/strict"
+
+/**
+ * deepEqual, but numbers may differ by a rounding error. The frozen baselines
+ * were drawn on another machine, and Math.sin/cos may round the last bit
+ * differently across CPUs, so an unchanged model can differ by one ULP.
+ */
+export const assertNear=(actual:unknown,expected:unknown,path="",tolerance=1e-9):void=>{
+ if(typeof actual==="number"&&typeof expected==="number"){
+ assert.ok(Math.abs(actual-expected)<=tolerance,`${path}: ${actual} ≠ ${expected}`)
+ return
+ }
+ if(typeof actual!=="object"||actual===null||typeof expected!=="object"||expected===null){
+ assert.equal(actual,expected,path)
+ return
+ }
+ assert.equal(Array.isArray(actual),Array.isArray(expected),path)
+ const a=actual as Record<string,unknown>,e=expected as Record<string,unknown>
+ assert.deepEqual(Object.keys(a).sort(),Object.keys(e).sort(),path)
+ for(const k of Object.keys(e))assertNear(a[k],e[k],`${path}/${k}`,tolerance)
+}
diff --git a/test/park-models.test.ts b/test/park-models.test.ts
index 2a0c42d..c18aeca 100644
--- a/test/park-models.test.ts
+++ b/test/park-models.test.ts
@@ -9,6 +9,7 @@ import { parkAsset, parkProp } from "../src/asset-lab/town-props.ts"
import { parkReviewModels } from "../src/model-review/park-models.ts"
import { human } from "../src/asset-lab/dimensions.ts"
import { DIRS, key } from "../src/grid.ts"
+import { assertNear } from "./near.ts"
const baseline=JSON.parse(gunzipSync(readFileSync(new URL("../public/model-review/parks-before.json.gz",import.meta.url))).toString()) as {revision:string;models:InkAsset[];walker:InkAsset}
const points=(a:InkAsset)=>[...a.faces,...a.strokes].flatMap(f=>f.points)
@@ -19,8 +20,8 @@ test("park comparisons retain the approved originals, plots and unchanged person
const current=parkReviewModels()
assert.equal(current.length,12)
assert.deepEqual(current.map(a=>[a.id,a.footprint]),baseline.models.map(a=>[a.id,a.footprint]))
- assert.deepEqual(baseline.walker.faces,assetById.get("settler-cap")!.faces)
- assert.deepEqual(baseline.walker.strokes,assetById.get("settler-cap")!.strokes)
+ assertNear(assetById.get("settler-cap")!.faces,baseline.walker.faces,"walker.faces")
+ assertNear(assetById.get("settler-cap")!.strokes,baseline.walker.strokes,"walker.strokes")
})
test("furnishings stay within one cell and use the town's human scale",()=>{
diff --git a/test/proportions.test.ts b/test/proportions.test.ts
index 763c46c..ca97d2e 100644
--- a/test/proportions.test.ts
+++ b/test/proportions.test.ts
@@ -10,6 +10,7 @@ import { sides, type InkAsset } from "../src/asset-lab/primitives.ts"
import { buildingAsset, buildingTop, noDoors } from "../src/render3d/models.ts"
import { architectureIds, proportionModels } from "../src/model-review/proportion-models.ts"
import { vertex3 } from "../src/asset-lab/renderer.ts"
+import { assertNear } from "./near.ts"
const baseline=JSON.parse(gunzipSync(readFileSync(new URL("../public/model-review/proportions-before.json.gz",import.meta.url))).toString()) as {revision:string;models:InkAsset[];walker:InkAsset}
const points=(a:InkAsset)=>[...a.faces,...a.strokes].flatMap(f=>f.points)
@@ -23,8 +24,8 @@ test("every comparison uses the approved frozen baseline and the exact unchanged
assert.equal(current.length,45)
assert.deepEqual(new Set(current.map(a=>a.id)),new Set(baseline.models.map(a=>a.id)))
for(const a of current)assert.equal(a.footprint,baseline.models.find(b=>a.id===b.id)!.footprint,`${a.id}: plot changed`)
- assert.deepEqual(walker.faces,baseline.walker.faces)
- assert.deepEqual(walker.strokes,baseline.walker.strokes)
+ assertNear(walker.faces,baseline.walker.faces,"walker.faces")
+ assertNear(walker.strokes,baseline.walker.strokes,"walker.strokes")
})
test("all home tiers have door and floor clearance for a walker in every orientation",()=>{