// 一次性探针(票 47 DOM overlay 自绘母版): // ① 拟合母版下半收尖轮廓(假设=圆弧,检验残差);② 量镂空版主版的孔洞几何。 // 输出直接嵌进 markerOverlay.js 的手绘 SVG path。 import { readFileSync } from 'node:fs' import { inflateSync } from 'node:zlib' function decodePng(path) { const buf = readFileSync(path) let pos = 8 const idat = [] let width = 0, height = 0, colorType = 0, trns = null while (pos < buf.length) { const len = buf.readUInt32BE(pos) const type = buf.toString('ascii', pos + 4, pos + 8) const data = buf.subarray(pos + 8, pos + 8 + len) if (type === 'IHDR') { width = data.readUInt32BE(0); height = data.readUInt32BE(4); colorType = data[9] } else if (type === 'tRNS') trns = Buffer.from(data) else if (type === 'IDAT') idat.push(data) else if (type === 'IEND') break pos += 12 + len } const channels = colorType === 6 ? 4 : colorType === 2 ? 3 : 1 const stride = width * channels const raw = inflateSync(Buffer.concat(idat)) const img = Buffer.alloc(height * stride) for (let y = 0; y < height; y++) { const filter = raw[y * (stride + 1)] const row = raw.subarray(y * (stride + 1) + 1, (y + 1) * stride) const prev = y > 0 ? img.subarray((y - 1) * stride, y * stride) : null const out = img.subarray(y * stride, (y + 1) * stride) for (let x = 0; x < stride; x++) { const a = x >= channels ? out[x - channels] : 0 const b = prev ? prev[x] : 0 const c = prev && x >= channels ? prev[x - channels] : 0 let v = row[x] if (filter === 1) v += a else if (filter === 2) v += b else if (filter === 3) v += (a + b) >> 1 else if (filter === 4) { const p = a + b - c const pa = Math.abs(p - a), pb = Math.abs(p - b), pc = Math.abs(p - c) v += pa <= pb && pa <= pc ? a : pb <= pc ? b : c } out[x] = v & 0xff } } const alphaAt = (x, y) => { if (colorType === 6) return img[y * stride + x * 4 + 3] if (colorType === 2) return 255 const idx = img[y * stride + x] if (trns && idx < trns.length) return trns[idx] return 255 } return { width, height, alphaAt } } const MINX = 67, MAXX = 444, MINY = 19, MAXY = 493 // 帽圆(实测):圆心 (255.5, 208),半径 189 —— 与 MASTER_GEOMETRY capCenter(0.499,0.397) 一致 const CAP = { cx: 255.5, cy: 208, r: 189 } const file = process.argv[2] || 'public/cockpit/assets/icons/T_MarkPoint_WhiteFull.png' const { alphaAt } = decodePng(file) const edge = (y) => { for (let x = MINX; x <= MAXX; x++) if (alphaAt(x, y) > 8) return x return null } // ---- ① 下半段左缘采样 + 圆拟合 ---- const pts = [] for (let y = 380; y <= 490; y += 5) { const x = edge(y) if (x != null) pts.push([x, y]) } function fitCircle(points) { const n = points.length let suu = 0, suv = 0, su = 0, svv = 0, sv = 0, suw = 0, svw = 0, sw = 0 for (const [u, v] of points) { const w = u * u + v * v suu += u * u; suv += u * v; su += u; svv += v * v; sv += v suw += w * u; svw += w * v; sw += w } const A = [[suu, suv, su], [suv, svv, sv], [su, sv, n]] const b = [suw, svw, sw] for (let i = 0; i < 3; i++) { let p = i for (let k = i + 1; k < 3; k++) if (Math.abs(A[k][i]) > Math.abs(A[p][i])) p = k ;[A[i], A[p]] = [A[p], A[i]]; [b[i], b[p]] = [b[p], b[i]] for (let k = i + 1; k < 3; k++) { const f = A[k][i] / A[i][i] for (let j = i; j < 3; j++) A[k][j] -= f * A[i][j] b[k] -= f * b[i] } } const z = [0, 0, 0] for (let i = 2; i >= 0; i--) { z[i] = b[i] for (let j = i + 1; j < 3; j++) z[i] -= A[i][j] * z[j] z[i] /= A[i][i] } const [D, E, F] = z return { cx: -D / 2, cy: -E / 2, r: Math.sqrt((D * D) / 4 + (E * E) / 4 - F) } } const fit = fitCircle(pts) let maxRes = 0 for (const [x, y] of pts) maxRes = Math.max(maxRes, Math.abs(Math.hypot(x - fit.cx, y - fit.cy) - fit.r)) console.log(`下半段圆弧拟合:圆心 (${fit.cx.toFixed(1)}, ${fit.cy.toFixed(1)}) 半径 ${fit.r.toFixed(1)},最大残差 ${maxRes.toFixed(2)}px`) const tip = { x: 255.5, y: 493 } const dTip = Math.hypot(tip.x - fit.cx, tip.y - fit.cy) console.log(`尖端到拟合圆心距离 ${dTip.toFixed(1)} vs 半径 ${fit.r.toFixed(1)}(差 ${(dTip - fit.r).toFixed(1)}px → ${Math.abs(dTip - fit.r) < 2 ? '尖端在圆上,A 命令直达' : '尖端不在圆上'})`) // 帽圆 ∩ 拟合圆 交点 const dx = fit.cx - CAP.cx, dy = fit.cy - CAP.cy, d = Math.hypot(dx, dy) const a = (CAP.r * CAP.r - fit.r * fit.r + d * d) / (2 * d) const h = Math.sqrt(Math.max(0, CAP.r * CAP.r - a * a)) const mx = CAP.cx + (a * dx) / d, my = CAP.cy + (a * dy) / d console.log(`帽圆∩拟合圆:(${(mx + (h * dy) / d).toFixed(1)}, ${(my - (h * dx) / d).toFixed(1)}) / (${(mx - (h * dy) / d).toFixed(1)}, ${(my + (h * dx) / d).toFixed(1)})`) // ---- ② 镂空版孔洞几何 ---- const hollow = decodePng('public/cockpit/assets/icons/T_MarkPoint_White.png') const rowGaps = (y) => { const gaps = [] let start = -1 for (let x = MINX; x <= MAXX; x++) { const al = hollow.alphaAt(x, y) if (al <= 8 && start < 0) start = x if (al > 8 && start >= 0) { gaps.push([start, x - 1]); start = -1 } } if (start >= 0) gaps.push([start, MAXX]) return gaps } const colGaps = () => { const gaps = [] let start = -1 for (let y = MINY; y <= MAXY; y++) { const al = hollow.alphaAt(256, y) if (al <= 8 && start < 0) start = y if (al > 8 && start >= 0) { gaps.push([start, y - 1]); start = -1 } } if (start >= 0) gaps.push([start, MAXY]) return gaps } console.log('\n镂空版 y=208 透明段:', JSON.stringify(rowGaps(208))) console.log('镂空版 y=190 透明段:', JSON.stringify(rowGaps(190))) console.log('镂空版 x=256 透明段:', JSON.stringify(colGaps()))