Files
vibemake/tests/assembly-framing.test.js
T

28 lines
1.8 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {Box3,PerspectiveCamera,Vector3} from '../vendor/three/build/three.module.min.js';
import {buildWorkBounds,componentViewDirection,workBoundsFit} from '../js/assembly-framing.js';
const box=(x,y,z,w,h,d)=>new Box3().setFromCenterAndSize(new Vector3(x,y,z),new Vector3(w,h,d));
test('first installed base is framed at the work site, not the center of an invisible completed leg',()=>{
const base=box(0,.03,0,.1,.06,.08),top=box(0,.65,0,.15,.1,.12),whole=base.clone().union(top);
const bounds=buildWorkBounds(new Map([['base',base],['top',top]]),new Set(['base']),whole);
assert.ok(bounds.getCenter(new Vector3()).distanceTo(base.getCenter(new Vector3()))<1e-8);
assert.ok(bounds.getSize(new Vector3()).y<whole.getSize(new Vector3()).y*.3);
const withEntry=buildWorkBounds(new Map([['base',base],['top',top]]),new Set(['base','top']),whole,[{id:'top',offset:new Vector3(0,.1,0)}]);
assert.ok(withEntry.containsBox(top.clone().translate(new Vector3(0,.1,0))));
});
test('paired components use their own outer viewing side without changing the front or elevation',()=>{
const whole=box(0,.5,0,.5,1,.5),left=box(0,.2,-.2,.1,.4,.1),right=box(0,.2,.2,.1,.4,.1);
const a=componentViewDirection(left,whole),b=componentViewDirection(right,whole);
assert.ok(a.x>0&&b.x>0&&a.y>.3&&b.y>.3);
assert.ok(a.z<0&&b.z>0);assert.equal(a.x,b.x);
});
test('only off-frame work requires a new shot, and portrait bounds are checked against the actual camera',()=>{
const camera=new PerspectiveCamera(32,.5,.01,50);
camera.position.set(0,0,2);camera.lookAt(0,0,0);camera.updateProjectionMatrix();
assert.equal(workBoundsFit(box(0,0,0,.2,.2,.2),camera),true);
assert.equal(workBoundsFit(box(0,0,0,1.8,.2,.2),camera),false);
assert.equal(workBoundsFit(box(0,0,3,.2,.2,.2),camera),false);
});