aboutsummaryrefslogtreecommitdiff
path: root/test/domains/box-test.ts
blob: 248ae38d0a449e4c0ea5ae9a5329116212eacfb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { test, describe } from "node:test";
import assert from "node:assert/strict";
import { centreOf } from "../../src/domains/box";

describe("box centre", () => {
  test("computes the centre from a content quad", () => {
    const b = centreOf({ content: [10, 20, 110, 20, 110, 70, 10, 70], width: 100, height: 50 });
    assert.equal(b.x, 10);
    assert.equal(b.y, 20);
    assert.equal(b.cx, 60);
    assert.equal(b.cy, 45);
    assert.equal(b.width, 100);
    assert.equal(b.height, 50);
  });

  test("a degenerate zero-size quad yields its own corner, not NaN", () => {
    const b = centreOf({ content: [5, 5, 5, 5, 5, 5, 5, 5], width: 0, height: 0 });
    assert.equal(b.cx, 5);
    assert.equal(b.cy, 5);
    assert.ok(!Number.isNaN(b.cx));
  });
});