32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import * as THREE from 'three'
|
|
import {
|
|
domLabelBoundsOverlap,
|
|
getDomLabelBounds,
|
|
isDomLabelWithinViewport,
|
|
projectObjectToDom
|
|
} from '@/components/map/poiDomLabels'
|
|
|
|
describe('POI DOM label projection and collision', () => {
|
|
it('projects a world-space anchor to CSS pixels', () => {
|
|
const camera = new THREE.PerspectiveCamera(60, 2, 0.1, 100)
|
|
camera.position.set(0, 0, 10)
|
|
camera.lookAt(0, 0, 0)
|
|
camera.updateProjectionMatrix()
|
|
camera.updateMatrixWorld()
|
|
|
|
const anchor = new THREE.Object3D()
|
|
anchor.position.set(0, 0, 0)
|
|
expect(projectObjectToDom(anchor, camera, 390, 195)).toEqual({ x: 195, y: 97.5 })
|
|
})
|
|
|
|
it('uses measured DOM dimensions for bottom-anchored overlap checks', () => {
|
|
const hall = getDomLabelBounds({ x: 120, y: 100 }, { width: 146, height: 38 }, 'bottom')
|
|
const facility = getDomLabelBounds({ x: 240, y: 100 }, { width: 88, height: 32 }, 'bottom')
|
|
|
|
expect(domLabelBoundsOverlap(hall, facility, 6)).toBe(true)
|
|
expect(isDomLabelWithinViewport(hall, 390, 844)).toBe(true)
|
|
expect(isDomLabelWithinViewport(getDomLabelBounds({ x: 5, y: 10 }, { width: 88, height: 32 }, 'bottom'), 390, 844)).toBe(false)
|
|
})
|
|
})
|