Skip to content

Editorial diagram design for Claude Code, Codex, GitHub Copilot, Cursor, Factory Droid, Qoder, and Pi. 45 diagram types. Self-contained HTML + SVG. No shadows. No Mermaid slop.

test(verify-geometry): fail diagonal, border-riding, corner, and shared-port connectors

Cathryn Lavery7b1d2fa6557a
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4780361..dd15ca1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -61,7 +61,7 @@ Every validation gate below must pass before a PR is ready. They also run automa
| README WebP previews match their PNGs, manifest, dimensions, and full-size links | `python3 scripts/test-build-readme-thumbs.py && python3 scripts/build-readme-thumbs.py --check` (requires `Pillow==12.1.1`) |
| Packaged output self-check behaves (pass + adversarial cases) | `python3 scripts/test-self-check.py` |
| Standalone SVG export carries CSS and namespaces defs IDs | `python3 scripts/test-export-svg-standalone.py` |
-| Label masks are never clipped by a node painted after them | `python3 scripts/verify-geometry.py --all` |
+| Label masks are never clipped by a node painted after them; connectors stay orthogonal, off node borders and corners, and on their own ports | `python3 scripts/verify-geometry.py --all` |
| Label geometry checker behaves (pass + adversarial cases) | `python3 scripts/test-verify-geometry.py` |
| Architecture delta snapshots preserve identity, ledger coverage, signatures, positions, and relationship endpoints | `python3 scripts/verify-architecture-delta.py --all` |
| Architecture delta checker behaves (pass + adversarial cases) | `python3 scripts/test-verify-architecture-delta.py` |
@@ -205,7 +205,7 @@ python3 scripts/test-plugin-package.py \
- **`verify-bump.py`:** a vertex sits off the rank grid the figure itself declares, a snapshot's ranks are not a permutation of 1..N, a segment curves or arrives by a relative command, or an endpoint label is missing a coordinate, drawn inboard of the end it names, or off the gutter its peers share. Fix the geometry or the declaration, never the label — and never nudge a vertex off its row to dodge a label collision, because a rank between two ranks is not a rank.
- **`verify-beeswarm.py`:** a dot is drawn off the shared value scale its peers describe, two dots declaring one value sit at two positions, a pair overprints instead of dodging, a second radius or a second non-focal fill appears, a second dot wears the accent, two dots share a `data-name` (or one is empty), anything positions a mark from CSS (`transform`, `translate`/`rotate`/`scale`, a geometry property, a motion path) by any carrier — attribute, inline `style`, or `<style>` rule, or a bound label/tick disagrees with the mark it names. Fix the geometry, never the binding — and never move a dot along the value axis to open up space, because crowding is data and the dodge is the only honest resolution.
- **`verify-skin-polarity.py`:** a legend key or caption names the ramp's direction by lightness (`darker is larger`) in a file whose ramp composites the other way. `ink` is a role, not a colour — it resolves near-black on light paper and near-white on dark — so one set of opacities runs darker as it strengthens in the light skin and lighter in the dark one. Name the direction by contrast against the paper (`stronger contrast is larger`), which survives the skin swap, and ship the same sentence in every variant; never invert the word for one file. The gate also fails closed on a claim it cannot substantiate — no resolvable paper colour, fewer than three rank-bearing ramp members, or a ramp that is not strictly ordered — and on wording it cannot parse: a tone word within six words of a magnitude word that no supported sentence form binds. Rephrase that as `<tone> <is|means|represents> <magnitude>` (`stronger contrast is larger`), because a claim the gate cannot read is a claim nothing checks.
-- **`verify-geometry.py`:** a label mask overlaps a node declared later in the document, so the node fill clips the label at render time. Move the label to a free segment of its connector — keep the 6–10px gap from the stroke required by SKILL.md §6, and do not shrink the mask to sneak under the check.
+- **`verify-geometry.py`:** a label mask overlaps a node declared later in the document, so the node fill clips the label at render time. Move the label to a free segment of its connector — keep the 6–10px gap from the stroke required by SKILL.md §6, and do not shrink the mask to sneak under the check. It also fails an arrowed connector with a diagonal straight segment, a segment lying on a node's border, an endpoint within 8px of a node corner, or two connectors leaving (or arriving at) one node through the same point. Reroute the connector so it leaves each box perpendicular to the edge it starts on, from its own port; do not drop the marker or the node stroke to get past the check.
- **`verify-architecture-delta.py`:** a stable ID, snapshot membership, status, signature, position, endpoint, or ledger target disagrees with the declared migration. Follow `type-architecture-delta.md`: record every changed object in the center ledger, retain unchanged positions on matching grids, and distinguish CHANGED, MOVED, and REWIRED by what actually differs. Fix the diagram and metadata together; never suppress the ledger entry to hide an unaccounted change.
- **`verify-exploded.py`:** a part's silhouette is off the projection of the box it declares, a level sits at two heights, the gaps differ or fall under max(0.5 x top-face height, 3 x part thickness), a leader bends, starts off its part, or crosses another part, labels crowd or leave the column, or an animated lift disagrees with the geometry. Change the model in `scripts/build-exploded-examples.py` and rebuild; never nudge a drawn coordinate, and never shrink a gap to fit the canvas.
- **`verify-axonometric-plan.py`:** a box's silhouette is off the projection of its declared footprint, a box stands outside the plate, floats above it, or shares floor with another, a box is painted after one in front of it, or a tag is off its plan point, stands on a room or roof it does not name, overlaps another tag, runs past two words, or is missing or doubled for a room or building. Change the plan in `scripts/build-axonometric-plan-examples.py` and rebuild; move a tag to open floor rather than shrinking it.
diff --git a/scripts/test-verify-geometry.py b/scripts/test-verify-geometry.py
index ac1b637..aead6d2 100644
--- a/scripts/test-verify-geometry.py
+++ b/scripts/test-verify-geometry.py
@@ -15,6 +15,8 @@ ARCHITECTURE = ASSET_DIR / "example-architecture.html"
SWIMLANE = ASSET_DIR / "example-swimlane.html"
ZONED = ASSET_DIR / "example-dp-integration.html"
SEQUENCE_OAUTH = ASSET_DIR / "example-sequence-oauth.html"
+HIGH_LEVEL = ASSET_DIR / "example-high-level.html"
+QUEUE_ANIMATED = ASSET_DIR / "example-queue-animated.html"
def load_verifier():
@@ -120,8 +122,87 @@ def main() -> int:
0,
)
+ # Connector routing. A stroked node; arrows carry a marker to count.
+ stroked = '<rect x="100" y="60" width="160" height="64" rx="6" fill="#fff" stroke="#2d3142"/>'
+ arrow = 'fill="none" stroke="#4f5d75" marker-end="url(#arrow)"'
+
+ # The reported defect: leave the top edge, then run flat along the border,
+ # so the arrow appears to grow out of the top-right corner.
+ check(
+ "connector riding a node's top border",
+ document(f'<path d="M 180,60 H 332 Q 340,60 340,52 V 20" {arrow}/>' + stroked),
+ 1,
+ )
+ check(
+ "connector leaving the side edge at its own port",
+ document(f'<path d="M 260,84 H 332 Q 340,84 340,76 V 20" {arrow}/>' + stroked),
+ 0,
+ )
+ check(
+ "diagonal connector",
+ document(f'<line x1="10" y1="10" x2="60" y2="40" {arrow}/>'),
+ 1,
+ )
+ check(
+ "diagonal line without a marker is not a connector",
+ document('<line x1="10" y1="10" x2="60" y2="40" stroke="#4f5d75"/>'),
+ 0,
+ )
+ # Loop write-back spokes are the documented radial exception.
+ check(
+ "loop spoke is exempt from the diagonal rule",
+ document(f'<path class="spoke" d="M 10 10 L 60 40" {arrow}/>'),
+ 0,
+ )
+ check(
+ "connector landing on a node corner",
+ document(f'<line x1="40" y1="60" x2="100" y2="60" {arrow}/>' + stroked),
+ 1,
+ )
+ check(
+ "two connectors forking from one port",
+ document(
+ f'<path d="M 260,84 H 300" {arrow}/>'
+ f'<path d="M 260,84 H 280 Q 288,84 288,92 V 120" {arrow}/>' + stroked
+ ),
+ 1,
+ )
+ # One arrow lands where the next leaves: a chain the reader follows in order.
+ check(
+ "head-to-tail chain joint is legal",
+ document(
+ f'<path d="M 60,60 C 60,0 180,0 180,60" {arrow}/>'
+ f'<path d="M 180,60 C 180,0 300,0 300,60" {arrow}/>' + stroked
+ ),
+ 0,
+ )
+ # Identical local geometry in two translated panels must not collide.
+ panel = f'<path d="M 260,84 H 300" {arrow}/>' + stroked
+ check(
+ "translated panels are compared in canvas space",
+ document(f'<g transform="translate(0 0)">{panel}</g><g transform="translate(400 0)">{panel}</g>'),
+ 0,
+ )
+ # An arrowed axis along an unstroked quadrant fill is not a border ride.
+ check(
+ "unstroked fill rect is not a node",
+ document(
+ '<rect x="100" y="60" width="160" height="64" fill="rgba(235,108,54,0.04)"/>'
+ f'<line x1="100" y1="40" x2="100" y2="200" {arrow}/>'
+ ),
+ 0,
+ )
+ # Coordinates under a rotate are not canvas space; skip rather than misjudge.
+ check(
+ "connector under a non-translate transform is skipped",
+ document(f'<g transform="rotate(45)"><line x1="10" y1="10" x2="60" y2="40" {arrow}/></g>'),
+ 0,
+ )
+
check_file("shipped architecture example", ARCHITECTURE, 0)
check_file("shipped swimlane example", SWIMLANE, 0)
+ check_file("shipped high-level example", HIGH_LEVEL, 0)
+ check_file("shipped queue animation", QUEUE_ANIMATED, 0)
check_file("shipped zoned example", ZONED, 0)
check_file("shipped sequence-oauth example", SEQUENCE_OAUTH, 0)
diff --git a/scripts/verify-geometry.py b/scripts/verify-geometry.py
index 129273a..e6adf76 100644
--- a/scripts/verify-geometry.py
+++ b/scripts/verify-geometry.py
@@ -25,6 +25,21 @@ Shape heuristics follow the shipped templates:
* A mask fully contained in a node is a badge chip (`EXT`, `EDGE`, `ORIG`) and
is legal.
+It also checks connector routing (references/primitives-core.md rule 1). A
+connector is a `<path>` or `<line>` that carries an arrow marker; a node, for
+this check, is a stroked `<rect>` at least 60x40, so unstroked quadrant fills
+and chart bars stay out of it. Four shapes are reported:
+
+* A straight segment that is neither horizontal nor vertical. Loop write-back
+ spokes (`class="spoke"`) are the documented radial exception and skipped.
+* A horizontal or vertical segment lying on a node's border. It hides behind
+ the node fill, so the arrow appears to start at the corner.
+* A connector endpoint within 8px of a node corner, where the rounded corner
+ makes the port ambiguous.
+* Two connectors leaving (or two arriving at) the same node less than 8px
+ apart, the hard minimum in primitives-core.md rule 4, so neither arrow can be
+ traced alone. A head-to-tail chain joint is allowed.
+
Usage:
python3 scripts/verify-geometry.py --all
python3 scripts/verify-geometry.py skills/diagram-design/assets/example-x.html
@@ -109,6 +124,287 @@ def contained(inner: Rect, outer: Rect) -> bool:
)
+TAG_RE = re.compile(
+ r"<(?P<close>/?)(?P<tag>g|svg|rect|path|line)\b(?P<attrs>[^>]*?)(?P<empty>/?)>",
+ re.IGNORECASE,
+)
+TRANSLATE_RE = re.compile(
+ r"^\s*translate\(\s*([-+]?[\d.]+)(?:[\s,]+([-+]?[\d.]+))?\s*\)\s*$"
+)
+PATH_TOKEN_RE = re.compile(
+ r"[MmLlHhVvQqCcSsTtAaZz]|[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?"
+)
+# Parameters each path command consumes per repetition.
+PATH_ARITY = {"M": 2, "L": 2, "H": 1, "V": 1, "Q": 4, "T": 2, "C": 6, "S": 4, "A": 7, "Z": 0}
+
+AXIS_TOLERANCE = 0.5 # a segment this close to axis-aligned is orthogonal
+BORDER_TOLERANCE = 1.0 # a segment this close to a node edge lies on it
+BORDER_MIN_RUN = 4.0 # shorter shared runs are a port touching the edge, not a ride
+PORT_TOLERANCE = 4.0 # an endpoint this close to a node outline attaches to it
+CORNER_CLEARANCE = 8.0 # ports keep this far from a corner (primitives-core rule 1)
+SHARED_PORT_MIN = 8.0 # two ports on one node keep at least this far apart (rule 4)
+
+
+def attribute(attrs: str, name: str) -> str | None:
+ match = re.search(rf'(?<![\w-]){re.escape(name)}\s*=\s*"([^"]*)"', attrs)
+ return match.group(1) if match else None
+
+
+def number(attrs: str, name: str) -> float | None:
+ value = attribute(attrs, name)
+ try:
+ return float(value) if value is not None else None
+ except ValueError:
+ return None
+
+
+Segment = tuple[str, float, float, float, float] # (kind, x1, y1, x2, y2)
+
+
+def path_segments(d: str) -> list[Segment] | None:
+ """Flatten a path into straight and curved segments, or None if unparseable."""
+
+ tokens = PATH_TOKEN_RE.findall(d)
+ segments: list[Segment] = []
+ x = y = start_x = start_y = 0.0
+ command = ""
+ index = 0
+ while index < len(tokens):
+ if tokens[index].isalpha():
+ command = tokens[index]
+ index += 1
+ if command in "Zz":
+ if (x, y) != (start_x, start_y):
+ segments.append(("line", x, y, start_x, start_y))
+ x, y = start_x, start_y
+ continue
+ if not command:
+ return None
+ upper = command.upper()
+ arity = PATH_ARITY.get(upper)
+ if not arity or index + arity > len(tokens):
+ return None # unknown command, numbers after Z, or truncated arguments
+ try:
+ args = [float(token) for token in tokens[index : index + arity]]
+ except ValueError:
+ return None
+ index += arity
+ relative = command.islower()
+ if upper == "H":
+ nx, ny = (x + args[0] if relative else args[0]), y
+ elif upper == "V":
+ nx, ny = x, (y + args[0] if relative else args[0])
+ else:
+ nx, ny = args[-2], args[-1]
+ if relative:
+ nx, ny = x + nx, y + ny
+ if upper == "M":
+ x, y = start_x, start_y = nx, ny
+ command = "l" if relative else "L" # implicit lineto after moveto
+ continue
+ kind = "line" if upper in "LHV" else "curve"
+ segments.append((kind, x, y, nx, ny))
+ x, y = nx, ny
+ return segments
+
+
+Offset = tuple[float, float]
+
+
+def translation(attrs: str) -> Offset | None:
+ """Offset a `transform` applies, (0, 0) when absent, None when not a translate."""
+
+ transform = attribute(attrs, "transform")
+ if transform is None:
+ return 0.0, 0.0
+ match = TRANSLATE_RE.match(transform)
+ if not match:
+ return None
+ return float(match.group(1)), float(match.group(2) or 0.0)
+
+
+def shapes(source: str):
+ """Yield (tag, attrs, match start, offset) for each rect, path, and line.
+
+ Offsets accumulate `translate()` on enclosing groups, so panels drawn with
+ the same local coordinates (architecture delta snapshots) are compared in
+ canvas space. Under any other transform, or inside a nested `<svg>` icon,
+ the offset is None and the element is left out of connector checks.
+ """
+
+ stack: list[Offset | None] = []
+ for match in TAG_RE.finditer(source):
+ tag, attrs = match.group("tag").lower(), match.group("attrs")
+ if tag in {"g", "svg"}:
+ if match.group("close"):
+ if stack:
+ stack.pop()
+ elif not match.group("empty"):
+ nested_svg = tag == "svg" and bool(stack)
+ stack.append(None if nested_svg else translation(attrs))
+ continue
+ frame: Offset | None = (0.0, 0.0)
+ for step in stack + [translation(attrs)]:
+ if step is None or frame is None:
+ frame = None
+ break
+ frame = (frame[0] + step[0], frame[1] + step[1])
+ yield tag, attrs, match.start(), frame
+
+
+def shifted(segments: list[Segment], frame: Offset) -> list[Segment]:
+ dx, dy = frame
+ return [(kind, x1 + dx, y1 + dy, x2 + dx, y2 + dy) for kind, x1, y1, x2, y2 in segments]
+
+
+def connectors(source: str) -> list[tuple[int, str, list[Segment]]]:
+ """Return (line number, short label, segments) for every arrowed connector."""
+
+ found: list[tuple[int, str, list[Segment]]] = []
+ for tag, attrs, start, frame in shapes(source):
+ if tag == "rect" or frame is None:
+ continue
+ if attribute(attrs, "marker-end") is None and attribute(attrs, "marker-start") is None:
+ continue
+ if "spoke" in (attribute(attrs, "class") or "").split():
+ continue
+ line = source.count("\n", 0, start) + 1
+ if tag == "line":
+ coords = [number(attrs, key) for key in ("x1", "y1", "x2", "y2")]
+ if None in coords:
+ continue
+ x1, y1, x2, y2 = coords # type: ignore[misc]
+ segments: list[Segment] | None = [("line", x1, y1, x2, y2)]
+ label = f"<line {x1:g},{y1:g} -> {x2:g},{y2:g}>"
+ else:
+ d = attribute(attrs, "d") or ""
+ segments = path_segments(d)
+ label = f'<path d="{d if len(d) <= 48 else d[:45] + "..."}">'
+ if segments:
+ found.append((line, label, shifted(segments, frame)))
+ return found
+
+
+def stroked_nodes(source: str) -> list[Rect]:
+ nodes: list[Rect] = []
+ for tag, attrs, start, frame in shapes(source):
+ if tag != "rect" or frame is None:
+ continue
+ x, y, w, h = (number(attrs, key) for key in ("x", "y", "width", "height"))
+ if None in (x, y, w, h) or w < NODE_MIN_W or h < NODE_MIN_H: # type: ignore[operator]
+ continue
+ stroke = (attribute(attrs, "stroke") or "none").strip().lower()
+ if stroke in {"none", "transparent"} or number(attrs, "stroke-width") == 0:
+ continue
+ line = source.count("\n", 0, start) + 1
+ nodes.append(Rect(x + frame[0], y + frame[1], w, h, line, start))
+ return nodes
+
+
+def rides_border(segment: Segment, node: Rect) -> str | None:
+ _, x1, y1, x2, y2 = segment
+ if abs(y1 - y2) <= AXIS_TOLERANCE:
+ low, high = sorted((x1, x2))
+ shared = min(high, node.right) - max(low, node.x)
+ for edge, name in ((node.y, "top"), (node.bottom, "bottom")):
+ if abs(y1 - edge) <= BORDER_TOLERANCE and shared > BORDER_MIN_RUN:
+ return name
+ if abs(x1 - x2) <= AXIS_TOLERANCE:
+ low, high = sorted((y1, y2))
+ shared = min(high, node.bottom) - max(low, node.y)
+ for edge, name in ((node.x, "left"), (node.right, "right")):
+ if abs(x1 - edge) <= BORDER_TOLERANCE and shared > BORDER_MIN_RUN:
+ return name
+ return None
+
+
+def attached(px: float, py: float, node: Rect) -> bool:
+ """True when an endpoint sits on (or just off) the node's outline."""
+
+ outside_x = max(node.x - px, 0.0, px - node.right)
+ outside_y = max(node.y - py, 0.0, py - node.bottom)
+ inside = min(px - node.x, node.right - px, py - node.y, node.bottom - py)
+ return max(outside_x, outside_y) <= PORT_TOLERANCE and inside <= PORT_TOLERANCE
+
+
+def near_corner(px: float, py: float, node: Rect) -> tuple[float, float] | None:
+ if not attached(px, py, node):
+ return None
+ for cx in (node.x, node.right):
+ for cy in (node.y, node.bottom):
+ if max(abs(px - cx), abs(py - cy)) < CORNER_CLEARANCE:
+ return cx, cy
+ return None
+
+
+def check_connectors(path: Path, source: str) -> list[str]:
+ nodes = stroked_nodes(source)
+ findings: list[str] = []
+ ports: list[tuple[int, float, float, int, str, str, int]] = []
+ for ident, (line, label, segments) in enumerate(connectors(source)):
+ where = f"{path.name}:{line}: connector {label}"
+ for kind, x1, y1, x2, y2 in segments:
+ if kind == "line" and abs(x1 - x2) > AXIS_TOLERANCE and abs(y1 - y2) > AXIS_TOLERANCE:
+ findings.append(
+ f"{where} has a diagonal segment {x1:g},{y1:g} -> {x2:g},{y2:g}"
+ f" - route it as a rounded right-angle elbow"
+ )
+ break
+ for segment in segments:
+ if segment[0] != "line":
+ continue
+ hit = next(((node, side) for node in nodes if (side := rides_border(segment, node))), None)
+ if hit:
+ node, side = hit
+ findings.append(
+ f"{where} runs along the {side} border of node {node} (line {node.line})"
+ f" - leave the node perpendicular to the edge the port sits on"
+ )
+ break
+ ends = ((segments[0][1], segments[0][2]), (segments[-1][3], segments[-1][4]))
+ for px, py in ends:
+ corner = next(((node, c) for node in nodes if (c := near_corner(px, py, node))), None)
+ if corner:
+ node, (cx, cy) = corner
+ findings.append(
+ f"{where} attaches at {px:g},{py:g}, within {CORNER_CLEARANCE:g}px of the"
+ f" {cx:g},{cy:g} corner of node {node} (line {node.line})"
+ f" - move the port onto the straight part of the edge"
+ )
+ break
+ for (px, py), role in zip(ends, ("start", "end")):
+ for index, node in enumerate(nodes):
+ if attached(px, py, node):
+ ports.append((index, px, py, line, label, role, ident))
+ findings.extend(shared_ports(path, nodes, ports))
+ return findings
+
+
+def shared_ports(
+ path: Path, nodes: list[Rect], ports: list[tuple[int, float, float, int, str, str, int]]
+) -> list[str]:
+ """Report two connectors leaving, or two arriving, at one point on a node.
+
+ A head-to-tail joint, where one arrow lands and the next leaves, is a chain
+ the reader traces in order (Medallion's documented promotion joints), so it
+ is not reported. Two starts are a fork and two ends are a merge.
+ """
+
+ findings: list[str] = []
+ for i, (node_a, ax, ay, line_a, label_a, role_a, id_a) in enumerate(ports):
+ for node_b, bx, by, line_b, label_b, role_b, id_b in ports[i + 1 :]:
+ if node_a != node_b or id_a == id_b or role_a != role_b:
+ continue
+ if max(abs(ax - bx), abs(ay - by)) < SHARED_PORT_MIN:
+ node = nodes[node_a]
+ findings.append(
+ f"{path.name}:{line_b}: connector {label_b} shares the {bx:g},{by:g} port on"
+ f" node {node} (line {node.line}) with {label_a} at line {line_a}"
+ f" - give each connector its own attach point, >={SHARED_PORT_MIN:g}px apart"
+ )
+ return findings
+
+
def check(path: Path) -> list[str]:
source = path.read_text(encoding="utf-8")
rects = parse_rects(source)
@@ -133,6 +429,7 @@ def check(path: Path) -> list[str]:
f" - move the label onto a free segment of its connector"
)
break
+ findings.extend(check_connectors(path, source))
return findings