BRAND-MANUAL.md 收敛识别方案裁定与实测判据;TOKEN-MIGRATION.md 记 P1/P3/P4 迁移面与孪生缺陷; TEST-PATCH.md 记 P7 的 1→0 实测。随包入库的是结论赖以成立的仪器与证据:check-assets、check-manual、 verify-assets-cross、check-wordmark-copies、check-docsync、check-probes(四段闸,每段带能失败的负例)、 check-baseline-shift.cjs(平移感知基线判据,四合成样本两绿两红自测通过;它取代被证伪的 「diff 包围盒不许越页眉带」)与 measured/baseline-shift-p1.json(第一批 104 张逐张分类,带 _src 出处戳)。 大体积工作件不入库:样机 HTML 与栅格截图 100+MB、字体母版 45MB 留在盘上,入库 690 个文本/矢量件。
487 lines
25 KiB
Python
487 lines
25 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
液滴 / 节点融合(第四十一刀)—— 甲方第二批参照:metaball 家族
|
||
|
||
八张参照里六张是同一个语法:圆点之间长出**凹颈**,融成一整块
|
||
(琵琶湖ホテル、BIOPUS、FARCA、ZEOUR、NFLUENCE、I-DO),
|
||
另两张是近亲(波形、圆点环)。
|
||
|
||
为什么这一族值得单独开一刀:**它是第一个既流行、又落在自有字理上的语法。**
|
||
· metaball 的本质不是"点被线连起来",是**两个独立的东西长成了一个**。
|
||
· 《说文》「叡,深明也。**通也**」;段玉裁「能容而後能明」;
|
||
《彖》「天地交而万物**通**也」。⇒ **颈就是"交",融合就是"通"。**
|
||
· 一家卖架构整合与系统打通的咨询公司,画"节点长在一起"是字面意义上的本行。
|
||
前面四十刀要么借古钱、借印、借山、借卦,这一刀不用借。
|
||
|
||
三族,全部单因子:
|
||
A 融合度 —— 两珠,只改圆心距 d。这一族真正的生死线在**颈宽**:
|
||
颈一细,缩到 16px 就断成两颗豆。所以把 d 扫开,逐档量连通体。
|
||
B 母题 —— 双珠 / 三合 / 四合 / 六环留心 / 五珠 / 递生长臂 / 频环 …
|
||
C 异常 —— 一颗出列(脱离接触)/ 一颗放大 / 交叠调子(参照图那种半透明叠色)
|
||
|
||
解析对照(答案由构造决定):两圆完全重合必 1 个连通体;两圆远隔必 2 个。
|
||
"""
|
||
import importlib.util
|
||
import json
|
||
import math
|
||
import os
|
||
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
|
||
|
||
def load(name, fn):
|
||
sp = importlib.util.spec_from_file_location(name, os.path.join(HERE, fn))
|
||
m = importlib.util.module_from_spec(sp)
|
||
sp.loader.exec_module(m)
|
||
return m
|
||
|
||
|
||
r2 = load("r2", "ring2.py")
|
||
CH = json.load(open(os.path.join(HERE, "_wm-chars.json"), encoding="utf-8"))["chars"]
|
||
RED, INK, WHITE, TAN = "#C41E3A", "#26221E", "#FFFFFF", "#81565D"
|
||
|
||
VB = 120.0
|
||
CC = 60.0
|
||
|
||
|
||
# --------------------------------------------------------------- metaball 几何
|
||
def field(nodes, x, y):
|
||
s = 0.0
|
||
for cx, cy, r in nodes:
|
||
dx, dy = x - cx, y - cy
|
||
d2 = dx * dx + dy * dy
|
||
s += (r * r) / d2 if d2 > 1e-9 else 1e9
|
||
return s
|
||
|
||
|
||
def contour(nodes, T=1.0, n=200, box=(2.0, 2.0, 118.0, 118.0)):
|
||
"""纯 Python marching squares。返回若干闭合环(不判向,交给 evenodd 处理嵌套)。"""
|
||
x0, y0, x1, y1 = box
|
||
hs = (x1 - x0) / (n - 1)
|
||
vs = (y1 - y0) / (n - 1)
|
||
F = [[0.0] * n for _ in range(n)]
|
||
for j in range(n):
|
||
y = y0 + j * vs
|
||
for i in range(n):
|
||
F[j][i] = field(nodes, x0 + i * hs, y)
|
||
pts = {}
|
||
|
||
def edge(e, i, j):
|
||
"""e: 0=top 1=right 2=bottom 3=left,返回该边上的插值交点。"""
|
||
key = (e, i, j) if e in (0, 2) else (e, j, i)
|
||
if key in pts:
|
||
return pts[key]
|
||
if e == 0:
|
||
a, b = F[j][i], F[j][i + 1]
|
||
t = (T - a) / (b - a) if b != a else 0.5
|
||
p = (x0 + (i + t) * hs, y0 + j * vs)
|
||
elif e == 2:
|
||
a, b = F[j + 1][i], F[j + 1][i + 1]
|
||
t = (T - a) / (b - a) if b != a else 0.5
|
||
p = (x0 + (i + t) * hs, y0 + (j + 1) * vs)
|
||
elif e == 3:
|
||
a, b = F[j][i], F[j + 1][i]
|
||
t = (T - a) / (b - a) if b != a else 0.5
|
||
p = (x0 + i * hs, y0 + (j + t) * vs)
|
||
else:
|
||
a, b = F[j][i + 1], F[j + 1][i + 1]
|
||
t = (T - a) / (b - a) if b != a else 0.5
|
||
p = (x0 + (i + 1) * hs, y0 + (j + t) * vs)
|
||
pts[key] = p
|
||
return p
|
||
|
||
# 位:tl=1 tr=2 br=4 bl=8。表里只列【真的被穿越】的两条边 ——
|
||
# case 9 是 tl|bl 在内,左边两端点都在内、根本没被穿越,
|
||
# 第一版误写成 (0,3),于是往一个不存在交点上连线,留下 66 个度为 1 的悬点,
|
||
# 环数从 1 炸到 41。正确是 top→bottom。
|
||
TAB = {1: [(0, 3)], 2: [(0, 1)], 3: [(3, 1)], 4: [(1, 2)], 6: [(0, 2)],
|
||
7: [(3, 2)], 8: [(2, 3)], 9: [(0, 2)], 11: [(1, 2)], 12: [(3, 1)],
|
||
13: [(0, 1)], 14: [(0, 3)]}
|
||
segs = []
|
||
for j in range(n - 1):
|
||
for i in range(n - 1):
|
||
c = ((1 if F[j][i] >= T else 0) | (2 if F[j][i + 1] >= T else 0)
|
||
| (4 if F[j + 1][i + 1] >= T else 0) | (8 if F[j + 1][i] >= T else 0))
|
||
if c == 0 or c == 15:
|
||
continue
|
||
if c in (5, 10):
|
||
ctr = (F[j][i] + F[j][i + 1] + F[j + 1][i] + F[j + 1][i + 1]) / 4.0
|
||
if (ctr >= T) == (c == 5):
|
||
segs.append((edge(0, i, j), edge(3, i, j)))
|
||
segs.append((edge(1, i, j), edge(2, i, j)))
|
||
else:
|
||
segs.append((edge(0, i, j), edge(1, i, j)))
|
||
segs.append((edge(2, i, j), edge(3, i, j)))
|
||
continue
|
||
for a, b in TAB[c]:
|
||
segs.append((edge(a, i, j), edge(b, i, j)))
|
||
|
||
def key(p):
|
||
return (round(p[0], 5), round(p[1], 5))
|
||
|
||
adj = {}
|
||
for si, (a, b) in enumerate(segs):
|
||
adj.setdefault(key(a), []).append(si)
|
||
adj.setdefault(key(b), []).append(si)
|
||
loose = [q for q, v in adj.items() if len(v) != 2]
|
||
if loose:
|
||
raise AssertionError("等值面有 %d 个悬点(应为 0)—— 查 marching squares 表"
|
||
% len(loose))
|
||
used = [False] * len(segs)
|
||
loops = []
|
||
for si in range(len(segs)):
|
||
if used[si]:
|
||
continue
|
||
loop = [segs[si][0], segs[si][1]]
|
||
used[si] = True
|
||
cur = key(segs[si][1])
|
||
guard = 0
|
||
while cur != key(loop[0]) and guard < 100000:
|
||
guard += 1
|
||
nxt = None
|
||
for s2 in adj.get(cur, ()):
|
||
if not used[s2]:
|
||
nxt = s2
|
||
break
|
||
if nxt is None:
|
||
break
|
||
used[nxt] = True
|
||
a, b = segs[nxt]
|
||
p = b if key(a) == cur else a
|
||
loop.append(p)
|
||
cur = key(p)
|
||
loops.append(loop)
|
||
return loops
|
||
|
||
|
||
def path_d(nodes, T=1.0, n=200):
|
||
loops = contour(nodes, T, n)
|
||
if not loops:
|
||
raise AssertionError("等值面空 —— 节点半径或阈值给错了")
|
||
out = []
|
||
for lp in loops:
|
||
out.append("M " + " L ".join("%.2f %.2f" % (x, y) for x, y in lp) + " Z")
|
||
return " ".join(out), len(loops)
|
||
|
||
|
||
def ring_nodes(k, rad, r, phase=90.0, radii=None, rr=None):
|
||
"""k 个节点均分在半径 rad 的圆上。radii 可逐点给不同半径(做"一颗放大")。"""
|
||
out = []
|
||
for i in range(k):
|
||
a = math.radians(phase + 360.0 * i / k)
|
||
out.append((CC + rad * math.cos(a), CC + rad * math.sin(a),
|
||
r if radii is None else radii[i]))
|
||
return out
|
||
|
||
|
||
def pair(d, r):
|
||
return [(CC - d / 2.0, CC, r), (CC + d / 2.0, CC, r)]
|
||
|
||
|
||
def neck(d, r):
|
||
"""两等珠融合颈宽(解析):2·sqrt(2r² − d²/4)。≤0 即已断开。"""
|
||
v = 2.0 * r * r - d * d / 4.0
|
||
return 2.0 * math.sqrt(v) if v > 0 else 0.0
|
||
|
||
|
||
# --------------------------------------------------------------- 三族候选
|
||
FAM_A = ("A 融合度:颈就是生死线",
|
||
"两珠,只改圆心距 d。颈宽按解析式 2√(2r²−d²/4) 递减;"
|
||
"缩到 16px 时颈先断 —— 断的那一刻,标志从「一个物」退化成「两颗豆」。",
|
||
[("A1 d=26 已融成一体", pair(26.0, 20.0),
|
||
"d 远小于 2r,腰部比珠径还宽(颈/珠径 1.26)—— 等于没有颈,一整颗椭圆。上限对照。"),
|
||
("A2 d=34", pair(34.0, 20.0), "颈/珠径 1.13,腰还比珠粗,颈只是刚要显形。"),
|
||
("A3 d=42", pair(42.0, 20.0), "颈开始明显收细 —— 这是最好看的一段,也是最危险的一段。"),
|
||
("A4 d=50", pair(50.0, 20.0), "再细一档。"),
|
||
("A5 d=56", pair(56.0, 20.0), "临界:解析颈宽已接近 0,16px 必断。")])
|
||
|
||
FAM_B = ("B 母题",
|
||
"同一套液滴语法下的不同「数」。每一个数都对应我们自己的东西,不借象。",
|
||
[("B1 二珠·通", pair(38.0, 21.0), "两个系统长成一个。「叡,通也」。最小、最强的那一格。"),
|
||
("B2 三合", ring_nodes(3, 19.0, 17.0, 90.0), "三才/三层。旋转 120°,琵琶湖ホテル那种。"),
|
||
("B3 四合", ring_nodes(4, 19.0, 16.0, 45.0), "四方/四字 睿新致远。"),
|
||
("B4 五珠", ring_nodes(4, 21.0, 15.0, 90.0) + [(CC, CC, 15.0)],
|
||
"四合一中心。中心那颗把孔填掉 —— 对照 J2「只留一个封闭负形」。"),
|
||
("B5 六环留心", ring_nodes(6, 32.0, 12.0, 90.0),
|
||
"六爻/六合,中间留一个孔。BIOPUS 那种。"
|
||
"R=25/r=15.5 第一版留不住孔:中心场 = 6r²/R² = 2.31 > 1 已被填死。"
|
||
"留孔的硬条件是 R > r√6,融合的硬条件是 R < 2.83r —— 两条件之间只剩"
|
||
" 2.45r < R < 2.83r 这一条窄缝,这里取 R=32 / r=12(中心场 0.84,实测 2 环)。"),
|
||
("B6 递生长臂", [(CC - 22, CC + 20, 20.0), (CC, CC, 15.0),
|
||
(CC + 20, CC - 20, 10.0), (CC + 31, CC - 31, 5.0)],
|
||
"由大到小一路甩出去 —— 致远。FARCA 那条尾巴。"),
|
||
("B7 频环", ring_nodes(9, 26.0, 0.0, 90.0,
|
||
radii=[13 + 6.0 * math.sin(3 * math.radians(360.0 * i / 9))
|
||
for i in range(9)]),
|
||
"一圈半径按正弦起伏的珠子 —— 把 BrainFrequency 那个波形翻成环。")])
|
||
|
||
FAM_C = ("C 异常",
|
||
"参照图那一族几乎每张都留一处不可复制的偏差。这一族试三种做法。",
|
||
[("C1 一颗出列", pair(38.0, 21.0) + [(CC, 15.0, 6.5)],
|
||
"主体不动,上方放一颗**脱离接触**的小珠。第一版放在 y=20 时其实没脱开 —— "
|
||
"两珠合起来的场在 y≈33 处仍 >1,被一根看不见的细颈连着,环数诚实地报了 1。"
|
||
"挪到 y=15 才真是两颗。"),
|
||
("C2 一颗放大", ring_nodes(4, 19.0, 15.0, 45.0,
|
||
radii=[23.0, 15.0, 15.0, 15.0]),
|
||
"四合里有一颗明显大 —— 打破旋转对称,避免读成齿轮。"),
|
||
("C3 交叠调子", pair(44.0, 22.0),
|
||
"参照图那种半透明叠色(两色相交出第三色)。这里用朱砂+檀色叠,"
|
||
"但**印刷与单色化时是风险**,只作试探。")])
|
||
|
||
FAMS = [FAM_A, FAM_B, FAM_C]
|
||
|
||
CSS = """
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:#F7F4EF;color:#4F4A42;
|
||
font:17px/1.9 "Songti SC","Noto Serif SC",Georgia,serif;-webkit-font-smoothing:antialiased}
|
||
.wrap{max-width:1240px;margin:0 auto;padding:46px 32px 100px}
|
||
code{font:13.5px/1.5 ui-monospace,Menlo,monospace;background:#EFEAE1;padding:1px 5px}
|
||
.ey{font:12px/1.4 "PingFang SC",Inter,sans-serif;letter-spacing:.18em;
|
||
text-transform:uppercase;color:#8A8377}
|
||
h1{font-size:50px;line-height:1.16;color:#26221E;margin:12px 0 16px;font-weight:600}
|
||
h1 em{font-style:normal;color:#C41E3A}
|
||
h2{font-size:25px;color:#26221E;margin:52px 0 8px;font-weight:600}
|
||
h2 .ax{font:13px/1.6 "PingFang SC",Inter,sans-serif;color:#8A8377;font-weight:400;
|
||
margin-left:12px;display:block}
|
||
p{max-width:92ch;margin:10px 0}
|
||
.lede{font-size:19px;color:#26221E;max-width:80ch}
|
||
.j{border-left:2px solid #C41E3A;padding:3px 0 3px 18px;margin:14px 0;color:#26221E;max-width:96ch}
|
||
.grid{display:grid;grid-template-columns:repeat(5,1fr);gap:14px;margin:16px 0 6px}
|
||
.c{background:#fff;border:1px solid #EFEAE1;padding:14px 12px 16px}
|
||
.c.pick{border-color:#C41E3A;box-shadow:0 0 0 1px #C41E3A inset}
|
||
.nm{font:650 13px/1.35 "PingFang SC",Inter,sans-serif;color:#26221E;min-height:34px}
|
||
.fig{text-align:center;padding:6px 0}
|
||
.mt{font:11px/1.6 "PingFang SC",Inter,sans-serif;color:#8A8377;
|
||
font-variant-numeric:tabular-nums;text-align:center}
|
||
.mt .bad{color:#C41E3A;font-weight:700}
|
||
.mt .good{color:#0f7b3b;font-weight:700}
|
||
.nt{font-size:12.5px/1.6 "PingFang SC",Inter,sans-serif;color:#4F4A42;
|
||
border-top:1px solid #EFEAE1;margin-top:8px;padding-top:7px}
|
||
table{border-collapse:collapse;width:100%;margin:14px 0;
|
||
font:13px/1.6 "PingFang SC",Inter,sans-serif}
|
||
th,td{padding:9px 11px;border-bottom:1px solid #C3BDB1;text-align:left}
|
||
th{font-size:11px;letter-spacing:.11em;text-transform:uppercase;color:#8A8377;font-weight:500}
|
||
td.n,th.n{text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap}
|
||
.lk{display:flex;gap:26px;align-items:flex-start;flex-wrap:wrap;
|
||
background:#fff;border:1px solid #EFEAE1;padding:22px 24px;margin:14px 0}
|
||
footer{margin-top:56px;padding-top:16px;border-top:1px solid #C3BDB1;
|
||
font:12.5px/1.7 "PingFang SC",Inter,sans-serif;color:#8A8377}
|
||
"""
|
||
|
||
|
||
def art(nodes, px, key, fill=RED, extra=""):
|
||
d, nloop = path_d(nodes)
|
||
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g" '
|
||
'style="width:%dpx;height:%dpx;display:block" data-k="%s">'
|
||
'<path fill="%s" fill-rule="evenodd" d="%s"/>%s</svg>'
|
||
% (VB, VB, px, px, key, fill, d, extra)), nloop
|
||
|
||
|
||
def svg_plain(d, px, fill=RED, op=1.0):
|
||
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g" '
|
||
'style="width:%dpx;height:%dpx;display:block">'
|
||
'<path fill="%s" fill-opacity="%.2f" fill-rule="evenodd" d="%s"/></svg>'
|
||
% (VB, VB, px, px, fill, op, d))
|
||
|
||
|
||
def lockup(nodes, px, ccol=INK, fill=RED):
|
||
d, _n = path_d(nodes)
|
||
h, cw = 26.0, 30.0
|
||
total = 4 * cw
|
||
x0 = (VB - total) / 2.0 + cw / 2.0
|
||
cal = "".join(r2.char_svg(i, x0 + i * cw, 150.0, h, ccol) for i in range(4))
|
||
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g 176" '
|
||
'style="width:%dpx;height:auto;display:block">'
|
||
'<path fill="%s" fill-rule="evenodd" d="%s"/>%s</svg>'
|
||
% (VB, px, fill, d, cal))
|
||
|
||
|
||
def build():
|
||
P = ['<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8">'
|
||
'<meta name="viewport" content="width=device-width,initial-scale=1">'
|
||
'<title>液滴 · 节点融合</title><style>' + CSS + '</style></head><body><div class="wrap">']
|
||
P.append('<div class="ey">Cut 41 · 2026-10-14 · metaball 家族 · 颈宽是生死线 · repo 零改动</div>')
|
||
P.append('<h1>节点:<em>颈就是「通」</em></h1>')
|
||
P.append('<p class="lede">八张里六张是同一个语法:圆点之间长出凹颈、融成一整块。'
|
||
'这一族值得单独开一刀,因为它是第一个既流行、又落在<b>我们自己的字理</b>上的语法 —— '
|
||
'metaball 讲的不是"点被线连起来",是"两个东西长成了一个",'
|
||
'而《说文》给睿的定义正是「深明也,<b>通也</b>」,《彖》曰「天地交而万物通也」。</p>')
|
||
P.append('<div class="j"><b>这一族的生死线只有一条,而且可以算。</b>'
|
||
'两珠之间的<b>颈宽</b>解析式 = 2√(2r² − d²/4)。颈一细,缩到 16px 就先断 —— '
|
||
'断的那一刻,标志从「一个物」退化成「两颗豆」。'
|
||
'所以 A 族只改圆心距,逐档量 16px 连通体数:它掉到 2 的那一档,就是这族的分辨率天花板。</div>')
|
||
|
||
rows = []
|
||
for title, axnote, items in FAMS:
|
||
P.append('<h2><span class="no">%s</span><span class="ax">%s</span></h2>' % (title, axnote))
|
||
P.append('<div class="grid">')
|
||
for nm, nodes, why in items:
|
||
key = nm.split()[0]
|
||
a, nloop = art(nodes, 150, key)
|
||
nk = neck(nodes[1][0] - nodes[0][0], nodes[0][2]) if key.startswith("A") else None
|
||
rows.append((nm, key, len(nodes), nloop, nk))
|
||
cls = "c pick" if key in ("B1", "A3") else "c"
|
||
P.append('<div class="%s"><div class="nm">%s</div><div class="fig">%s</div>'
|
||
'<div class="mt">%d 珠 · 环 %d · 颈/珠径 %s</div>'
|
||
'<div class="nt">%s</div></div>'
|
||
% (cls, nm, a, len(nodes), nloop,
|
||
("%.2f" % nk) if nk is not None else "—", why))
|
||
P.append('</div>')
|
||
|
||
P.append('<h2><span class="no">锁定</span><span class="ax">液滴 + 睿新致遠真迹</span></h2>')
|
||
P.append('<div class="lk">')
|
||
for nm, nodes, why in list(FAM_B[2]):
|
||
key = nm.split()[0]
|
||
if key not in ("B1", "B5", "B6"):
|
||
continue
|
||
P.append('<div style="text-align:center">%s<div class="mt">%s · 朱砂+墨字</div></div>'
|
||
% (lockup(nodes, 190), key))
|
||
P.append('<div style="text-align:center"><span style="display:inline-block;'
|
||
'background:#141210;border-radius:16px;padding:12px">%s</span>'
|
||
'<div class="mt">%s · 暖墨底反白</div></div>'
|
||
% (lockup(nodes, 190, ccol=WHITE, fill=WHITE), key))
|
||
P.append('</div>')
|
||
|
||
P.append('<h2><span class="no">实测</span></h2>')
|
||
P.append('<table><thead><tr><th>格</th><th class="n">珠数</th><th class="n">颈/珠径</th>'
|
||
'<th class="n">环数@512</th><th class="n">墨率@512</th>'
|
||
'<th class="n">颈@512</th><th class="n">颈@16</th>'
|
||
'<th class="n">16px 连通体</th></tr></thead><tbody>')
|
||
for nm, key, nnode, nloop, nk in rows:
|
||
P.append('<tr><td><b>%s</b></td><td class="n">%d</td><td class="n">%s</td>'
|
||
'<td class="n" data-cell="%s@loops">…</td>'
|
||
'<td class="n" data-cell="%s@ink">…</td>'
|
||
'<td class="n" data-cell="%s@w512">…</td>'
|
||
'<td class="n" data-cell="%s@w16">…</td>'
|
||
'<td class="n" data-cell="%s@c16">…</td></tr>'
|
||
% (nm, nnode, ("%.1f" % nk) if nk is not None else "—",
|
||
key, key, key, key, key))
|
||
P.append('</tbody></table>')
|
||
P.append('<p><b>16px 连通体</b>是这一刀的主判据:=1 说明颈活到了 16 像素,'
|
||
'≥2 说明已经断成豆子。</p>'
|
||
'<p><b>换掉了一个指标。</b>原来这两列是「最细特征」(全局 minRun),'
|
||
'实测发现它对全弯轮廓不可信:最胖的 A1 报 1.00px、比最瘦的 A5 的 4.00px '
|
||
'还小 —— 非单调即指标失效,原因是弧形边的抗锯齿毛刺本身就只有 1px。'
|
||
'改成<b>沿中轴量腰</b>:过形心那一列上、包含形心的那段连续墨长。'
|
||
'两珠水平排布时它就是颈,且对 A 族可以和解析式 2√(2r²−d²/4) 对账。</p>')
|
||
P.append('<p id="ctrl">仪器对照:计算中…</p>')
|
||
|
||
P.append('<footer>生成器 <code>goo.py</code> · 液滴轮廓用纯 Python marching squares '
|
||
'解等值面 f=Σr²/d²=1(不是拼圆+贝塞尔近似,所以凹颈是场自己长出来的)· '
|
||
'环不判向,嵌套交给 evenodd · 解析颈宽 2√(2r²−d²/4) 与栅格实测对账 · '
|
||
'书法四字取自 <code>public/logo.svg</code> 真迹路径(只缩放)· '
|
||
'repo 零改动</footer>')
|
||
|
||
P.append(r"""<script>
|
||
const WHT=[255,255,255];
|
||
function isAny(p,a){return a>=40&&Math.hypot(p[0]-255,p[1]-255,p[2]-255)>=110;}
|
||
function ras(el,size){return new Promise(r=>{const s=new XMLSerializer().serializeToString(el);
|
||
const im=new Image(),cv=document.createElement('canvas');cv.width=size;cv.height=size;
|
||
const x=cv.getContext('2d');x.fillStyle='#fff';x.fillRect(0,0,size,size);
|
||
im.onload=()=>{x.drawImage(im,0,0,size,size);r(x.getImageData(0,0,size,size));};
|
||
im.onerror=()=>r(null);im.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(s);});}
|
||
function ink(im){const d=im.data;let n=0;for(let i=0;i<d.length;i+=4){
|
||
if(isAny([d[i],d[i+1],d[i+2]],d[i+3]))n++;}return 100*n/(d.length/4);}
|
||
function runs(im,px,vert){const d=im.data;let best=Infinity;
|
||
for(let a=0;a<px;a++){let c=0;
|
||
for(let b=0;b<px;b++){const i=((vert?b:a)*px+(vert?a:b))*4;
|
||
if(isAny([d[i],d[i+1],d[i+2]],d[i+3]))c++;else{if(c)best=Math.min(best,c);c=0;}}
|
||
if(c)best=Math.min(best,c);}
|
||
return best===Infinity?0:best;}
|
||
/* 颈宽实测:过形心那一列上、包含形心的那段连续墨长。
|
||
两珠水平排布时这就是腰。不用全局 minRun —— 全弯轮廓下 minRun 被
|
||
抗锯齿毛刺主导(实测最胖的 A1 报 1.00px、比最瘦的 A5 的 4.00px 还小,
|
||
非单调即指标失效)。 */
|
||
function waist(im,px){const d=im.data;const x=px>>1;let best=0,run=0,hit=false;
|
||
for(let y=0;y<px;y++){const i=(y*px+x)*4;
|
||
if(isAny([d[i],d[i+1],d[i+2]],d[i+3])){run++;if(y===(px>>1))hit=true;}
|
||
else{if(hit&&best===0)best=run;run=0;}}
|
||
if(hit&&best===0)best=run;return best;}
|
||
function comps(im,px,edge){const d=im.data;const m=new Uint8Array(px*px);
|
||
for(let i=0;i<px*px;i++){const j=i*4;m[i]=isAny([d[j],d[j+1],d[j+2]],d[j+3])?1:0;}
|
||
const seen=new Uint8Array(px*px);let big=0;const fl=edge?px*px*0.0025:px*px*0.0008;
|
||
for(let i=0;i<px*px;i++){if(!m[i]||seen[i])continue;let n=0;const st=[i];seen[i]=1;
|
||
while(st.length){const p=st.pop();n++;const x=p%px,y=(p-x)/px;
|
||
for(const [dx,dy] of [[1,0],[-1,0],[0,1],[0,-1]]){const nx=x+dx,ny=y+dy;
|
||
if(nx<0||ny<0||nx>=px||ny>=px)continue;const q=ny*px+nx;
|
||
if(m[q]&&!seen[q]){seen[q]=1;st.push(q);}}}
|
||
if(n>=fl)big++;}
|
||
return big;}
|
||
(async()=>{
|
||
const out={};
|
||
for(const el of document.querySelectorAll('.grid svg[data-k]')){
|
||
const k=el.dataset.k;
|
||
const i512=await ras(el,512),i40=await ras(el,40),i16=await ras(el,16);
|
||
if(!i512||!i40||!i16)continue;
|
||
out[k]=Object.assign({},out[k],{ink:ink(i512),loops:comps(i512,512,true),
|
||
m40:Math.min(runs(i40,40,false),runs(i40,40,true)),
|
||
m16:Math.min(runs(i16,16,false),runs(i16,16,true)),
|
||
c16:comps(i16,16,true),w16:waist(i16,16),w512:waist(i512,512)});
|
||
}
|
||
document.querySelectorAll('[data-cell]').forEach(td=>{
|
||
const c=td.dataset.cell,at=c.lastIndexOf('@');
|
||
const k=c.slice(0,at),f=c.slice(at+1),o=out[k];if(!o)return;
|
||
if(f==='ink')td.textContent=o.ink.toFixed(1)+'%';
|
||
else if(f==='loops')td.textContent=o.loops;
|
||
else if(f==='c16'){td.textContent=o.c16;td.style.color=o.c16<=1?'#0f7b3b':'#C41E3A';}
|
||
else if(f==='w16'){td.textContent=o.w16+'px';
|
||
td.style.color=o.w16>=2?'#0f7b3b':'#C41E3A';}
|
||
else if(f==='w512')td.textContent=(o.w512*120/512).toFixed(1);
|
||
});
|
||
/* 构造级对照:答案由构造决定 —— 完全重合的两圆必 1 个连通体、
|
||
远隔的两圆必 2 个。这两条不过,comps/等值面就是写坏了。 */
|
||
const mk=(nd)=>{const s='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" '+
|
||
'width="512" height="512"><path fill="#C41E3A" fill-rule="nonzero" d="'+
|
||
unionPath(nd)+'"/></svg>';
|
||
return new Promise(async(res)=>{
|
||
const im=new Image();im.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(s);
|
||
im.onload=()=>{const cv=document.createElement('canvas');cv.width=512;cv.height=512;
|
||
const x=cv.getContext('2d');x.fillStyle='#fff';x.fillRect(0,0,512,512);
|
||
x.drawImage(im,0,0,512,512);res(x.getImageData(0,0,512,512));};
|
||
im.onerror=()=>res(null);});};
|
||
|
||
/* 对照要的是【两圆的并】,必须 nonzero:
|
||
用 evenodd 会把相交的透镜挖空,剩下两瓣只在两个点上相接,
|
||
栅格就判成 2 个连通体 —— 第一版对照自己就是错的,反而把好的实现冤枉了。 */
|
||
function unionPath(nd){let s='';for(const [cx,cy,r] of nd){s+='M '+(cx-r)+' '+cy+
|
||
' A '+r+' '+r+' 0 1 1 '+(cx+r)+' '+cy+' A '+r+' '+r+' 0 1 1 '+(cx-r)+' '+cy+' Z ';}
|
||
return s;}
|
||
const one=await mk([[52,60,26],[68,60,26]]);
|
||
const two=await mk([[28,60,20],[92,60,20]]);
|
||
const c1=one?comps(one,512,true):-1, c2=two?comps(two,512,true):-1;
|
||
const unres=[...document.querySelectorAll('[data-cell]')].filter(e=>e.textContent==='…').length;
|
||
const okc=(c1===1&&c2===2);
|
||
document.getElementById('ctrl').innerHTML='构造级对照(圆并):两圆完全重合 测得 '+c1+
|
||
' 应为 1 · 两圆远隔 测得 '+c2+' 应为 2 · 未解析格数 = '+unres+
|
||
'<br><b style="color:'+((okc&&unres===0)?'#0f7b3b':'#C41E3A')+'">'+
|
||
((okc&&unres===0)?'对照通过,本页连通体/最细特征可用':'对照不过,连通体读数作废')+'</b>';
|
||
window.__goo={out:out,unresolved:unres,ctl:[c1,c2]};
|
||
})();
|
||
</script>""")
|
||
P.append('</div></body></html>')
|
||
return "".join(P)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
html = build()
|
||
out = os.path.join(HERE, "goo.html")
|
||
with open(out, "w", encoding="utf-8") as f:
|
||
f.write(html)
|
||
os.makedirs(os.path.join(HERE, "assets-goo"), exist_ok=True)
|
||
for title, axnote, items in FAMS:
|
||
for nm, nodes, why in items:
|
||
key = nm.split()[0]
|
||
d, nloop = path_d(nodes)
|
||
with open(os.path.join(HERE, "assets-goo", key + ".svg"), "w",
|
||
encoding="utf-8") as fh:
|
||
fh.write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g">'
|
||
'<path fill="%s" fill-rule="evenodd" d="%s"/></svg>'
|
||
% (VB, VB, RED, d))
|
||
nk = neck(nodes[1][0] - nodes[0][0], nodes[0][2]) if key.startswith("A") else None
|
||
if nk is not None:
|
||
nk /= 2.0 * nodes[0][2]
|
||
print("%-4s 珠 %d 环 %d 颈/珠径 %s"
|
||
% (key, len(nodes), nloop, ("%.2f" % nk) if nk is not None else "—"))
|
||
print("goo.html %s B" % format(len(html.encode("utf-8")), ","))
|