fix(rebar): section labels once per bar and spots once

- The coping section listed every piece of a bar as its own crossing, so the
  same spot and name were drawn many times. Each spot is drawn once and each
  bar name is written once.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
ypshimandClaude Haiku 5.5 committed 2026-10-26 14:28:33 +09:00
1 parent 57f7c148ec
commit 32cf01a29f
2 files changed
+26 -2

No files matched your search

+17 -2
View File
@@ -55,9 +55,24 @@ export function copingSectionSvg(records: BarRecord[], s0: number): string {
crossings.push({ name: r.name, x: a[2] + (b[2] - a[2]) * t, y: a[1] + (b[1] - a[1]) * t, group: copingBarGroup(r.name) });
}
}
const xs = crossings.map((c) => c.x * 1000);
// The same bar is recorded in several pieces, so the same spot can be crossed more than once: draw each spot once,
// and write each bar name once (at its first crossing), so the labels do not pile up.
const seen = new Set<string>();
const named = new Set<string>();
const unique = crossings.filter((c) => {
const key = `${Math.round(c.x * 1e4)}|${Math.round(c.y * 1e4)}|${c.name}`;
if (seen.has(key)) return false;
seen.add(key);
return true;
});
const xs = unique.map((c) => c.x * 1000);
const minX = Math.min(...xs, 0);
const maxX = Math.max(...xs, 0);
const parts: string[] = crossings.map((c) => `<circle cx="${c.x * 1000}" cy="${(top - c.y) * 1000}" r="${c.group === 'step' ? 22 : 30}" fill="${COLOR[c.group]}"></circle><text x="${c.x * 1000 + 40}" y="${(top - c.y) * 1000 - 40}" font-size="140" fill="#18212B">${c.name}</text>`);
const parts: string[] = unique.map((c) => {
const dot = `<circle cx="${c.x * 1000}" cy="${(top - c.y) * 1000}" r="${c.group === 'step' ? 22 : 30}" fill="${COLOR[c.group]}"></circle>`;
if (named.has(c.name)) return dot;
named.add(c.name);
return `${dot}<text x="${c.x * 1000 + 60}" y="${(top - c.y) * 1000 - 60}" font-size="120" fill="#18212B">${c.name}</text>`;
});
return `<svg viewBox="${minX - 800} -800 ${maxX - minX + 1600} ${(top - Math.min(...els)) * 1000 + 1600}" width="100%" style="max-width: 560px; height: auto" role="img" aria-label="코핑 배근 단면 · 폐합 구성 at s = ${s0} m">${parts.join('')}</svg>`;
}