/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import { type CanvasEnd, type CanvasHead } from "../../shared/links/canvas.js"; import { type Bbox, type ScreenCamera } from "./camera"; import type { DrawnItem, DrawnLink, DrawnNet } from "./drawn"; import { type LodTier } from "./model"; type Pt = { x: number; y: number; }; /** Expand anchors into an axis-aligned point list (one elbow per diagonal). * Exported so link hit-testing routes exactly like the painter (P11 spirit). */ export declare function orthogonalize(points: Pt[]): Pt[]; /** * Segment-wise distance from a screen point to a polyline — the link * hit-test's core (routed points, so the clickable path equals the drawn * path, including fan lanes). Exported for unit testing. * * @param pts - the routed points, in order * @param sx - screen x * @param sy - screen y * @returns the minimum distance (Infinity for fewer than 2 points) */ export declare function distanceToPolyline(pts: readonly Pt[], sx: number, sy: number): number; /** Screen-px gap between parallel link lanes (#180 fan-out). */ export declare const LINK_LANE_GAP = 7; /** * The arc-length midpoint of a polyline (screen space) — where a link's label * pill anchors, so it sits centred along the routed path (not the chord). * Exported for unit testing. * * @param pts - the routed points, in order * @returns the midpoint (the sole point / origin for degenerate inputs) */ export declare function polylineMidpoint(pts: readonly Pt[]): Pt; /** * Per-link parallel-fan lanes (#180): links sharing an endpoint pair (either * direction, no explicit waypoints, both endpoints resolved) would overdraw * into one edge — assign each a lane index so the painter can translate the * whole routed polyline rigidly along the pair's perpendicular. Deterministic * (lanes ordered by link key). Exported for unit testing. * * @param links - the links about to paint (pre-filtered upstream is fine) * @param eligible - whether a link participates (endpoints resolved, no `via`, not hidden) * @returns link key → `{ i, n }` lane position, only for groups of 2+ */ export declare function parallelLanes(links: readonly L[], eligible: (link: L) => boolean): Map; /** Net (bus / trunk) geometry, world space — shared verbatim by the * painter and the hit-test so the clickable shape equals the drawn one. */ /** The leg a net's stub draws: the side it is on, and its member's place in that side. */ export interface NetStubLeg { end: "source" | "destination"; index: number; } export interface NetGeometry { /** Trunk polyline: source anchor → via… → destination anchor. */ trunk: Pt[]; bars: Array<[Pt, Pt]>; stubs: Pt[][]; /** * Each stub's leg, in the stubs' order (#1388): a side with one member — * or its members at one point — draws no stub, so a stub's place among the * stubs alone doesn't name its leg. */ legs: NetStubLeg[]; taps: Pt[]; } /** Bus-bar geometry for a whole net: each side becomes a header bar (or a * bare anchor), the trunk runs bar-tap → `via`… → bar-tap. With one * endpoint per side and no waypoints this degrades to a plain link. */ export declare function netGeometry(sources: readonly Pt[], destinations: readonly Pt[], via: readonly Pt[]): NetGeometry; /** * The world box a net draws in (invariant 9): its members drawn, its bends, and its bus as {@link netGeometry} lays it * out — its trunk, its bars and its legs. A side's bar stands off toward the trunk, and where the other side stands * level with it — a rack's trunk into frames in its row — past every member: the members' box alone leaves it out. * What the painter culls a net by and the links' R-tree files it under, so a net draws, and takes a tap, wherever its bus * is. * * @param net - The net * @param centers - Each item drawn's centre, in world units, by its id * @returns Its box; `null` while a side has no member drawn, when it draws nothing */ export declare function netBox(net: DrawnNet, centers: ReadonlyMap): Bbox | null; /** Where an item draws at the zoom, in the canvas's px — a card's box, a labelled pin's, a dot's circle: what a link's end meets. */ export type EndShape = CanvasEnd; /** * Where an item draws at the zoom, in the canvas's px (#1403): its card's box, * its labelled pin's — the box a tap meets it in ({@link markerHitbox}) — or * its dot's circle. A card's box is its card's size as the page lays it out, * or, unmeasured, the size the declutter reckons it at (`tierSize`). * * @param item - The item, where it draws * @param tier - What it draws as at the zoom * @param cam - The screen camera * @param measure - A label's width in px, in the pins' font * @param card - Its card's size as the page lays it out; `undefined`, unmeasured * @returns Its shape */ export declare function endShape(item: DrawnItem, tier: LodTier, cam: ScreenCamera, measure: (text: string) => number, card: { readonly w: number; readonly h: number; } | undefined): EndShape; /** * A route leaving its source where the source draws (#1403): from the point * its line first leaves the source's shape, every point before it dropped. A * route that starts outside the shape stands as it is; one the shape holds * whole is no route. * * @param points - The route, from inside the source * @param shape - The source's shape * @returns The route from the shape's edge */ export declare function leaveShape(points: readonly Pt[], shape: EndShape): Pt[]; /** * A route meeting its destination where the destination draws (#1403): to the * point its line first meets the destination's shape, every point after it * dropped — {@link leaveShape} walked from the far end. * * @param points - The route, into the destination * @param shape - The destination's shape * @returns The route to the shape's edge */ export declare function meetShape(points: readonly Pt[], shape: EndShape): Pt[]; /** A link's or a net's weight: its style's, else a solid run's 2.5 and a dashed one's 1.5. */ export declare function edgeWeight(style: DrawnLink["style"]): number; /** One run of a link's or a net's drawing, in the canvas's px. */ export interface EdgeRun { /** Its route, from where it leaves to where it arrives — its head's tip, where it has one: what the pointer meets. */ readonly route: readonly Pt[]; /** What its line draws: its route, to its head's base where it has one. */ readonly line: readonly Pt[]; /** Its head, where it arrives at an item. */ readonly head: CanvasHead | undefined; /** Its weight (px). */ readonly width: number; /** The radius its corners turn at, before their clamp. */ readonly corner: number; /** The net's leg it is — its side and its member — or `undefined`: a link's line, a trunk, a bar. */ readonly leg: { readonly end: "source" | "destination"; readonly item: string; } | undefined; } /** What a link or a net draws, in the canvas's px, before its look (#1403). */ export interface EdgeGeometry { /** Its runs: a link's line; a net's trunk, its bars and its legs. */ readonly runs: readonly EdgeRun[]; /** Where a net's legs join its bars: its junction dots. */ readonly dots: readonly { readonly x: number; readonly y: number; readonly r: number; }[]; /** The shapes of the items it joins: what its rings go round while it is lit or selected. */ readonly ends: readonly EndShape[]; /** A link's ends where its line leaves its source and meets its destination — where its handles stand; none for a net. */ readonly handles: { readonly from: Pt; readonly to: Pt; } | undefined; /** Its route's middle — a net's trunk's — where its caption centres; `undefined` with no route to draw. */ readonly middle: Pt | undefined; } /** What a link's or a net's routes are worked out over: the camera, the items' centres and shapes, and the links' lanes. */ export interface RouteEnv { /** The screen camera. */ readonly cam: ScreenCamera; /** Each item's centre drawn, in world units, by its id. */ readonly centers: ReadonlyMap; /** Each item's shape on the screen, by its id; `undefined` for one not drawn. */ readonly shapeOf: (id: string) => EndShape | undefined; /** The links' lanes, by their ids (`parallelLanes`). */ readonly lanes: ReadonlyMap; } /** * What a link's or a net's routes are worked out over, each item's shape * worked out once, as it is asked. * * @param input - The camera, each item drawn and its centre, what each draws as, its card's size, the lanes and a label's width * @returns The routes' environment */ export declare function routeEnv(input: { readonly cam: ScreenCamera; readonly centers: ReadonlyMap; readonly items: ReadonlyMap; readonly tiers: ReadonlyMap; readonly cardSizes: ReadonlyMap | undefined; readonly lanes: ReadonlyMap; readonly measure: (text: string) => number; }): RouteEnv; /** * A link's drawing on the screen (#1403): routed from its source's centre to * its destination's — orthogonal or direct, through its bends, translated * rigidly onto its lane — then from where its line leaves its source's shape to * where it meets its destination's, its head there. * * @param link - The link * @param env - What its routes are worked out over * @returns Its drawing; `undefined` while an item it joins is drawn nowhere */ export declare function linkRoutes(link: DrawnLink, env: RouteEnv): EdgeGeometry | undefined; /** * A net's drawing on the screen (#1403): its bus (`netGeometry`) — its trunk, * a bar across each side of several members, a leg from each of them — its * trunk leaving a lone source where it draws and meeting a lone destination so, * its head there; each source's leg leaving its member's shape, and each * destination's meeting it, its head there. Its trunk and its bars carry no * head; its junctions are dots. * * @param net - The net * @param env - What its routes are worked out over * @returns Its drawing; `undefined` while a side has no member drawn */ export declare function netRoutes(net: DrawnNet, env: RouteEnv): EdgeGeometry | undefined; export {}; //# sourceMappingURL=routes.d.ts.map