Files
management/Management/tests/interface-direction.test.ts

50 lines
1.8 KiB
TypeScript

import { expect, it } from 'vitest'
import * as THREE from 'three'
import {
createInterfaceDirectionMarker,
disposeInterfaceDirectionMarker,
} from '@/infrastructure/interface-direction'
it('uses the interface Link world transform for marker position and axes', () => {
const model = new THREE.Group()
const parent = new THREE.Group()
parent.position.set(1, 2, 3)
parent.rotation.z = Math.PI / 2
const point = new THREE.Object3D()
point.position.set(2, 0, 0)
parent.add(point)
model.add(parent)
model.updateMatrixWorld(true)
const before = model.toJSON()
const marker = createInterfaceDirectionMarker(model, point)
expect(marker).not.toBeNull()
expect(marker!.getObjectByName('+Y 朝向参考')).toBeUndefined()
expect(marker!.position.x).toBeCloseTo(1)
expect(marker!.position.y).toBeCloseTo(4)
expect(marker!.position.z).toBeCloseTo(3)
const z = new THREE.Vector3(0, 0, 1).applyQuaternion(marker!.quaternion)
const x = new THREE.Vector3(1, 0, 0).applyQuaternion(marker!.quaternion)
expect(z.toArray()).toEqual([0, 0, 1])
expect(x.x).toBeCloseTo(0)
expect(x.y).toBeCloseTo(1)
expect(model.toJSON()).toEqual(before)
disposeInterfaceDirectionMarker(marker!)
expect(marker!.children).toHaveLength(0)
})
it('shows the Y axis only when diagnostic display is enabled', () => {
const model = new THREE.Group()
const point = new THREE.Object3D()
model.add(point)
const marker = createInterfaceDirectionMarker(model, point, 1, { showYAxis: true })
expect(marker?.getObjectByName('+Y 朝向参考')).toBeDefined()
disposeInterfaceDirectionMarker(marker!)
})
it('rejects an interface point from another model', () => {
const model = new THREE.Group()
const other = new THREE.Object3D()
expect(createInterfaceDirectionMarker(model, other)).toBeNull()
})