Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
perf(workflow): assemble the enumerated routes in one pass
goatliamia088fbcac3218
diff --git a/archify/renderers/shared/geometry.mjs b/archify/renderers/shared/geometry.mjsindex 0d0198cf..c1b4a006 100644--- a/archify/renderers/shared/geometry.mjs+++ b/archify/renderers/shared/geometry.mjs@@ -352,7 +352,6 @@ export function routeHonorsEndpointSides(points, fromSide, toSide) {return !endpointSideIssue(points, 'source', fromSide)&& !endpointSideIssue(points, 'target', toSide);}-// Explicit fromSide/toSide are authored geometry, so a tangent or backwards// endpoint segment changes their meaning. Fail this universally instead of// leaving a malformed arrow for visual review to discover. Named routes and@@ -1257,6 +1256,27 @@ function segmentPosition(index, segmentCount) {// route simply gets a new entry.const NORMALIZED_ROUTE_POINTS = new WeakMap();+// Assembling a route from an anchor, corridor points and an anchor is the same+// normalization without the intermediate array, and the result is seeded in the+// cache so later predicates do not normalize it again.+export function joinRoutePoints(start, via, end) {+ const normalized = [];+ const accept = (point) => {+ if (!Array.isArray(point) || point.length !== 2 || !isFinitePoint(point[0], point[1])) return;+ const previous = normalized.at(-1);+ if (previous+ && Math.abs(point[0] - previous[0]) <= 0.0001+ && Math.abs(point[1] - previous[1]) <= 0.0001) return;+ while (normalized.length >= 2 && collinearForward(normalized.at(-2), normalized.at(-1), point)) normalized.pop();+ normalized.push(point);+ };+ accept(start);+ for (const point of Array.isArray(via) ? via : []) accept(point);+ accept(end);+ NORMALIZED_ROUTE_POINTS.set(normalized, normalized);+ return normalized;+}+export function normalizeRoutePoints(points) {if (Array.isArray(points)) {const cached = NORMALIZED_ROUTE_POINTS.get(points);diff --git a/archify/renderers/workflow/workflow-compiler.mjs b/archify/renderers/workflow/workflow-compiler.mjsindex 0c5066ca..67e75eeb 100644--- a/archify/renderers/workflow/workflow-compiler.mjs+++ b/archify/renderers/workflow/workflow-compiler.mjs@@ -30,6 +30,7 @@ import {planningWorkflow,} from './workflow-migration-geometry.mjs';import {+ joinRoutePoints,asArray,isFinitePoint,rectsOverlap,@@ -2175,7 +2176,7 @@ function corridorTopologyMatches(points, axis, coordinate) {const via = axis === 'x'? [[coordinate, start[1]], [coordinate, end[1]]]: [[start[0], coordinate], [end[0], coordinate]];- const expected = normalizeRoutePoints([start, ...via, end]);+ const expected = joinRoutePoints(start, via, end);const actualPattern = routeSegments(collapsed).map(({ orientation }) => orientation);const expectedPattern = routeSegments(expected).map(({ orientation }) => orientation);return actualPattern.length === expectedPattern.length@@ -3659,7 +3660,7 @@ function readableAutomaticCandidateSet(const candidates = rawCandidates.map((candidate, ordinal) => ({...candidate,ordinal: ordinalOffset + ordinal,- points: normalizeRoutePoints([start, ...candidate.via, end]),+ points: joinRoutePoints(start, candidate.via, end),})).filter(({ points }) => (readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide))).map((candidate) => ({@@ -3873,7 +3874,7 @@ function readablePresetVia(edge, from, to, start, end, fromSide, toSide) {default:return readableAutomaticVia(edge, from, to, start, end, fromSide, toSide);}- const points = normalizeRoutePoints([start, ...via, end]);+ const points = joinRoutePoints(start, via, end);if (readableCandidateIsFeasible(edge, points, from, to, fromSide, toSide)&& routeMatchesPresetFamily(preset, points, from, to)) {return points.slice(1, -1);@@ -4164,7 +4165,7 @@ function readableAutomaticRoute(edge, from, to, primarySides, primaryPorts) {const via = withDiagnosticRecordingSuppressed(() => readableAutomaticVia(edge, from, to, alternativeStart, alternativeEnd, candidateSides.fromSide, candidateSides.toSide,));- const points = normalizeRoutePoints([alternativeStart, ...via, alternativeEnd]);+ const points = joinRoutePoints(alternativeStart, via, alternativeEnd);plans.push({points, ...candidateSides,cost: readableCandidateCost(edge, points, pairOrdinal * 9 + portOrdinal * 144 + 6, naturalFromSide, naturalToSide),@@ -4187,7 +4188,7 @@ function readableAutomaticRoute(edge, from, to, primarySides, primaryPorts) {candidateSides.fromSide,candidateSides.toSide,));- const expandedPoints = normalizeRoutePoints([start, ...expandedVia, end]);+ const expandedPoints = joinRoutePoints(start, expandedVia, end);const outsideRightOrdinal = planned.rawCandidates.findIndex(({ family }) => (family === 'outside-right'));