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 个文本/矢量件。
431 lines
23 KiB
Python
431 lines
23 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
层云 / 地层(第四十刀)—— 甲方新参照:横条堆叠成方,白缝在中间张成一座山
|
||
|
||
参照图实测出来的四条语法(缺一条就退回"横纹装饰"或"数码管"):
|
||
① 条是弯的,而且**上下边同向弧弯、等厚** —— 像刨出来的木板,不是缩放出来的波浪贴纸。
|
||
② 方形**没有侧墙**:轮廓全靠条的两端齐平暗示出来。
|
||
这条正是本项目那条判据的正解 —— 判死横条族的不是"框内有横",是**墙闭没闭**。
|
||
把两侧墙整条删掉(这里连删都不用,因为从来没画过),同一批横线就读作字/卦/印。
|
||
③ 白缝不是均匀的:中间张开成一座山 ⇒ **负形在识字**。这是它和"条纹方块"的分水岭。
|
||
④ 有一根破格伸出(不可复制的异常),且条长有节奏。
|
||
|
||
移植到 睿新致远 / NOVALON 时换掉两样东西:
|
||
· 颜色用朱砂(甲方锁死),不用参照图的蓝。
|
||
· 负形不能是"山"——那是人家的。用我们自己的字理:
|
||
《说文》「叡,深明也。通也。从、从目,从谷省」;段玉裁「**谷以皃其深也**」
|
||
「能容而後能明」;《六书正讹》「谷取其响应不穷」。
|
||
⇒ 负形取**谷**(两山夹一谷),一家咨询公司卖的是"能容而后能明"。
|
||
· 字标用仓库里那四个真迹(_wm-chars.json),排版照参照图:
|
||
图在上、书法在下、每字正上方一颗极小的注音。
|
||
|
||
每格相对基准只改一件事(单因子纪律)。
|
||
"""
|
||
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 = "#C41E3A", "#26221E", "#FFFFFF"
|
||
PAPER = "#F7F4EF"
|
||
|
||
W = 120.0
|
||
X0, X1 = 14.0, 106.0
|
||
Y0, Y1 = 16.0, 104.0
|
||
|
||
|
||
def bump(x, c, s):
|
||
return math.exp(-((x - c) ** 2) / (2.0 * s * s))
|
||
|
||
|
||
def ridge(x, kind):
|
||
"""山体高度剖面(0..1)。负形的下缘 = 这条线;上缘只抬一点点,
|
||
所以缺口读起来是「一座山坐在一条地上」,而不是「中间挖了个洞」。"""
|
||
if kind == "mount": # 主峰偏右 + 一道肩 —— 参照图那种
|
||
return max(0.0, 0.88 * bump(x, 0.62, 0.19) + 0.44 * bump(x, 0.28, 0.12))
|
||
if kind == "valley": # 两山夹一谷 —— 睿之「谷」,取其深、响应不穷
|
||
return max(0.0, 1.0 - 0.92 * bump(x, 0.50, 0.135))
|
||
if kind == "twin": # 双峰等量
|
||
return max(0.0, min(1.0, 0.80 * bump(x, 0.30, 0.13) + 0.80 * bump(x, 0.70, 0.13)))
|
||
if kind == "flat": # 对照:不张嘴
|
||
return 0.0
|
||
if kind == "eye": # 中间一座独峰 —— 负形收成一道竖目
|
||
return max(0.0, bump(x, 0.50, 0.085))
|
||
raise AssertionError("未知负形 %s" % kind)
|
||
|
||
|
||
BASE = dict(n=9, t=6.6, k=5, s=12.0, up=0.34, kind="mount", ripple=0.55,
|
||
ragged=0.0, breakout=None)
|
||
|
||
|
||
def bands(n=BASE["n"], t=BASE["t"], k=BASE["k"], s=BASE["s"], up=BASE["up"],
|
||
kind=BASE["kind"], ripple=BASE["ripple"], ragged=BASE["ragged"],
|
||
breakout=BASE["breakout"], steps=150):
|
||
"""两条子堆叠被一座山隔开:上堆整体抬起 up*s*ridge,下堆整体落下 s*ridge。
|
||
等厚由构造保证 —— 上下边是同一条中心曲线各移半厚。"""
|
||
if n < 3:
|
||
raise AssertionError("条数 %d 太少" % n)
|
||
if not 0 < k < n:
|
||
raise AssertionError("分裂位 k=%d 不在 (0,%d)" % (k, n))
|
||
pitch = (Y1 - Y0) / float(n)
|
||
if t >= pitch:
|
||
raise AssertionError("条厚 %g ≥ 间距 %g,会并成实心块" % (t, pitch))
|
||
out = []
|
||
for i in range(n):
|
||
lift = (-up if i < k else 1.0) * s # 上堆抬(-y)、下堆落(+y),中间才张得开口子
|
||
pts = []
|
||
for j in range(steps + 1):
|
||
u = j / float(steps)
|
||
x = X0 + (X1 - X0) * u
|
||
ph = i * 1.9 # 每条错相位,避免像复制粘贴
|
||
r = ripple * (math.sin(2 * math.pi * (u * 1.6) + ph) * 0.5 +
|
||
math.sin(2 * math.pi * (u * 3.7) + ph * 1.7) * 0.22)
|
||
y = Y0 + pitch * (i + 0.5) + lift * ridge(u, kind) + r
|
||
pts.append((x, y))
|
||
xb1 = X1
|
||
if ragged:
|
||
xb1 = X1 - ragged * pitch * ((i * 3) % 4)
|
||
if breakout is not None and i == breakout:
|
||
xb1 = X1 + 11.0 # 一根破格伸出方外
|
||
top = [(x, y - t / 2.0) for x, y in pts]
|
||
bot = [(x, y + t / 2.0) for x, y in pts]
|
||
keep = [x for x, _ in top if x <= xb1 + 1e-9]
|
||
if len(keep) < 8:
|
||
raise AssertionError("条 %d 被裁得太短(只剩 %d 点)" % (i, len(keep)))
|
||
ring = top[:len(keep)] + list(reversed(bot[:len(keep)]))
|
||
out.append(("M " + " L ".join("%g %g" % q for q in ring) + " Z", pts))
|
||
return out
|
||
|
||
|
||
def mark(**kw):
|
||
p = dict(BASE)
|
||
p.update(kw)
|
||
bs = bands(**p)
|
||
return '<path fill="%s" d="%s"/>' % (RED, " ".join(b[0] for b in bs)), bs
|
||
|
||
|
||
def gap_stats(bs, n, t):
|
||
"""逐 x 量相邻两条之间的白缝,返回 (最大缝, 最小缝)。"""
|
||
import array
|
||
steps = len(bs[0][1]) - 1
|
||
lo, hi = 1e9, 0.0
|
||
for j in range(0, steps + 1, 3):
|
||
ys = [bs[i][1][j][1] for i in range(n)]
|
||
for i in range(n - 1):
|
||
g = (ys[i + 1] - t / 2.0) - (ys[i] + t / 2.0)
|
||
lo = min(lo, g)
|
||
hi = max(hi, g)
|
||
return hi, max(0.3, lo)
|
||
|
||
|
||
def svg(inner, px, key=None):
|
||
k = ' data-k="%s"' % key if key else ""
|
||
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g" '
|
||
'style="width:%dpx;height:%dpx;display:block"%s>%s</svg>'
|
||
% (W, W, px, px, k, inner))
|
||
|
||
|
||
def char_svg(i, cx, cy, size, col=INK):
|
||
return r2.char_svg(i, cx, cy, size, col)
|
||
|
||
|
||
PINYIN = ["RUI", "XIN", "ZHI", "YUAN"]
|
||
|
||
|
||
def lockup(inner, px, ccol=INK):
|
||
"""竖锁定:图在上,书法在下,每字正上方一颗极小注音(照参照图那个细节)。"""
|
||
h, cw = 30.0, 34.0
|
||
total = 4 * cw
|
||
x0 = (W - total) / 2.0 + cw / 2.0
|
||
cal = "".join(char_svg(i, x0 + i * cw, Y1 + 30.0, h, ccol) for i in range(4))
|
||
py = "".join('<text x="%g" y="%g" font-family="Helvetica,Arial,sans-serif" '
|
||
'font-size="4.6" letter-spacing="0.6" text-anchor="middle" '
|
||
'fill="%s">%s</text>' % (x0 + i * cw, Y1 + 12.0, ccol, PINYIN[i])
|
||
for i in range(4))
|
||
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g" '
|
||
'style="width:%dpx;height:auto;display:block">%s%s%s</svg>'
|
||
% (W, Y1 + 52.0, px, inner, cal, py))
|
||
|
||
|
||
CELLS = [
|
||
("S0 基准·谷", dict(kind="valley"),
|
||
"九条等厚弧条,两端齐平、无侧墙;两堆之间被一座「谷」撑开 —— 中间最深、两侧合拢。"
|
||
"睿从谷省,段玉裁说「谷以皃其深也」,《六书正讹》说「谷取其响应不穷」。这是我的主张。"),
|
||
("S1 负形=山", dict(kind="mount"),
|
||
"只把负形翻过来:中间一座主峰加一道肩,就是参照图那个读法。与 S0 只差负形剖面。"),
|
||
("S2 负形=独峰", dict(kind="eye"),
|
||
"只换剖面:中间一座窄峰,白缝收成一道竖目。睿从目、「目取其明」。"),
|
||
("S3 无负形", dict(kind="flat"),
|
||
"对照,不是提案:白缝均匀。这一格专门量「负形到底值多少」——"
|
||
"如果它和 S0/S1 的读数与观感几乎一样,那负形就是我加戏。"),
|
||
("S4 一根破格", dict(kind="valley", breakout=6),
|
||
"在 S0 上只加一处异常:第 7 条向右伸出方外。参照图那条不可复制的偏差。"),
|
||
("S5 两端参差", dict(kind="valley", ragged=0.42),
|
||
"只改右端:不再齐平,按条错位。方形轮廓从「靠齐平暗示」变成「靠重心维持」。"),
|
||
("S6 条数减半", dict(kind="valley", n=5, t=9.4, k=3, s=9.0),
|
||
"为 16px 活下来做的努力:五条、更厚、缝更少。看这一族的最小尺寸天花板在哪。"),
|
||
("S7 抬得更高", dict(kind="valley", up=0.62),
|
||
"只改上堆的抬升量:负形上缘由「近乎平」变成「也拱起来」,"
|
||
"看山体读法什么时候开始退化成「中间一个洞」。"),
|
||
]
|
||
|
||
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 .no{color:#C41E3A;margin-right:10px}
|
||
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(4,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 13.5px/1.35 "PingFang SC",Inter,sans-serif;color:#26221E;min-height:22px}
|
||
.fig{text-align:center;padding:8px 0}
|
||
.mt{font:11px/1.7 "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.65 "PingFang SC",Inter,sans-serif;color:#4F4A42;
|
||
border-top:1px solid #EFEAE1;margin-top:9px;padding-top:8px}
|
||
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 void_ratio(bs, n, t):
|
||
"""负形张开度 = 最大白缝 / 最小白缝。1.00 就是均匀条纹(数码管那一侧)。
|
||
⚠ 它只量「开多深」,量不出「开成什么形」—— 山、谷、独峰三种剖面的 max/min 都是 1,
|
||
实测三格同读数 12.88×。那是指标瞎,不是设计同。形状交给 void_shape 量。"""
|
||
hi, lo = gap_stats(bs, n, t)
|
||
return hi / lo
|
||
|
||
|
||
def void_shape(bs, n, k, t, frac=2.0):
|
||
"""沿 x 看分裂处那条缝(第 k-1 与第 k 条之间):
|
||
段数 = 有几段缝高 > frac×最紧缝 ⇒ 山=1、谷=2、独峰=1、均匀=0
|
||
占宽 = 这些段的总宽 / 全宽
|
||
⚠ 基准必须取【最紧缝】,不能取中位数:谷那一种,沿 x 大多数位置都是张开的,
|
||
中位数就落在"张开值"上,于是 2×中位数谁都超不过,段数恒 0 —— 第一版就是这么瞎的。
|
||
"""
|
||
if not 0 < k < n:
|
||
raise AssertionError("分裂位 k=%d 不在 (0,%d)" % (k, n))
|
||
steps = len(bs[0][1]) - 1
|
||
# 量的是【白缝】,不是中心线间距:中心线差里含着一条的厚度 t,
|
||
# 不减掉的话 t 越大越把变化量淹掉 —— S6(5 条、厚 9.4)就是这么被读成 0 段的。
|
||
prof = [bs[k][1][j][1] - bs[k - 1][1][j][1] - t for j in range(steps + 1)]
|
||
lo = min(prof)
|
||
thr = lo * frac
|
||
runs, wide, inrun = 0, 0, False
|
||
for v in prof:
|
||
if v > thr:
|
||
wide += 1
|
||
if not inrun:
|
||
runs += 1
|
||
inrun = True
|
||
else:
|
||
inrun = False
|
||
return runs, wide / float(len(prof))
|
||
|
||
|
||
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 40 · 2026-10-14 · 新参照:横条堆叠 + 负形识字 · repo 零改动</div>')
|
||
P.append('<h1>横条堆叠:<em>负形在识字</em></h1>')
|
||
P.append('<p class="lede">这张图的语法有四个零件,缺任何一个就退回"条纹方块"或"数码管":'
|
||
'条是弯的且等厚;方形没有侧墙;白缝在中间张成东西;有一根破格。'
|
||
'移植到我们这儿换掉两样 —— 颜色用朱砂,负形不用"山"(那是人家的),'
|
||
'用我们自己的字理:<b>谷</b>。</p>')
|
||
P.append('<div class="j"><b>为什么是谷。</b>《说文》「叡,深明也。通也。从、从目,'
|
||
'从<b>谷</b>省」;段玉裁「<b>谷以皃其深也</b>」「能容而後能明」;'
|
||
'《六书正讹》「谷取其响应不穷」。一家卖架构与响应的咨询公司,'
|
||
'横条同时是"层"(架构分层)也是"云/水纹",而中间那道空是谷 —— '
|
||
'能容而后能明。这比借一座山是我们的东西。</div>')
|
||
|
||
rows = []
|
||
P.append('<div class="grid">')
|
||
for nm, kw, why in CELLS:
|
||
inner, bs = mark(**kw)
|
||
vr = void_ratio(bs, kw.get("n", BASE["n"]), kw.get("t", BASE["t"]))
|
||
runs, cover = void_shape(bs, kw.get("n", BASE["n"]), kw.get("k", BASE["k"]),
|
||
kw.get("t", BASE["t"]))
|
||
key = nm.split()[0]
|
||
rows.append((nm, key, kw, vr, runs, cover))
|
||
cls = "c pick" if key == "S0" else "c"
|
||
P.append('<div class="%s"><div class="nm">%s</div><div class="fig">%s</div>'
|
||
'<div class="mt">%d 条 · 厚 %g · 张开 <span class="%s">%.2f×</span> · '
|
||
'张口 <b>%d</b> 段 / 占宽 %.0f%%</div>'
|
||
'<div class="nt">%s</div></div>'
|
||
% (cls, nm, svg(inner, 176, key), kw.get("n", BASE["n"]),
|
||
kw.get("t", BASE["t"]), "good" if vr > 1.6 else "bad", vr,
|
||
runs, 100.0 * cover, why))
|
||
P.append('</div>')
|
||
P.append('<p><b>负形张开度</b> = 白缝最大高度 ÷ 白缝最小高度。1.00 就是均匀条纹(数码管那一侧);'
|
||
'这一栏是这一刀的主判据 —— 它回答"负形到底在不在"。</p>')
|
||
|
||
P.append('<h2><span class="no">1</span>竖锁定(照参照图:图在上、书法在下、每字上方一颗极小注音)</h2>')
|
||
P.append('<div class="lk">')
|
||
for key in ("S0", "S1", "S4"):
|
||
kw = dict(next(k3 for n3, k3, w3 in CELLS if n3.split()[0] == key))
|
||
inner, _bs = mark(**kw)
|
||
P.append('<div class="cell" style="text-align:center">%s'
|
||
'<div class="mt">%s · 朱砂条 + 墨字</div></div>'
|
||
% (lockup(inner, 210), key))
|
||
P.append('<div class="cell" style="text-align:center"><span style="display:inline-block;'
|
||
'background:#141210;border-radius:14px;padding:10px">%s</span>'
|
||
'<div class="mt">%s · 暖墨底反白</div></div>'
|
||
% (lockup(inner.replace(RED, WHITE), 210, ccol=WHITE), key))
|
||
P.append('</div>')
|
||
|
||
P.append('<h2><span class="no">2</span>实测</h2>')
|
||
P.append('<table><thead><tr><th>格</th><th class="n">负形张开</th>'
|
||
'<th class="n">张口段数/占宽</th>'
|
||
'<th class="n">连通体</th><th class="n">墨率@512</th>'
|
||
'<th class="n">最细特征@40</th><th class="n">最细特征@16</th>'
|
||
'<th class="n">缩放漂移</th></tr></thead><tbody>')
|
||
for nm, key, kw, vr, runs, cover in rows:
|
||
P.append('<tr><td><b>%s</b></td><td class="n">%.2f×</td>'
|
||
'<td class="n">%d 段 / %.0f%%</td>'
|
||
'<td class="n" data-cell="%s@comps">…</td>'
|
||
'<td class="n" data-cell="%s@ink">…</td>'
|
||
'<td class="n" data-cell="%s@m40">…</td>'
|
||
'<td class="n" data-cell="%s@m16">…</td>'
|
||
'<td class="n" data-cell="%s@drift">…</td></tr>'
|
||
% (nm, vr, runs, 100.0 * cover, key, key, key, key, key))
|
||
P.append('</tbody></table>')
|
||
P.append('<p id="ctrl">仪器对照:计算中…</p>')
|
||
P.append('<p><b>连通体</b>是这一族的命门:条与条不相接,所以它天然是 N 个分离块 —— '
|
||
'本项目那条工艺律(J2/碎片化:泰卦死于 9 个分离块)会在这里复发。'
|
||
'这一栏就是把"碎"量化,不靠感觉。</p>')
|
||
|
||
P.append('<footer>生成器 <code>strata.py</code> · 条的几何=同一条中心曲线上下各平移半厚 ⇒ '
|
||
'结构上保证等厚(参照图第①条)· 全程不画侧墙(第②条,也是本项目「墙闭没闭」判据的正解)· '
|
||
'负形剖面见 <code>void()</code> · 书法四字取自 <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;}
|
||
function comps(im,px){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 sizes=[];
|
||
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);}}}
|
||
sizes.push(n);if(n>=Math.round(px*px*0.0008))big++;}
|
||
return {big:big,all:sizes.length};}
|
||
(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;
|
||
const e5=ink(i512),e40=ink(i40);
|
||
out[k]=Object.assign({},out[k],{ink:e5,comps:comps(i512,512).big,
|
||
m40:Math.min(runs(i40,40,false),runs(i40,40,true)),
|
||
m16:Math.min(runs(i16,16,false),runs(i16,16,true)),drift:Math.abs(e5-e40)});
|
||
}
|
||
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==='comps')td.textContent=o.comps;
|
||
else if(f==='ink')td.textContent=o.ink.toFixed(1)+'%';
|
||
else if(f==='m40'){td.textContent=o.m40.toFixed(2)+'px';
|
||
td.style.color=o.m40>=2?'#0f7b3b':'#C41E3A';}
|
||
else if(f==='m16'){td.textContent=o.m16.toFixed(2)+'px';
|
||
td.style.color=o.m16>=2?'#0f7b3b':'#C41E3A';}
|
||
else if(f==='drift')td.textContent=o.drift.toFixed(1)+'pt';
|
||
});
|
||
/* 构造级对照:答案由构造决定 —— 纯白 0% / 纯红 100% /
|
||
两条已知分离块必须报 2 个连通体,报不出就是 comps 写坏了 */
|
||
const t=document.createElement('canvas');t.width=64;t.height=64;
|
||
const tc=t.getContext('2d');
|
||
tc.fillStyle='#fff';tc.fillRect(0,0,64,64);const neg=ink(tc.getImageData(0,0,64,64));
|
||
tc.fillStyle='#C41E3A';tc.fillRect(0,0,64,64);const pos=ink(tc.getImageData(0,0,64,64));
|
||
const two=await (async()=>{const s2='<svg xmlns="http://www.w3.org/2000/svg" '+
|
||
'viewBox="0 0 100 100" width="512" height="512"><rect x="10" y="10" width="20" height="20" '+
|
||
'fill="#C41E3A"/><rect x="60" y="60" width="20" height="20" fill="#C41E3A"/></svg>';
|
||
const im=new Image();im.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(s2);
|
||
await new Promise(r=>{im.onload=r;im.onerror=()=>r();});
|
||
const c2=document.createElement('canvas');c2.width=512;c2.height=512;
|
||
const x2=c2.getContext('2d');x2.fillStyle='#fff';x2.fillRect(0,0,512,512);
|
||
x2.drawImage(im,0,0,512,512);return comps(x2.getImageData(0,0,512,512),512).big;})();
|
||
const unres=[...document.querySelectorAll('[data-cell]')].filter(e=>e.textContent==='…').length;
|
||
const ok=(neg<0.05&&pos>99.95&&two===2&&unres===0);
|
||
document.getElementById('ctrl').innerHTML='墨色分类器:负·纯白 = '+neg.toFixed(1)+'% 应 0.0 · '
|
||
+'正·纯红 = '+pos.toFixed(1)+'% 应 100.0<br>构造级对照:两块分离方块 测得 '+two+
|
||
' 个连通体 应为 2 · 未解析格数 = '+unres+'<br><b style="color:'+
|
||
(ok?'#0f7b3b':'#C41E3A')+'">'+(ok?'四条全过,本页读数可用':'有一条不过,对应读数作废')+'</b>';
|
||
window.__st={out:out,unresolved:unres,controlsOk:ok};
|
||
})();
|
||
</script>""")
|
||
P.append('</div></body></html>')
|
||
return "".join(P)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
html = build()
|
||
out = os.path.join(HERE, "strata.html")
|
||
with open(out, "w", encoding="utf-8") as f:
|
||
f.write(html)
|
||
os.makedirs(os.path.join(HERE, "assets-strata"), exist_ok=True)
|
||
for nm, kw, why in CELLS:
|
||
inner, bs = mark(**kw)
|
||
key = nm.split()[0]
|
||
vr = void_ratio(bs, kw.get("n", BASE["n"]), kw.get("t", BASE["t"]))
|
||
runs, cover = void_shape(bs, kw.get("n", BASE["n"]), kw.get("k", BASE["k"]),
|
||
kw.get("t", BASE["t"]))
|
||
with open(os.path.join(HERE, "assets-strata", key + ".svg"), "w",
|
||
encoding="utf-8") as fh:
|
||
fh.write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 %g %g">%s</svg>'
|
||
% (W, W, inner))
|
||
print("%-4s %d 条 张开 %6.2fx 张口 %d 段 占宽 %3.0f%% %s"
|
||
% (key, kw.get("n", BASE["n"]), vr, runs, 100.0 * cover,
|
||
"★主张" if key == "S0" else ("均匀条纹" if vr < 1.2 else "")))
|
||
print("strata.html %s B" % format(len(html.encode("utf-8")), ","))
|