Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

fix(geometry): let rectsOverlap clear float rounding at the layout minimum (#583)

Aashish652227f4eb19
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3cacff10..ea1bb85c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@ All notable changes are documented here. Format loosely follows [Keep a Changelo
- **Japanese entry point under the same maintenance contract.** `README_JA.md` joins the language switcher and every README parity check: brand mark and demo-section placement, the animated proof and demo deep links, share-card and real-repository proofs, the update-awareness disclosure, the Hermes Agent and DSH installation rows, the self-hosted Star History ending, and release-identity validation of the version badge, the Japanese development marker, and the Raven manual-ZIP boundary. The switcher check is now driven by one per-language table, so a future language is added in one place.
### Fixed
+- **Node clearance at the solver's exact minimum (#583).** `rectsOverlap` now compares separations with the same `0.0001` numeric tolerance the route and layout geometry already uses, so a column the layout solver separated by exactly its minimum no longer reads as overlapping because of float rounding. Genuine closeness still reports; a shortfall an author could act on remains well outside the tolerance.
- **Lifecycle transition notes (#549).** Notes render when the transition label is omitted or empty, with matching route-space reservations and collision checks; existing label-only and label-plus-note layouts retain their behavior.
- **Brand content-encoding negotiation (#514).** Capture and pinned re-fetches request identity encoding and reject unexpected encoded response bodies before parsing or hashing, with the coding error preserved if favicon fallback also fails.
- **Escaped brand icon URLs (#454).** Favicon discovery decodes basic named and numeric HTML character references once before URL resolution, preserving percent escapes and the existing network and digest checks.
diff --git a/archify.zip b/archify.zip
index 19ade230..f3ffa4f9 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/renderers/shared/geometry.mjs b/archify/renderers/shared/geometry.mjs
index 7d5331e6..cd8882c7 100644
--- a/archify/renderers/shared/geometry.mjs
+++ b/archify/renderers/shared/geometry.mjs
@@ -17,6 +17,14 @@ export function isFinitePoint(...coords) {
return coords.every((c) => Number.isFinite(c));
}
+// Separation the layout solver guarantees and separation this check re-derives
+// travel through different arithmetic, so a pair the solver placed at exactly
+// its minimum can land a few ulps short of this comparison. In #583 the CLI's
+// own receipt has the pair `793.6 + 160 + 8` read as 2**-43 past a5's left edge
+// at 961.5999999999999 — one ulp at that magnitude. 0.0001 is the numeric
+// tolerance the route and layout geometry in this file already compares with.
+const NUMERIC_CLEARANCE_PX = 0.0001;
+
export function rectsOverlap(a, b, gap = 0) {
// Non-finite geometry means "unknown", not "overlapping". Every comparison
// below is false for NaN, so without this guard the negation reports a
@@ -27,10 +35,10 @@ export function rectsOverlap(a, b, gap = 0) {
return false;
}
return !(
- a.x + a.width + gap <= b.x ||
- b.x + b.width + gap <= a.x ||
- a.y + a.height + gap <= b.y ||
- b.y + b.height + gap <= a.y
+ a.x + a.width + gap <= b.x + NUMERIC_CLEARANCE_PX ||
+ b.x + b.width + gap <= a.x + NUMERIC_CLEARANCE_PX ||
+ a.y + a.height + gap <= b.y + NUMERIC_CLEARANCE_PX ||
+ b.y + b.height + gap <= a.y + NUMERIC_CLEARANCE_PX
);
}
diff --git a/archify/test/geometry.test.mjs b/archify/test/geometry.test.mjs
index faa997f0..694a3be3 100644
--- a/archify/test/geometry.test.mjs
+++ b/archify/test/geometry.test.mjs
@@ -116,6 +116,35 @@ test('rectsOverlap: positive gap flags rects within that gap as too close', () =
assert.equal(rectsOverlap(rect(0, 0, 10, 10), rect(17, 0, 10, 10), 8), true);
});
+test('rectsOverlap: a clearance the solver measured short of by one ulp is met (#583)', () => {
+ // The column solver separates neighbouring centers by width/2 + gap + width/2,
+ // and the clearance check re-derives the same distance from the left node's x
+ // and width. Centers 873.6 and 1041.6 are 167.99999999999988631 apart, so the
+ // check's sum lands 1.14e-13px past the node it was built to clear.
+ const left = rect(873.6 - 80, 93, 160, 52);
+ const right = rect(1041.6 - 80, 93, 160, 52);
+ assert.ok(
+ left.x + left.width + 8 > right.x,
+ 'the reproduction must reach the check as a float shortfall, not as a clean gap',
+ );
+ assert.equal(rectsOverlap(left, right, 8), false);
+ assert.equal(rectsOverlap(right, left, 8), false, 'the swapped pair must agree');
+ // The same float error appears down a column, so all four separations need it.
+ const above = rect(93, 873.6 - 80, 52, 160);
+ const below = rect(93, 1041.6 - 80, 52, 160);
+ assert.ok(above.y + above.height + 8 > below.y);
+ assert.equal(rectsOverlap(above, below, 8), false);
+ assert.equal(rectsOverlap(below, above, 8), false);
+});
+
+test('rectsOverlap: the numeric tolerance stays far below a repairable shortfall', () => {
+ // The tolerance covers float error, not a shortfall an author could act on:
+ // 0.001px under the minimum still reports, so widening it tenfold breaks here.
+ assert.equal(rectsOverlap(rect(0, 0, 160, 52), rect(167.999, 0, 160, 52), 8), true);
+ assert.equal(rectsOverlap(rect(0, 0, 160, 52), rect(167.9, 0, 160, 52), 8), true);
+ assert.equal(rectsOverlap(rect(0, 0, 160, 52), rect(168, 0, 160, 52), 8), false);
+});
+
test('rectsOverlap: negative gap shrinks the hit box (label-collision convention)', () => {
// gap -2 means rects must overlap by MORE than 2px to count — a 1px sliver
// does not. This is the sign convention the label checks rely on.
diff --git a/archify/test/layout-rules.test.mjs b/archify/test/layout-rules.test.mjs
index f777519d..08ad3f48 100644
--- a/archify/test/layout-rules.test.mjs
+++ b/archify/test/layout-rules.test.mjs
@@ -366,6 +366,60 @@ for (const [name, mode, mutate, expected] of CASES) {
});
}
+test('workflow: same-lane nodes the solver separated by exactly 8px keep passing (#583)', () => {
+ // Redacted reproduction from #583: the neighbour constraint puts column
+ // centers at 873.6 and 1041.6, a 167.9999999999999 distance the check re-derives
+ // from the nodes' left edges as 1.14e-13px past a5. The compiler rejected the
+ // layout it had just produced, with an empty supportedFixes list.
+ const doc = {
+ schema_version: 2,
+ diagram_type: 'workflow',
+ meta: { title: 'Clearance rounding', quality_profile: 'showcase' },
+ lanes: [
+ { id: 'upper', label: 'Upper: the first lane' },
+ { id: 'lower', label: 'Lower lane: second lane' },
+ ],
+ nodes: [
+ { id: 's0', lane: 'lower', col: 0, type: 'backend', label: 'Start', width: 160 },
+ { id: 'a1', lane: 'upper', col: 1, type: 'backend', label: 'Step one', width: 160 },
+ { id: 'a2', lane: 'upper', col: 2, type: 'backend', label: 'Step two', width: 160 },
+ { id: 'a3', lane: 'upper', col: 3, type: 'backend', label: 'Step three', width: 160 },
+ { id: 'a4', lane: 'upper', col: 4, type: 'backend', label: 'Step four', width: 160 },
+ { id: 'a5', lane: 'upper', col: 5, type: 'backend', label: 'Step five', width: 160 },
+ ],
+ edges: [
+ { id: 's0-a1', from: 's0', to: 'a1', fromSide: 'top', toSide: 'left' },
+ { id: 'a3-a4', from: 'a3', to: 'a4' },
+ ],
+ };
+
+ const { code, result } = validateCli('workflow', doc);
+ assert.equal(code, 0, JSON.stringify(result, null, 2));
+ assert.equal(result.ok, true, JSON.stringify(result.diagnostics, null, 2));
+
+ // The painted pair must sit on the minimum, not comfortably clear of it, or
+ // this regression would pass with the tolerance set to anything.
+ const rendered = render('workflow', doc);
+ assert.equal(rendered.code, 0, rendered.stderr);
+ const html = fs.readFileSync(rendered.outPath, 'utf8');
+ const left = workflowNodeRect(html, 'a4');
+ const right = workflowNodeRect(html, 'a5');
+ const paintedGap = right.x - (left.x + left.width);
+ assert.ok(
+ Math.abs(paintedGap - 8) < 1e-6,
+ `expected a4 and a5 to paint 8px apart, measured ${paintedGap}`,
+ );
+
+ const overlapping = JSON.parse(JSON.stringify(doc));
+ overlapping.nodes[5].col = 4;
+ const { result: overlapResult } = validateCli('workflow', overlapping);
+ assert.equal(overlapResult.ok, false, JSON.stringify(overlapResult, null, 2));
+ assert.ok(
+ overlapResult.diagnostics.some((diagnostic) => diagnostic.code === 'workflow/node-overlap'),
+ JSON.stringify(overlapResult.diagnostics, null, 2),
+ );
+});
+
test('architecture: ordinary boundaries may express orthogonal overlapping memberships', () => {
const d = load('architecture');
d.boundaries[1].wraps.push('auth');