/**
 * The relief ramp, and the camera's contract with it.
 *
 * Extracted so the FiDi landing cannot silently look at a point in the air
 * again. At 3.4 km the ground group is at 5.78/15; a target still written at
 * baked 15x hangs 2.6x above the city.
 */

import assert from "node:assert/strict";
import { describe, it } from "node:test";

import {
  RELIEF_FAR_M,
  RELIEF_NEAR_M,
  reliefScaleAt,
  surfaceWorldY,
} from "../../engine/relief.ts";

const BUILT = 15;
const NEAR = 5.78;

describe("reliefScaleAt", () => {
  it("is 1 at the state pose, so every capture of the whole board is untouched", () => {
    assert.equal(reliefScaleAt(1_551_000, NEAR, BUILT), 1);
    assert.equal(reliefScaleAt(RELIEF_FAR_M, NEAR, BUILT), 1);
  });

  it("is near/built once you are inside a city", () => {
    const wanted = NEAR / BUILT;
    assert.ok(Math.abs(reliefScaleAt(RELIEF_NEAR_M, NEAR, BUILT) - wanted) < 1e-9);
    // FiDi on the merged board, restated: ~3.4 km.
    assert.ok(Math.abs(reliefScaleAt(3_400, NEAR, BUILT) - wanted) < 1e-9);
    assert.ok(Math.abs(reliefScaleAt(2_500, NEAR, BUILT) - wanted) < 1e-9);
  });

  it("does not ramp a pack that asked for one exaggeration", () => {
    assert.equal(reliefScaleAt(3_400, 5.78, 5.78), 1);
  });
});

describe("surfaceWorldY", () => {
  it("puts the look-at on the scaled surface, not in the air above it", () => {
    const baked = 2.0; // scene units of 15x ground
    const scale = NEAR / BUILT;
    const worldY = surfaceWorldY(baked, scale);
    assert.ok(Math.abs(worldY - baked * scale) < 1e-12);
    assert.ok(worldY < baked, "the ramped surface is lower than the baked one");
  });
});
