21 lines
870 B
TypeScript
21 lines
870 B
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { textureCoordinatesForCrop, textureCoordinatesForRect } from "./texture-coordinates";
|
|
|
|
describe("texture coordinates", () => {
|
|
test("maps an asset-pixel crop to normalized UVs", () => {
|
|
expect(rounded(textureCoordinatesForCrop({ w: 200, h: 100 }, { x: 50, y: 10, w: 100, h: 40 }))).toEqual([
|
|
0.25, 0.1, 0.75, 0.1, 0.25, 0.5, 0.25, 0.5, 0.75, 0.1, 0.75, 0.5,
|
|
]);
|
|
});
|
|
|
|
test("maps cropped content onto the corresponding region of an aligned full-size mask", () => {
|
|
expect(rounded(textureCoordinatesForRect({ x: 50, y: 20, w: 100, h: 40 }, { x: 0, y: 0, w: 200, h: 100 }))).toEqual([
|
|
0.25, 0.2, 0.75, 0.2, 0.25, 0.6, 0.25, 0.6, 0.75, 0.2, 0.75, 0.6,
|
|
]);
|
|
});
|
|
});
|
|
|
|
function rounded(values: Float32Array) {
|
|
return [...values].map((value) => Math.round(value * 1_000) / 1_000);
|
|
}
|