Files
zyt/TUICallKit-Vue3/training/pose/__tests__/viewport.test.ts
T
long c3f4d726e0 feat: 新增 AI 跟练(训练分包)
- 页面:pose-hub 选择动作,pose-coach 跟练(教练小甄示范 + 摄像头动作识别计数)
- 动作:徒手深蹲、原地高抬腿、低冲击开合、站姿侧平举
- VisionKit 人体识别,按动作幅度计数、评分、纠错;没有摄像头或识别不可用时自动进入领练模式
- 教练逐帧动画:分包内置 600px 帧,COS 高清帧全部加载完后无缝切换
- 语音报数与口令(WechatSI),舒缓背景音乐(COS,教练说话时自动压低,可关闭)
- 逻辑单测:npm run test:pose
2026-10-31 10:33:25 +08:00

27 lines
1.1 KiB
TypeScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { toScreen } from '../viewport.ts'
const near = (a: number, b: number) => Math.abs(a - b) < 1e-6
test('比例一致时直接按尺寸缩放', () => {
const p = toScreen({ x: 0.25, y: 0.5 }, { width: 300, height: 400, frameWidth: 480, frameHeight: 640, mirror: false })
assert.ok(near(p.x, 75) && near(p.y, 200))
})
test('全屏竖屏按 aspectFill 裁掉左右两边,画面中心仍在屏幕中心', () => {
const vp = { width: 390, height: 844, frameWidth: 480, frameHeight: 640, mirror: false }
const c = toScreen({ x: 0.5, y: 0.5 }, vp)
assert.ok(near(c.x, 195) && near(c.y, 422))
const top = toScreen({ x: 0.5, y: 0 }, vp)
assert.ok(near(top.y, 0), '高度方向不裁剪')
const left = toScreen({ x: 0, y: 0.5 }, vp)
assert.ok(left.x < 0, '宽度方向被裁掉的部分落在屏幕外')
})
test('镜像预览左右翻转', () => {
const vp = { width: 300, height: 400, frameWidth: 480, frameHeight: 640, mirror: true }
const p = toScreen({ x: 0.2, y: 0.3 }, vp)
assert.ok(near(p.x, 240) && near(p.y, 120))
})