feat: add crop and canvas resize workflows
This commit is contained in:
20
renderer/texture-coordinates.test.ts
Normal file
20
renderer/texture-coordinates.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user