Open History to see the last commit
1import { PerspectiveCamera, Texture, Vector3 } from "three";
2import { describe, expect, it } from "vite-plus/test";
3import { createAndroidFoldScene } from "./androidFoldScene.ts";
4import { phoneDisplayLayout } from "./phoneScene.ts";
5
6describe("Android fold scene", () => {
7 it("maps touches on each open half and the closed cover to the live frame", () => {
8 const texture = new Texture();
9 const scene = createAndroidFoldScene(texture, phoneDisplayLayout(null, 2200, 1840), 180);
10 const camera = new PerspectiveCamera(32, 1, 0.1, 30);
11 camera.position.z = 6;
12 camera.updateMatrixWorld(true);
13 const project = (x: number) => {
14 const point = new Vector3(x, 0, 0.041).project(camera);
15 return scene.screenPoint((point.x + 1) / 2, (1 - point.y) / 2, camera);
16 };
17 expect(project(-0.52)?.x).toBeCloseTo(0.25, 1);
18 expect(project(0.52)?.x).toBeCloseTo(0.75, 1);
19 expect(scene.screenPoint(0.99, 0.5, camera, true)?.x).toBe(1);
20 scene.setAngle(0);
21 expect(project(0.52)?.x).toBeCloseTo(0.5, 1);
22 scene.dispose();
23 texture.dispose();
24 });
25});