Where to Find Archify's Shared Geometry Utilities for Layout Computation
Archify's shared geometry utilities for layout computation are centralized in archify/renderers/shared/geometry.mjs, a pure-function module that exports helpers for rectangle overlap detection, segment clearance calculations, and route validation.
Archify diagram renderers rely on centralized geometry helpers to compute layouts without state mutation. The shared geometry utilities for layout computation live in the archify/renderers/shared/ directory, providing mathematical foundations for collision detection, clearance measurement, and endpoint validation across workflow, sequence, and UI renderers. According to the tt-a1i/archify source code, these stateless functions enable consistent positioning while keeping layout tables encapsulated within individual renderers.
Core Location of Geometry Utilities
All shared geometry utilities for layout computation reside in a single ES module designed for cross-renderer compatibility. The primary file exports pure functions that operate on measured rectangle objects containing {x, y, width, height, cx, cy} coordinates.
archify/renderers/shared/geometry.mjs serves as the central library. This module contains implementations for rectangle overlap detection, segment-to-rectangle clearance calculations, route validation against endpoint-side contracts, and layout problem collection for diagnostic reporting.
Renderers import these helpers to perform spatial calculations without mutating their internal layout state. The module remains deliberately pure—layout tables remain owned by individual renderers, which pass coordinate data to the utility functions for evaluation.
Key Geometry Functions and Usage
The geometry module exports specialized functions that handle common layout computation scenarios. Each utility validates inputs, performs mathematical comparisons, and returns deterministic results.
Rectangle Overlap Detection
The rectsOverlap function determines whether two axis-aligned rectangles intersect. It validates that all coordinates are finite before performing bounding-box comparisons.
import { rectsOverlap } from './geometry.mjs';
const a = { x: 10, y: 20, width: 100, height: 50 };
const b = { x: 80, y: 40, width: 120, height: 60 };
if (rectsOverlap(a, b)) {
console.log('The two rectangles intersect.');
}
Implementation details: The helper checks coordinate finiteness and performs axis-aligned bounding-box comparison. Source: lines 20-34 of archify/renderers/shared/geometry.mjs.
Segment-Rectangle Clearance
Calculate the minimum distance between a line segment and a label's bounding box using segmentRectClearance. This utility returns the clearance distance or null for invalid inputs.
import { segmentRectClearance } from './geometry.mjs';
const segment = { start: [30, 30], end: [200, 30] };
const labelRect = { x: 120, y: 10, width: 40, height: 20 };
const clearance = segmentRectClearance(segment, labelRect);
console.log(`Clearance: ${clearance}px`);
Implementation details: The function validates inputs, computes the nearest distance between the segment and rectangle, and returns null for invalid data. Source: lines 54-72 of archify/renderers/shared/geometry.mjs.
Endpoint-Side Contract Validation
Verify that routed relationships respect declared endpoint sides using routeHonorsEndpointSides. This ensures orthogonal routes leave and enter specified sides perpendicularly.
import { routeHonorsEndpointSides } from './geometry.mjs';
const points = [
[10, 10], // source anchor
[10, 50],
[80, 50],
[80, 90] // target anchor
];
const fromSide = 'left';
const toSide = 'right';
if (routeHonorsEndpointSides(points, fromSide, toSide)) {
console.log('Route respects endpoint-side contracts.');
}
Implementation details: The helper inspects the first and last segments of the polyline to verify perpendicular departure and arrival relative to the specified sides. Source: lines 50-56 of archify/renderers/shared/geometry.mjs.
Layout Problem Collection
Diagnose label-route clearance issues using collectLabelRouteClearance. This function aggregates all instances where labels violate proximity thresholds relative to relationship routes.
import { collectLabelRouteClearance } from './geometry.mjs';
const hits = collectLabelRouteClearance({
labels: [/* label objects with rects */],
routedRelations: [/* rendered relationships with points */],
threshold: 4
});
hits.forEach(hit => {
console.log(`Label ${hit.label?.label} is only ${hit.clearance}px from route`);
});
Implementation details: The utility leverages segmentRectClearance and segmentRectIntersectionLength to evaluate label proximity against routed relationships. Source: lines 107-165 of archify/renderers/shared/geometry.mjs.
Testing and Migration Wrappers
Beyond the core implementation, Archify provides testing infrastructure and renderer-specific wrappers that expose the geometry utilities.
Unit Test Coverage
archify/test/geometry.test.mjs contains the comprehensive test suite verifying correctness of all geometry helpers. These tests validate rectangle comparisons, distance calculations, and route validations against known values.
Workflow Renderer Integration
archify/renderers/workflow/workflow-migration-geometry.mjs acts as a migration-oriented wrapper that re-exports selected shared helpers specifically for the workflow renderer. This file demonstrates how typed renderers consume the shared utilities while maintaining their own layout table ownership.
Summary
- Primary location: All shared geometry utilities reside in
archify/renderers/shared/geometry.mjswithin the tt-a1i/archify repository. - Pure functions: The module exports stateless helpers that accept rectangle coordinates and return calculated values without side effects.
- Key capabilities: Utilities include
rectsOverlap,segmentRectClearance,routeHonorsEndpointSides, andcollectLabelRouteClearancefor layout validation. - Testing: Unit tests in
archify/test/geometry.test.mjsverify mathematical correctness. - Integration: Renderers import these utilities to compute positions, detect collisions, and enforce layout contracts while retaining ownership of their layout tables.
Frequently Asked Questions
Where are Archify's shared geometry utilities located?
Archify's shared geometry utilities reside in archify/renderers/shared/geometry.mjs. This central module exports pure functions for layout computation including rectangle overlap detection, clearance calculations, and route validation used by all diagram renderers.
How do I detect rectangle collisions in Archify?
Import the rectsOverlap function from archify/renderers/shared/geometry.mjs. Pass two rectangle objects containing x, y, width, and height properties; the function returns a boolean indicating whether the rectangles intersect. Source: lines 20-34.
Are Archify's geometry utilities pure functions?
Yes. According to the tt-a1i/archify source code, the geometry utilities are deliberately pure—they accept measured rectangle data and return computed results without mutating any state. Renderers maintain their own layout tables and pass coordinate objects to these helpers for calculations.
How are the geometry utilities tested?
The archify/test/geometry.test.mjs file contains unit tests verifying the correctness of each geometry helper. Additionally, the workflow renderer uses archify/renderers/workflow/workflow-migration-geometry.mjs as a migration wrapper that re-exports and utilizes these tested utilities in production scenarios.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →