t03-camera-contract.mjs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /**
  2. * T03 逻辑检查:三键相机契约、旋转中心规则与阻尼(票 03 / ADR 0008)。
  3. *
  4. * 仓库没有测试运行器,且项目约定不为验证引入新框架,所以这里用零依赖 Node 断言脚本:
  5. * 相机语义全在 `domain/camera.js`(纯数学)与 `services/cameraControl.js`(状态迁移,引擎依赖注入),
  6. * 因此可以用**假引擎**驱动整套交互,不需要浏览器、不需要 cesium。
  7. * 真机行为(Cesium 默认输入确实被替换、中心确实落在屏幕中心、阻尼真的在真机上生效)
  8. * 由 t03-camera-walkthrough.mjs 覆盖。
  9. *
  10. * 运行:node .scratch/cockpit-shell-panel-layout/verify/t03-camera-contract.mjs
  11. */
  12. import assert from 'node:assert/strict'
  13. import { DAMPING_TAU_MS, FOCUS_FLIGHT_MS, PITCH_LIMITS, RANGE_LIMITS } from '../../../src/modules/cockpit/domain/camera.js'
  14. import * as camera from '../../../src/modules/cockpit/domain/camera.js'
  15. import { attachCameraInput, createCameraControl } from '../../../src/modules/cockpit/services/cameraControl.js'
  16. const GROUND = { lon: 110.39, lat: 28.46, height: 0 }
  17. const XIANGLING = { lon: 110.396, lat: 28.455, height: 0 } // 沅陵某监测点
  18. const FRAME_MS = 1000 / 60
  19. function createFakeEngine({ viewport = { width: 1680, height: 900 }, fovY = Math.PI / 3, ground = GROUND } = {}) {
  20. const applied = []
  21. let clock = 1000
  22. let pendingFrame = null
  23. return {
  24. applied,
  25. engine: {
  26. applyView(pivot, hpr) {
  27. applied.push({ pivot: { ...pivot }, hpr: { ...hpr } })
  28. },
  29. readView() {
  30. return { heading: 0, pitch: -60, range: 10000 }
  31. },
  32. pickGroundAtCenter() {
  33. return { ...ground }
  34. },
  35. projectPivot() {
  36. return { x: viewport.width / 2, y: viewport.height / 2 }
  37. },
  38. inputTarget() {
  39. return null
  40. },
  41. viewport() {
  42. return { ...viewport }
  43. },
  44. fovY() {
  45. return fovY
  46. },
  47. now() {
  48. return clock
  49. },
  50. requestFrame(callback) {
  51. pendingFrame = callback
  52. },
  53. },
  54. get pendingFrame() {
  55. return pendingFrame
  56. },
  57. advance(ms) {
  58. clock += ms
  59. },
  60. /** 跑一帧:假的 rAF 不带时间戳,控制器会退回 `engine.now()`(真机用真时间戳)。 */
  61. runFrame(dtMs = FRAME_MS) {
  62. const callback = pendingFrame
  63. pendingFrame = null
  64. clock += dtMs
  65. if (callback) callback()
  66. }, last() {
  67. return applied[applied.length - 1]
  68. },
  69. }
  70. }
  71. function newControl(options) {
  72. const fake = createFakeEngine(options)
  73. const control = createCameraControl({ engine: fake.engine, ...(options && options.control) })
  74. control.syncFromEngine()
  75. fake.applied.length = 0
  76. return { fake, control }
  77. }
  78. /** 一直跑到停稳(阻尼 + 换中心飞行都收敛),返回跑过的帧数。 */
  79. function settle(fake, control, maxFrames = 400) {
  80. let frames = 0
  81. while (!control.getState().settled && frames < maxFrames) {
  82. fake.runFrame()
  83. frames += 1
  84. }
  85. assert.ok(frames < maxFrames, `阻尼/飞行应在有限帧内停稳(已跑 ${frames} 帧仍未 settled)`)
  86. return frames
  87. }
  88. /** 假元素:记录监听器,供 attachCameraInput 的绑定/解绑断言。 */
  89. function createFakeElement() {
  90. const handlers = new Map()
  91. return {
  92. handlers,
  93. defaultPrevented: 0,
  94. addEventListener(type, fn) {
  95. if (!handlers.has(type)) handlers.set(type, new Set())
  96. handlers.get(type).add(fn)
  97. },
  98. removeEventListener(type, fn) {
  99. if (handlers.has(type)) handlers.get(type).delete(fn)
  100. },
  101. setPointerCapture() {},
  102. releasePointerCapture() {},
  103. fire(type, payload = {}) {
  104. const set = handlers.get(type)
  105. if (!set) return
  106. const event = {
  107. preventDefault() {
  108. this.defaultPrevented = true
  109. },
  110. ...payload,
  111. }
  112. set.forEach((fn) => fn(event))
  113. return event
  114. },
  115. }
  116. }
  117. const near = (a, b, tolerance, message) =>
  118. assert.ok(Math.abs(a - b) <= tolerance, `${message}:期望 ≈${b}(±${tolerance}),实际 ${a}`)
  119. const round3 = (n) => Number(n.toFixed(3))
  120. const metersPerPxAt = (range) => camera.metersPerPixel({ range, fovYRad: Math.PI / 3, viewportHeight: 900 })
  121. const degreesLonFor = (meters, lat) => meters / (111320 * Math.cos((lat * Math.PI) / 180))
  122. // ---------- 1. 左键拖拽只平移 ----------
  123. {
  124. const { fake, control } = newControl()
  125. const before = control.getState()
  126. control.beginDrag({ button: 0, x: 0, y: 0 })
  127. control.moveDrag({ x: 100, y: 0 })
  128. const after = control.getState()
  129. assert.deepEqual(after.hpr, before.hpr, '平移不得改 heading / pitch / range')
  130. // 维护者 2026-09-17 裁定:**抓着地图拖** —— 拖右 → 相机左移、画面右移,所以中心往西(lon 减小)。
  131. const expectedLon = before.pivot.lon - degreesLonFor(100 * metersPerPxAt(before.hpr.range), GROUND.lat)
  132. near(after.pivot.lon, expectedLon, Math.abs(expectedLon - before.pivot.lon) * 0.02, '拖右应把中心按像素比例西移(相机左移)')
  133. near(after.pivot.lat, before.pivot.lat, 1e-6, 'heading=0 时右拖不应产生南北位移')
  134. settle(fake, control)
  135. near(fake.last().pivot.lon, expectedLon, 1e-9, '阻尼收敛后下发给相机的中心应等于目标')
  136. console.log('PASS 1 左键拖拽只平移(heading/pitch/range 原样,中心按像素比例随「抓地图」方向西移)')
  137. }
  138. // ---------- 2. 平移方向 = 抓着地图拖(维护者裁定的语义钉子) ----------
  139. {
  140. const { fake, control } = newControl()
  141. control.beginDrag({ button: 0, x: 0, y: 0 })
  142. control.moveDrag({ x: 0, y: 100 })
  143. const down = control.getState()
  144. assert.ok(
  145. down.pivot.lat > GROUND.lat,
  146. `heading=0 时下拖应把中心往北带(画面下移、相机上移):${JSON.stringify(down.pivot)}`,
  147. )
  148. const { fake: fake2, control: control2 } = newControl()
  149. control2.beginDrag({ button: 2, x: 0, y: 0 })
  150. control2.moveDrag({ x: 90 / camera.ORBIT_SENSITIVITY.heading, y: 0 }) // 先把 heading 拖到 90°(向东看)
  151. control2.endDrag()
  152. settle(fake2, control2)
  153. near(control2.getState().hpr.heading, 90, 1e-6, '轨道旋转应把 heading 拖到 90°')
  154. const beforePan = control2.getState()
  155. control2.beginDrag({ button: 0, x: 0, y: 0 })
  156. control2.moveDrag({ x: 100, y: 0 })
  157. const afterPan = control2.getState()
  158. assert.ok(
  159. afterPan.pivot.lat > beforePan.pivot.lat,
  160. `heading=90°(向东看)时拖右应把中心往北带(画面右移=相机往左=北):${JSON.stringify(afterPan.pivot)}`,
  161. )
  162. near(afterPan.pivot.lon, beforePan.pivot.lon, 1e-6, 'heading=90° 时右拖不应产生东西位移')
  163. console.log('PASS 2 平移方向 = 抓着地图拖(拖右→画面右移/相机左移,heading=0/90 两点验证)')
  164. }
  165. // ---------- 3. 右键拖拽只做轨道旋转 ----------
  166. {
  167. const { fake, control } = newControl()
  168. const before = control.getState()
  169. control.beginDrag({ button: 2, x: 0, y: 0 })
  170. control.moveDrag({ x: 100, y: 50 })
  171. const after = control.getState()
  172. near(after.hpr.heading, 28, 1e-6, 'heading 变化 = dx × 灵敏度')
  173. near(after.hpr.pitch, -60 - 50 * 0.22, 1e-6, 'pitch 变化 = -dy × 灵敏度')
  174. assert.equal(after.hpr.range, before.hpr.range, '轨道旋转不得改弹簧臂长度')
  175. assert.deepEqual(after.pivot, before.pivot, '轨道旋转不得移动中心')
  176. settle(fake, control)
  177. near(fake.last().hpr.range, before.hpr.range, 1e-9, '阻尼收敛后下发的 range 仍应原样')
  178. console.log('PASS 3 右键拖拽只做轨道旋转(heading/pitch 按像素变化,range 与中心不动)')
  179. }
  180. // ---------- 4. pitch 夹在上下限内 ----------
  181. {
  182. const { fake, control } = newControl()
  183. control.beginDrag({ button: 2, x: 0, y: 0 })
  184. control.moveDrag({ x: 0, y: 5000 })
  185. near(control.getState().hpr.pitch, PITCH_LIMITS.ground.min, 1e-9, '一直下拖应夹在下限')
  186. control.moveDrag({ x: 0, y: -10000 })
  187. near(control.getState().hpr.pitch, PITCH_LIMITS.ground.max, 1e-9, '一直上拖应夹在上限')
  188. settle(fake, control)
  189. near(fake.last().hpr.pitch, PITCH_LIMITS.ground.max, 1e-9, '阻尼收敛后下发的 pitch 也应在限内')
  190. console.log(`PASS 4 pitch 夹在 [${PITCH_LIMITS.ground.min}, ${PITCH_LIMITS.ground.max}](地面视图)`)
  191. }
  192. // ---------- 5. 右键按下锁定中心:拖拽中不重新拾取 ----------
  193. {
  194. const { fake, control } = newControl()
  195. const locked = control.getState().pivot
  196. control.beginDrag({ button: 2, x: 0, y: 0 })
  197. // 拖拽进行中来了「选中某对象」:中心不许被改,飞行也不许插进来。
  198. control.setFocus(XIANGLING)
  199. control.moveDrag({ x: 40, y: 0 })
  200. assert.deepEqual(control.getState().pivot, locked, '拖拽中下发的中心必须仍是按下时锁定的那个')
  201. control.endDrag()
  202. assert.equal(control.getState().flying, true, '松手后应开始平滑换中心')
  203. settle(fake, control)
  204. const final = control.getState().pivot
  205. near(final.lon, XIANGLING.lon, 1e-9, '飞行结束后中心应为选中对象')
  206. near(final.lat, XIANGLING.lat, 1e-9, '飞行结束后中心应为选中对象')
  207. console.log('PASS 5 右键按下锁定中心(拖拽中的选中不插队;松手后才开始换中心)')
  208. }
  209. // ---------- 6. 滚轮只改弹簧臂长度 ----------
  210. {
  211. const { fake, control } = newControl()
  212. const before = control.getState()
  213. const handled = control.wheel({ deltaY: -100 })
  214. const after = control.getState()
  215. assert.equal(handled, true, '滚轮应被相机契约接管(调用方据此 preventDefault)')
  216. near(after.hpr.range, 10000 * Math.exp(-100 * 0.0012), 1e-6, '上滚拉近:range 按指数缩')
  217. assert.equal(after.hpr.heading, before.hpr.heading, '滚轮不得转 heading')
  218. assert.equal(after.hpr.pitch, before.hpr.pitch, '滚轮不得改 pitch')
  219. assert.deepEqual(after.pivot, before.pivot, '滚轮不得移动中心')
  220. control.wheel({ deltaY: -1e6 })
  221. near(control.getState().hpr.range, RANGE_LIMITS.min, 1e-9, '拉近到极限应夹住下限')
  222. control.wheel({ deltaY: 1e6 })
  223. near(control.getState().hpr.range, RANGE_LIMITS.max, 1e-9, '推远到极限应夹住上限')
  224. settle(fake, control)
  225. near(fake.last().hpr.range, RANGE_LIMITS.max, 1e-9, '阻尼收敛后下发的 range 应等于目标')
  226. console.log(`PASS 6 滚轮只改弹簧臂长度(并夹在 [${RANGE_LIMITS.min}, ${RANGE_LIMITS.max}] 米)`)
  227. }
  228. // ---------- 7. 中心规则:选中优先 / 取消不回退 / 平移才回退 ----------
  229. {
  230. const { fake, control } = newControl()
  231. assert.deepEqual(control.getState().pivot, GROUND, '未选中时中心 = 屏幕中心的地面拾取点')
  232. control.setFocus(XIANGLING)
  233. settle(fake, control)
  234. assert.deepEqual(control.getState().pivot, XIANGLING, '选中后中心 = 对象地表点')
  235. control.setFocus(null)
  236. assert.deepEqual(control.getState().pivot, XIANGLING, '取消选中不得回退中心')
  237. assert.equal(control.getState().focus, null, '取消选中应清掉选中态')
  238. control.beginDrag({ button: 0, x: 0, y: 0 })
  239. control.moveDrag({ x: 10, y: 0 })
  240. control.endDrag()
  241. assert.deepEqual(control.getState().pivot, GROUND, '左键平移后中心回到地面拾取点')
  242. console.log('PASS 7 中心规则:选中优先 → 取消不回退 → 平移才更新为地面拾取点')
  243. }
  244. // ---------- 8. 换中心平滑、且全程保持 heading 与 range ----------
  245. {
  246. const { fake, control } = newControl()
  247. const before = control.getState()
  248. control.setFocus(XIANGLING)
  249. // 起手第一帧(elapsed = 0)必须仍停在原中心 —— 换中心不许瞬移。
  250. fake.runFrame(0)
  251. near(control.getState().pivot.lon, before.pivot.lon, 1e-12, '换中心第一帧应从原中心出发')
  252. const samples = []
  253. let frames = 0
  254. while (control.getState().flying && frames++ < 200) {
  255. fake.runFrame(FOCUS_FLIGHT_MS / 8)
  256. const now = control.getState()
  257. assert.equal(now.hpr.heading, before.hpr.heading, '换中心过程中 heading 必须保持')
  258. assert.equal(now.hpr.range, before.hpr.range, '换中心过程中 range 必须保持')
  259. samples.push(now.pivot.lon)
  260. }
  261. assert.ok(samples.length >= 4, `换中心应有多帧(实际 ${samples.length})`)
  262. assert.equal(
  263. samples.every((lon, i) => i === 0 || lon >= samples[i - 1] - 1e-12),
  264. true,
  265. `中心应朝目标单调推进:${samples.join(' → ')}`,
  266. )
  267. settle(fake, control)
  268. near(control.getState().pivot.lon, XIANGLING.lon, 1e-9, '末帧应到达目标中心')
  269. assert.equal(control.getState().flying, false, '到达后应结束飞行')
  270. console.log(`PASS 8 换中心平滑(${samples.length} 帧单调推进、heading/range 全程不变)`)
  271. }
  272. // ---------- 9. 阻尼:渐入、不超调、停稳、且与帧率无关 ----------
  273. {
  274. const { fake, control } = newControl()
  275. const before = control.getState()
  276. control.beginDrag({ button: 0, x: 0, y: 0 })
  277. control.moveDrag({ x: 400, y: 0 })
  278. const target = control.getState()
  279. // 目标立刻到位(输入不丢),实际态还在起点附近 —— 这就是「丝滑」的来源。
  280. assert.notDeepEqual(target.pivot, before.pivot, '目标态应当立刻跟上输入')
  281. assert.deepEqual(control.getState().shownPivot, before.pivot, '首个阻尼帧之前,实际态还在起点')
  282. const targetShift = target.pivot.lon - before.pivot.lon
  283. fake.runFrame(FRAME_MS)
  284. const oneFrame = control.getState()
  285. const oneFrameShift = oneFrame.shownPivot.lon - before.pivot.lon
  286. assert.ok(
  287. Math.abs(oneFrameShift) > 0 && Math.abs(oneFrameShift) < Math.abs(targetShift) * 0.6,
  288. `一帧内应只走一小部分(实际 ${oneFrameShift} / 目标 ${targetShift})`,
  289. )
  290. assert.equal(oneFrame.settled, false, '一帧后还没停稳')
  291. // 逼近过程不得超调(单调朝目标,不越过)。
  292. let previous = Math.abs(target.pivot.lon - oneFrame.shownPivot.lon)
  293. let frames = 1
  294. while (!control.getState().settled && frames < 400) {
  295. fake.runFrame(FRAME_MS)
  296. const gap = Math.abs(target.pivot.lon - control.getState().shownPivot.lon)
  297. assert.ok(gap <= previous + 1e-12, `阻尼不得超调:缺口从 ${previous} 变成 ${gap}`)
  298. previous = gap
  299. frames += 1
  300. }
  301. assert.equal(control.getState().settled, true, '有限帧内应停稳')
  302. assert.deepEqual(control.getState().shownPivot, target.pivot, '停稳后实际态应吸附到目标')
  303. console.log(`PASS 9a 阻尼渐入、不超调、${frames} 帧内停稳并吸附(τ=${DAMPING_TAU_MS}ms)`)
  304. // 帧率无关:同样的真实时长,60fps 与 120fps 收敛到同一个位置(±1%)。
  305. const walk = (dtMs, totalMs) => {
  306. const { fake: f, control: c } = newControl()
  307. const start = c.getState()
  308. c.beginDrag({ button: 0, x: 0, y: 0 })
  309. c.moveDrag({ x: 400, y: 0 })
  310. // 固定帧数,别用浮点累加判停:累加误差会多跑一帧,把「帧率无关」测成假的偏差。
  311. const frames = Math.round(totalMs / dtMs)
  312. for (let i = 0; i < frames; i += 1) f.runFrame(dtMs)
  313. const shift = c.getState().shownPivot.lon - start.pivot.lon
  314. const full = c.getState().pivot.lon - start.pivot.lon
  315. return shift / full
  316. }
  317. const at60 = walk(1000 / 60, 200)
  318. const at120 = walk(1000 / 120, 200)
  319. near(at60, at120, 0.01, '同样 200ms 内 60fps 与 120fps 的收敛比例应一致(±1%)')
  320. assert.ok(at60 > 0.6 && at60 < 0.95, `200ms(≈1.8τ)应走掉大半但未走完:实际 ${at60}`)
  321. console.log(`PASS 9b 阻尼与帧率无关(60fps ${(at60 * 100).toFixed(1)}% vs 120fps ${(at120 * 100).toFixed(1)}%)`)
  322. }
  323. // ---------- 10. 用户操作打断换中心飞行 ----------
  324. {
  325. const { fake, control } = newControl()
  326. control.setFocus(XIANGLING)
  327. assert.equal(control.getState().flying, true, '应处于换中心飞行中')
  328. control.beginDrag({ button: 0, x: 0, y: 0 })
  329. assert.equal(control.getState().flying, false, '一上手就应打断飞行(输入永远优先)')
  330. console.log('PASS 10 用户操作打断换中心飞行')
  331. }
  332. // ---------- 10b. 阻尼可现场拖调(手感是主观的,维护者要能在控制台试) ----------
  333. {
  334. const { fake, control } = newControl()
  335. assert.equal(control.getState().dampingTauMs, DAMPING_TAU_MS, '默认应取 domain 里的 τ')
  336. // 调大 τ:同样一帧走得更少(更飘)。
  337. const shiftWith = (tau) => {
  338. const { fake: f, control: c } = newControl()
  339. c.setDampingTau(tau)
  340. const start = c.getState().pivot.lon
  341. c.beginDrag({ button: 0, x: 0, y: 0 })
  342. c.moveDrag({ x: 400, y: 0 })
  343. f.runFrame(FRAME_MS)
  344. return Math.abs(c.getState().shownPivot.lon - start)
  345. }
  346. const loose = shiftWith(400)
  347. const tight = shiftWith(40)
  348. assert.ok(tight > loose * 1.5, `τ 越小越跟手:τ=40 走 ${tight},τ=400 只走 ${loose}`)
  349. // τ = 0:不做阻尼(一帧内直接贴到目标),给「要完全即时手感」的场合留的档。
  350. const { fake: f2, control: c2 } = newControl()
  351. c2.setDampingTau(0)
  352. c2.beginDrag({ button: 0, x: 0, y: 0 })
  353. c2.moveDrag({ x: 400, y: 0 })
  354. f2.runFrame(FRAME_MS)
  355. assert.deepEqual(c2.getState().shownPivot, c2.getState().pivot, 'τ=0 时一帧内实际态应贴到目标态')
  356. assert.equal(c2.getState().settled, true, 'τ=0 时下完指令一帧即停稳')
  357. assert.equal(f2.pendingFrame, null, 'τ=0 停稳后不应再排帧')
  358. // 非法值不生效(守住旋钮)。
  359. assert.equal(control.setDampingTau(-5), DAMPING_TAU_MS, '负数应被拒绝并保持原值')
  360. assert.equal(control.setDampingTau('abc'), DAMPING_TAU_MS, '非数字应被拒绝并保持原值')
  361. console.log(`PASS 10b 阻尼可拖调(τ=40 走 ${round3(tight)}° > τ=400 走 ${round3(loose)}°;τ=0 直接跟手)`)
  362. }
  363. // ---------- 11. DOM 绑定:三类输入都接上,右键菜单与滚轮默认行为被吃掉 ----------
  364. {
  365. const { fake, control } = newControl()
  366. const element = createFakeElement()
  367. const detach = attachCameraInput(element, control)
  368. assert.deepEqual(
  369. [...element.handlers.keys()].sort(),
  370. ['contextmenu', 'pointercancel', 'pointerdown', 'pointermove', 'pointerup', 'wheel'],
  371. '应绑定左右键拖拽与滚轮(并吃掉右键菜单)',
  372. )
  373. assert.equal(element.fire('contextmenu').defaultPrevented, true, '右键菜单必须被 preventDefault')
  374. element.fire('pointerdown', { button: 0, pointerId: 1, clientX: 500, clientY: 400 })
  375. element.fire('pointermove', { pointerId: 1, clientX: 560, clientY: 400 })
  376. assert.equal(control.getState().dragging, 'pan', '左键按下后应处于平移态')
  377. element.fire('pointerup', { pointerId: 1, clientX: 560, clientY: 400 })
  378. assert.equal(control.getState().dragging, null, '松手后应结束拖拽')
  379. element.fire('pointerdown', { button: 2, pointerId: 2, clientX: 500, clientY: 400 })
  380. element.fire('pointermove', { pointerId: 2, clientX: 540, clientY: 400 })
  381. assert.equal(control.getState().dragging, 'orbit', '右键按下后应处于轨道旋转态')
  382. element.fire('pointerup', { pointerId: 2, clientX: 540, clientY: 400 })
  383. assert.equal(element.fire('wheel', { deltaY: -120 }).defaultPrevented, true, '滚轮默认行为(页面滚动)必须被吃掉')
  384. detach()
  385. assert.equal(element.handlers.get('pointerdown').size, 0, 'detach 应摘掉监听器')
  386. assert.equal(element.handlers.get('wheel').size, 0, 'detach 应摘掉滚轮监听器')
  387. console.log('PASS 11 DOM 绑定:三类输入接上、右键菜单与滚轮默认行为被吃掉、可完整摘除')
  388. }
  389. // ---------- 12. 状态串(走查与人工排查读的那一行) ----------
  390. {
  391. const { control } = newControl()
  392. const text = camera.formatCameraState(control.getState())
  393. ;['h=', 'p=', 'r=', 'pivot=', 'focus=ground', 'drag=none', 'settled='].forEach((part) =>
  394. assert.ok(text.includes(part), `状态串应含 ${part}:${text}`),
  395. )
  396. assert.equal(
  397. camera.formatCameraState({ hpr: { heading: 0, pitch: -60, range: 1 }, pivot: null }),
  398. 'h=0.0 p=-60.0 r=1 pivot=none',
  399. )
  400. console.log(`PASS 12 状态串可读:${text}`)
  401. }
  402. console.log('\nT03 逻辑检查通过:三键契约、中心规则、换中心动画、阻尼(帧率无关)、DOM 绑定均符合契约与维护者裁定。')