@metronforge/concept-map 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/layout/hints.d.ts +2 -2
- package/dist/layout/hints.d.ts.map +1 -1
- package/dist/layout/hints.js.map +1 -1
- package/dist/layout/index.d.ts +1 -6
- package/dist/layout/index.d.ts.map +1 -1
- package/dist/layout/index.js +1 -82
- package/dist/layout/index.js.map +1 -1
- package/dist/layout/layout.d.ts +7 -0
- package/dist/layout/layout.d.ts.map +1 -0
- package/dist/layout/layout.js +83 -0
- package/dist/layout/layout.js.map +1 -0
- package/dist/layout/place-sketch.d.ts +1 -1
- package/dist/layout/place-sketch.d.ts.map +1 -1
- package/dist/layout/place-sketch.js +5 -1
- package/dist/layout/place-sketch.js.map +1 -1
- package/dist/layout/relations/sketch-order.d.ts +3 -2
- package/dist/layout/relations/sketch-order.d.ts.map +1 -1
- package/dist/layout/relations/sketch-order.js +4 -3
- package/dist/layout/relations/sketch-order.js.map +1 -1
- package/dist/layout/relations/sketch-placement.d.ts +4 -3
- package/dist/layout/relations/sketch-placement.d.ts.map +1 -1
- package/dist/layout/relations/sketch-placement.js +8 -8
- package/dist/layout/relations/sketch-placement.js.map +1 -1
- package/dist/layout/sketch-conflicts.d.ts +8 -0
- package/dist/layout/sketch-conflicts.d.ts.map +1 -0
- package/dist/layout/sketch-conflicts.js +56 -0
- package/dist/layout/sketch-conflicts.js.map +1 -0
- package/dist/layout/sketch-route.d.ts +2 -1
- package/dist/layout/sketch-route.d.ts.map +1 -1
- package/dist/layout/sketch-route.js +6 -6
- package/dist/layout/sketch-route.js.map +1 -1
- package/dist/layout/stages/hints.d.ts.map +1 -1
- package/dist/layout/stages/hints.js +33 -15
- package/dist/layout/stages/hints.js.map +1 -1
- package/package.json +1 -1
- package/src/layout/hints.ts +2 -2
- package/src/layout/index.ts +1 -148
- package/src/layout/layout.ts +147 -0
- package/src/layout/place-sketch.ts +14 -9
- package/src/layout/relations/sketch-order.ts +12 -1
- package/src/layout/relations/sketch-placement.ts +11 -5
- package/src/layout/sketch-conflicts.ts +69 -0
- package/src/layout/sketch-route.ts +8 -5
- package/src/layout/stages/hints.ts +47 -19
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RecordSketchConflict } from "./relations/sketch-order.js";
|
|
1
2
|
import type { SourceMap } from "../schema.js";
|
|
2
3
|
import type { LayoutProblem } from "./problem.js";
|
|
3
4
|
import type { LayoutGraph, LayoutResult } from "./types.js";
|
|
@@ -6,6 +7,6 @@ import type { RouteRefinement } from "./inspect-routes.js";
|
|
|
6
7
|
export { safeSketch } from "./sketch-safety.js";
|
|
7
8
|
/** Keep sketch order gains with at most four extra bends and no new hard
|
|
8
9
|
* contacts or crossings, before and after width refinement. */
|
|
9
|
-
export declare function routeSketch(source: SourceMap, problem: LayoutProblem, graph: LayoutGraph, original: LayoutResult, measurer: Measurer, refinement?: RouteRefinement, sizingWidthEm?: number): LayoutResult;
|
|
10
|
+
export declare function routeSketch(source: SourceMap, problem: LayoutProblem, graph: LayoutGraph, original: LayoutResult, measurer: Measurer, refinement?: RouteRefinement, sizingWidthEm?: number, record?: RecordSketchConflict): LayoutResult;
|
|
10
11
|
export declare function sketchRoutes(problem: LayoutProblem, graph: LayoutGraph, original: LayoutResult, nodes: LayoutResult["nodes"] | null): (LayoutResult | null)[];
|
|
11
12
|
//# sourceMappingURL=sketch-route.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sketch-route.d.ts","sourceRoot":"","sources":["../../src/layout/sketch-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sketch-route.d.ts","sourceRoot":"","sources":["../../src/layout/sketch-route.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGxE,OAAO,KAAK,EAAe,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAU3D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD;+DAC+D;AAC/D,wBAAgB,WAAW,CACzB,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,QAAQ,EAClB,UAAU,CAAC,EAAE,eAAe,EAC5B,aAAa,CAAC,EAAE,MAAM,EACtB,MAAM,CAAC,EAAE,oBAAoB,GAC5B,YAAY,CAgBd;AAyHD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI,GAClC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CA2BzB"}
|
|
@@ -12,12 +12,12 @@ import { safeSketch } from "./sketch-safety.js";
|
|
|
12
12
|
export { safeSketch } from "./sketch-safety.js";
|
|
13
13
|
/** Keep sketch order gains with at most four extra bends and no new hard
|
|
14
14
|
* contacts or crossings, before and after width refinement. */
|
|
15
|
-
export function routeSketch(source, problem, graph, original, measurer, refinement, sizingWidthEm) {
|
|
15
|
+
export function routeSketch(source, problem, graph, original, measurer, refinement, sizingWidthEm, record) {
|
|
16
16
|
const checks = {
|
|
17
17
|
draw: (result) => resolveMeasured(source, graph, result, measurer),
|
|
18
18
|
safe: (base, route) => safeSketch(source, graph, base, route, measurer, refinement),
|
|
19
19
|
};
|
|
20
|
-
const placed = choosePlacement(problem, graph, original, checks, sizingWidthEm);
|
|
20
|
+
const placed = choosePlacement(problem, graph, original, checks, sizingWidthEm, record);
|
|
21
21
|
return chooseDetour(source, problem, graph, placed, measurer, checks);
|
|
22
22
|
}
|
|
23
23
|
function chooseDetour(source, problem, graph, placed, measurer, checks) {
|
|
@@ -43,8 +43,8 @@ function chooseDetour(source, problem, graph, placed, measurer, checks) {
|
|
|
43
43
|
}
|
|
44
44
|
return best;
|
|
45
45
|
}
|
|
46
|
-
function choosePlacement(problem, graph, original, { draw, safe }, sizingWidthEm) {
|
|
47
|
-
const candidates = placementRoutes(problem, graph, original);
|
|
46
|
+
function choosePlacement(problem, graph, original, { draw, safe }, sizingWidthEm, record) {
|
|
47
|
+
const candidates = placementRoutes(problem, graph, original, record);
|
|
48
48
|
const bends = (result) => resolvedBends(draw(result));
|
|
49
49
|
const originalBends = bends(original);
|
|
50
50
|
let best = original;
|
|
@@ -63,9 +63,9 @@ function choosePlacement(problem, graph, original, { draw, safe }, sizingWidthEm
|
|
|
63
63
|
return best;
|
|
64
64
|
return shortenSketchRoutes(problem, graph, original, best, candidates, bends, safe);
|
|
65
65
|
}
|
|
66
|
-
function placementRoutes(problem, graph, original) {
|
|
66
|
+
function placementRoutes(problem, graph, original, record) {
|
|
67
67
|
const rerouted = routeLayout(graph, original, original.nodes, routeBounds(original.nodes));
|
|
68
|
-
const candidates = sketchPlacements(problem, original).flatMap((nodes) => sketchRoutes(problem, graph, original, nodes));
|
|
68
|
+
const candidates = sketchPlacements(problem, original, record).flatMap((nodes) => sketchRoutes(problem, graph, original, nodes));
|
|
69
69
|
return [rerouted, ...candidates];
|
|
70
70
|
}
|
|
71
71
|
/** A side shared by both ends can take an arrow around an intervening box. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sketch-route.js","sourceRoot":"","sources":["../../src/layout/sketch-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sketch-route.js","sourceRoot":"","sources":["../../src/layout/sketch-route.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAA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,IACE,MAAM;gBACN,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC;gBACvC,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC;gBAElE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"hints.d.ts","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAmEvD,4EAA4E;AAC5E,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,GAAG,WAAW,EAC/B,QAAQ,EAAE,WAAW,GACpB,iBAAiB,EAAE,CA8BrB"}
|
|
@@ -22,32 +22,50 @@ function sideHolds(hint, source, resolved) {
|
|
|
22
22
|
point[other] >= box[other] - epsilon(other) &&
|
|
23
23
|
point[other] <= box[other] + box[other + 2] + epsilon(other));
|
|
24
24
|
}
|
|
25
|
+
function pinVerdict(hint, pins, resolved, axis) {
|
|
26
|
+
const box = resolved.nodes[hint.node]?.box;
|
|
27
|
+
const distance = box
|
|
28
|
+
? Math.hypot(...hint.at.map((at, i) => box[i] + box[i + 2] / 2 - at))
|
|
29
|
+
: Infinity;
|
|
30
|
+
const holds = hint.strength === "required"
|
|
31
|
+
? distance <= 1e-6
|
|
32
|
+
: !box ||
|
|
33
|
+
pins.some((other) => {
|
|
34
|
+
const target = resolved.nodes[other.node]?.box;
|
|
35
|
+
const order = Math.sign(hint.at[1 - axis] - other.at[1 - axis]);
|
|
36
|
+
return (Math.round(other.at[axis] * 64) ===
|
|
37
|
+
Math.round(hint.at[axis] * 64) &&
|
|
38
|
+
(box[axis] !== target?.[axis] ||
|
|
39
|
+
(order &&
|
|
40
|
+
Math.sign(box[1 - axis] - target[1 - axis]) !== order)));
|
|
41
|
+
})
|
|
42
|
+
? false
|
|
43
|
+
: null;
|
|
44
|
+
return {
|
|
45
|
+
...hint,
|
|
46
|
+
holds,
|
|
47
|
+
message: `${constraintName(hint)}: distance: ${distance}`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
25
50
|
/** Geometry is authoritative; rank exclusion cannot be inferred from it. */
|
|
26
51
|
export function checkHints(source, resolved) {
|
|
27
52
|
const axis = source.direction === "right" ? 0 : 1;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: Infinity;
|
|
34
|
-
const message = `${hint.path}: pin (${hint.node}): ${distance} units from box centre`;
|
|
35
|
-
return hint.strength === "required"
|
|
36
|
-
? { ...hint, holds: distance <= 1e-6, message }
|
|
37
|
-
: { ...hint, holds: null, message };
|
|
38
|
-
}
|
|
53
|
+
const hints = statedHints(source);
|
|
54
|
+
const pins = hints.filter((h) => h.kind === "pin" && h.strength !== "required");
|
|
55
|
+
return hints.map((hint) => {
|
|
56
|
+
if (hint.kind === "pin")
|
|
57
|
+
return pinVerdict(hint, pins, resolved, axis);
|
|
39
58
|
if (hint.kind === "free")
|
|
40
59
|
return {
|
|
41
60
|
...hint,
|
|
42
61
|
holds: null,
|
|
43
62
|
message: `${constraintName(hint)}: not verifiable from the drawing`,
|
|
44
63
|
};
|
|
45
|
-
const positions = hint.kind === "sameRank"
|
|
46
|
-
? hint.nodes.map((id) => resolved.nodes[id]?.box[axis])
|
|
47
|
-
: [];
|
|
48
64
|
const holds = hint.kind === "side"
|
|
49
65
|
? sideHolds(hint, source, resolved)
|
|
50
|
-
:
|
|
66
|
+
: hint.nodes
|
|
67
|
+
.map((id) => resolved.nodes[id]?.box[axis])
|
|
68
|
+
.every((position, _index, positions) => position !== undefined && position === positions[0]);
|
|
51
69
|
return {
|
|
52
70
|
...hint,
|
|
53
71
|
holds,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hints.js","sourceRoot":"","sources":["../../../src/layout/stages/hints.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,SAAS,SAAS,CAChB,IAA2C,EAC3C,MAA+B,EAC/B,QAAqB;IAErB,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;IACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;IAC7C,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAChC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,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M,CACvB,CAAC,CAAC,EAA6C,EAAE,CAC/C,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,QAAQ,KAAK,UAAU,CAChD,CAAC;IACF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAqB,EAAE;QAC3C,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK;YAAE,OAAO,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QACvE,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;YACtB,OAAO;gBACL,GAAG,IAAI;gBACP,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,mCAAmC;aACpE,CAAC;QACJ,MAAM,KAAK,GACT,IAAI,CAAC,IAAI,KAAK,MAAM;YAClB,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC;YACnC,CAAC,CAAC,IAAI,CAAC,KAAK;iBACP,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;iBAC1C,KAAK,CACJ,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,CAC9B,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CACtD,CAAC;QACV,OAAO;YACL,GAAG,IAAI;YACP,KAAK;YACL,OAAO,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,EAAE;SAC3E,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
package/src/layout/hints.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SourceMap, ResolvedMap } from "../schema.js";
|
|
2
2
|
import type { Constraint } from "./problem.js";
|
|
3
|
-
import type { LayoutOptions, UnsupportedHint } from "./types.js";
|
|
3
|
+
import type { LayoutOptions, StatedHint, UnsupportedHint } from "./types.js";
|
|
4
4
|
|
|
5
5
|
export function statedHints(map: SourceMap | ResolvedMap) {
|
|
6
6
|
return (map.layout?.hints ?? []).map((hint, i) => ({
|
|
@@ -11,7 +11,7 @@ export function statedHints(map: SourceMap | ResolvedMap) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** Name source hints in capability refusals without losing their references. */
|
|
14
|
-
export function constraintName(constraint: Constraint): string {
|
|
14
|
+
export function constraintName(constraint: Constraint | StatedHint): string {
|
|
15
15
|
if (!constraint.path) return constraint.kind;
|
|
16
16
|
const ids =
|
|
17
17
|
constraint.kind === "side"
|
package/src/layout/index.ts
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { validateReferences } from "../schema/references.js";
|
|
3
|
-
import { parseMap } from "./check.js";
|
|
4
|
-
import { asMeasurer } from "./measure.js";
|
|
5
|
-
import type { Measurer } from "./ports.js";
|
|
6
|
-
import { atWidth, needsWidthPass } from "./width.js";
|
|
7
|
-
import { refine } from "./stages/refine.js";
|
|
8
|
-
import { buildProblem, problemGraph } from "./build-problem.js";
|
|
9
|
-
import { reportUnsupportedHints } from "./hints.js";
|
|
10
|
-
import { asPlacer } from "./legacy.js";
|
|
11
|
-
import { placeWithHints } from "./place-with-hints.js";
|
|
12
|
-
import { checkConstraints } from "./stages/constraints.js";
|
|
13
|
-
import { resolveMeasured } from "./resolve-measured.js";
|
|
14
|
-
import type { RouteRefinement } from "./inspect-routes.js";
|
|
15
|
-
import type { LayoutEngine, LayoutOptions, UnsupportedHint } from "./types.js";
|
|
16
|
-
import {
|
|
17
|
-
EngineFailedError,
|
|
18
|
-
ResultRejectedError,
|
|
19
|
-
UnsupportedConstraintsError,
|
|
20
|
-
LayoutDefectsError,
|
|
21
|
-
} from "./errors.js";
|
|
22
|
-
import { placeAnnotations } from "./stages/placement.js";
|
|
1
|
+
export { layout } from "./layout.js";
|
|
23
2
|
export {
|
|
24
3
|
LayoutError,
|
|
25
4
|
EngineFailedError,
|
|
@@ -55,129 +34,3 @@ export type {
|
|
|
55
34
|
Contact,
|
|
56
35
|
LayoutReport,
|
|
57
36
|
} from "./stages/report.js";
|
|
58
|
-
|
|
59
|
-
/** Validate first, then measure and lay out; complete hand geometry is retained.
|
|
60
|
-
* `layout` proposes a drawing; `check` judges it. Success here does not mean
|
|
61
|
-
* the drawing was checked unless `strict` is set. */
|
|
62
|
-
export async function layout(
|
|
63
|
-
input: unknown,
|
|
64
|
-
engine: LayoutEngine,
|
|
65
|
-
options: LayoutOptions = {},
|
|
66
|
-
): Promise<ResolvedMap> {
|
|
67
|
-
const map = parseMap(input);
|
|
68
|
-
validateReferences(map);
|
|
69
|
-
if (
|
|
70
|
-
options.widthEm !== undefined &&
|
|
71
|
-
(!Number.isFinite(options.widthEm) || options.widthEm <= 0)
|
|
72
|
-
)
|
|
73
|
-
throw new Error("widthEm must be a finite positive number");
|
|
74
|
-
const measurer = asMeasurer(options.measureLabel);
|
|
75
|
-
if ("viewBox" in map)
|
|
76
|
-
return strict(
|
|
77
|
-
map,
|
|
78
|
-
map,
|
|
79
|
-
atWidth(measurer, map, options.widthEm).measure,
|
|
80
|
-
options,
|
|
81
|
-
);
|
|
82
|
-
const resolved = await resolveAtWidth(map, engine, measurer, options);
|
|
83
|
-
return strict(
|
|
84
|
-
map,
|
|
85
|
-
resolved,
|
|
86
|
-
atWidth(measurer, resolved, options.widthEm).measure,
|
|
87
|
-
options,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async function resolveAtWidth(
|
|
92
|
-
map: SourceMap,
|
|
93
|
-
engine: LayoutEngine,
|
|
94
|
-
measurer: Measurer,
|
|
95
|
-
options: LayoutOptions,
|
|
96
|
-
): Promise<ResolvedMap> {
|
|
97
|
-
let hints: readonly UnsupportedHint[] = [];
|
|
98
|
-
const collect = {
|
|
99
|
-
...options,
|
|
100
|
-
onUnsupportedHints: (items: readonly UnsupportedHint[]) => {
|
|
101
|
-
hints = items;
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
let resolved = await resolveSource(map, engine, measurer, collect);
|
|
105
|
-
if (
|
|
106
|
-
options.widthEm !== undefined &&
|
|
107
|
-
needsWidthPass(resolved, options.widthEm)
|
|
108
|
-
) {
|
|
109
|
-
hints = [];
|
|
110
|
-
resolved = await resolveSource(
|
|
111
|
-
map,
|
|
112
|
-
engine,
|
|
113
|
-
atWidth(measurer, resolved, options.widthEm),
|
|
114
|
-
collect,
|
|
115
|
-
{ measurer, widthEm: options.widthEm },
|
|
116
|
-
);
|
|
117
|
-
resolved = refine(resolved, atWidth(measurer, resolved, options.widthEm));
|
|
118
|
-
}
|
|
119
|
-
if (hints.length) options.onUnsupportedHints?.(hints);
|
|
120
|
-
return resolved;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function resolveSource(
|
|
124
|
-
map: SourceMap,
|
|
125
|
-
engine: LayoutEngine,
|
|
126
|
-
measurer: Measurer,
|
|
127
|
-
options: LayoutOptions,
|
|
128
|
-
refinement?: RouteRefinement,
|
|
129
|
-
): Promise<ResolvedMap> {
|
|
130
|
-
const measure = measurer.measure.bind(measurer);
|
|
131
|
-
const problem = buildProblem(map, measure, options.intent);
|
|
132
|
-
const graph = problemGraph(problem);
|
|
133
|
-
const placer = asPlacer(engine);
|
|
134
|
-
const outcome = await placeWithHints(
|
|
135
|
-
map,
|
|
136
|
-
problem,
|
|
137
|
-
placer,
|
|
138
|
-
measurer,
|
|
139
|
-
refinement,
|
|
140
|
-
refinement ? undefined : options.widthEm,
|
|
141
|
-
);
|
|
142
|
-
if (outcome.kind === "engine-failed") throw new EngineFailedError(outcome);
|
|
143
|
-
if (outcome.kind === "unsupported-constraints")
|
|
144
|
-
throw new UnsupportedConstraintsError(outcome);
|
|
145
|
-
reportUnsupportedHints(
|
|
146
|
-
outcome.unsupported,
|
|
147
|
-
options.onUnsupportedHints,
|
|
148
|
-
outcome.dropped,
|
|
149
|
-
);
|
|
150
|
-
const resolved = resolveMeasured(map, graph, outcome.result, measurer);
|
|
151
|
-
checkRequired(map, resolved, placer.name);
|
|
152
|
-
validateReferences(resolved);
|
|
153
|
-
return placeAnnotations(resolved);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function checkRequired(map: SourceMap, resolved: ResolvedMap, placer: string) {
|
|
157
|
-
const rejected = checkConstraints(map, resolved).find(
|
|
158
|
-
(c) => c.strength === "required" && c.holds === false,
|
|
159
|
-
);
|
|
160
|
-
if (rejected)
|
|
161
|
-
throw new ResultRejectedError({
|
|
162
|
-
placer,
|
|
163
|
-
constraint: rejected.kind,
|
|
164
|
-
message: rejected.message,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** The check is loaded only for `strict`, so plain layout stays small. */
|
|
169
|
-
async function strict(
|
|
170
|
-
source: SourceMap | ResolvedMap,
|
|
171
|
-
resolved: ResolvedMap,
|
|
172
|
-
measure: import("./types.js").LabelMeasurer,
|
|
173
|
-
options: LayoutOptions,
|
|
174
|
-
): Promise<ResolvedMap> {
|
|
175
|
-
if (!options.strict) return resolved;
|
|
176
|
-
const { check, describeDefects } = await import("./stages/report.js");
|
|
177
|
-
const report = check(source, resolved, { measureLabel: measure });
|
|
178
|
-
if (!report.hard) return resolved;
|
|
179
|
-
throw new LayoutDefectsError(
|
|
180
|
-
report,
|
|
181
|
-
`The layout has hard defects:\n${describeDefects(report).join("\n")}`,
|
|
182
|
-
);
|
|
183
|
-
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ResolvedMap, SourceMap } from "../schema.js";
|
|
2
|
+
import { validateReferences } from "../schema/references.js";
|
|
3
|
+
import { parseMap } from "./check.js";
|
|
4
|
+
import { asMeasurer } from "./measure.js";
|
|
5
|
+
import type { Measurer } from "./ports.js";
|
|
6
|
+
import { atWidth, needsWidthPass } from "./width.js";
|
|
7
|
+
import { refine } from "./stages/refine.js";
|
|
8
|
+
import { buildProblem, problemGraph } from "./build-problem.js";
|
|
9
|
+
import { reportUnsupportedHints } from "./hints.js";
|
|
10
|
+
import { asPlacer } from "./legacy.js";
|
|
11
|
+
import { placeWithHints } from "./place-with-hints.js";
|
|
12
|
+
import { checkConstraints } from "./stages/constraints.js";
|
|
13
|
+
import { resolveMeasured } from "./resolve-measured.js";
|
|
14
|
+
import type { RouteRefinement } from "./inspect-routes.js";
|
|
15
|
+
import type { LayoutEngine, LayoutOptions, UnsupportedHint } from "./types.js";
|
|
16
|
+
import {
|
|
17
|
+
EngineFailedError,
|
|
18
|
+
ResultRejectedError,
|
|
19
|
+
UnsupportedConstraintsError,
|
|
20
|
+
LayoutDefectsError,
|
|
21
|
+
} from "./errors.js";
|
|
22
|
+
import { placeAnnotations } from "./stages/placement.js";
|
|
23
|
+
/** Validate first, then measure and lay out; complete hand geometry is retained.
|
|
24
|
+
* `layout` proposes a drawing; `check` judges it. Success here does not mean
|
|
25
|
+
* the drawing was checked unless `strict` is set. */
|
|
26
|
+
export async function layout(
|
|
27
|
+
input: unknown,
|
|
28
|
+
engine: LayoutEngine,
|
|
29
|
+
options: LayoutOptions = {},
|
|
30
|
+
): Promise<ResolvedMap> {
|
|
31
|
+
const map = parseMap(input);
|
|
32
|
+
validateReferences(map);
|
|
33
|
+
if (
|
|
34
|
+
options.widthEm !== undefined &&
|
|
35
|
+
(!Number.isFinite(options.widthEm) || options.widthEm <= 0)
|
|
36
|
+
)
|
|
37
|
+
throw new Error("widthEm must be a finite positive number");
|
|
38
|
+
const measurer = asMeasurer(options.measureLabel);
|
|
39
|
+
if ("viewBox" in map)
|
|
40
|
+
return strict(
|
|
41
|
+
map,
|
|
42
|
+
map,
|
|
43
|
+
atWidth(measurer, map, options.widthEm).measure,
|
|
44
|
+
options,
|
|
45
|
+
);
|
|
46
|
+
const resolved = await resolveAtWidth(map, engine, measurer, options);
|
|
47
|
+
return strict(
|
|
48
|
+
map,
|
|
49
|
+
resolved,
|
|
50
|
+
atWidth(measurer, resolved, options.widthEm).measure,
|
|
51
|
+
options,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function resolveAtWidth(
|
|
56
|
+
map: SourceMap,
|
|
57
|
+
engine: LayoutEngine,
|
|
58
|
+
measurer: Measurer,
|
|
59
|
+
options: LayoutOptions,
|
|
60
|
+
): Promise<ResolvedMap> {
|
|
61
|
+
let hints: readonly UnsupportedHint[] = [];
|
|
62
|
+
const collect = {
|
|
63
|
+
...options,
|
|
64
|
+
onUnsupportedHints: (items: readonly UnsupportedHint[]) => {
|
|
65
|
+
hints = items;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
let resolved = await resolveSource(map, engine, measurer, collect);
|
|
69
|
+
if (
|
|
70
|
+
options.widthEm !== undefined &&
|
|
71
|
+
needsWidthPass(resolved, options.widthEm)
|
|
72
|
+
) {
|
|
73
|
+
hints = [];
|
|
74
|
+
resolved = await resolveSource(
|
|
75
|
+
map,
|
|
76
|
+
engine,
|
|
77
|
+
atWidth(measurer, resolved, options.widthEm),
|
|
78
|
+
collect,
|
|
79
|
+
{ measurer, widthEm: options.widthEm },
|
|
80
|
+
);
|
|
81
|
+
resolved = refine(resolved, atWidth(measurer, resolved, options.widthEm));
|
|
82
|
+
}
|
|
83
|
+
if (hints.length) options.onUnsupportedHints?.(hints);
|
|
84
|
+
return resolved;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function resolveSource(
|
|
88
|
+
map: SourceMap,
|
|
89
|
+
engine: LayoutEngine,
|
|
90
|
+
measurer: Measurer,
|
|
91
|
+
options: LayoutOptions,
|
|
92
|
+
refinement?: RouteRefinement,
|
|
93
|
+
): Promise<ResolvedMap> {
|
|
94
|
+
const measure = measurer.measure.bind(measurer);
|
|
95
|
+
const problem = buildProblem(map, measure, options.intent);
|
|
96
|
+
const graph = problemGraph(problem);
|
|
97
|
+
const placer = asPlacer(engine);
|
|
98
|
+
const outcome = await placeWithHints(
|
|
99
|
+
map,
|
|
100
|
+
problem,
|
|
101
|
+
placer,
|
|
102
|
+
measurer,
|
|
103
|
+
refinement,
|
|
104
|
+
refinement ? undefined : options.widthEm,
|
|
105
|
+
);
|
|
106
|
+
if (outcome.kind === "engine-failed") throw new EngineFailedError(outcome);
|
|
107
|
+
if (outcome.kind === "unsupported-constraints")
|
|
108
|
+
throw new UnsupportedConstraintsError(outcome);
|
|
109
|
+
reportUnsupportedHints(
|
|
110
|
+
outcome.unsupported,
|
|
111
|
+
options.onUnsupportedHints,
|
|
112
|
+
outcome.dropped,
|
|
113
|
+
);
|
|
114
|
+
const resolved = resolveMeasured(map, graph, outcome.result, measurer);
|
|
115
|
+
checkRequired(map, resolved, placer.name);
|
|
116
|
+
validateReferences(resolved);
|
|
117
|
+
return placeAnnotations(resolved);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function checkRequired(map: SourceMap, resolved: ResolvedMap, placer: string) {
|
|
121
|
+
const rejected = checkConstraints(map, resolved).find(
|
|
122
|
+
(c) => c.strength === "required" && c.holds === false,
|
|
123
|
+
);
|
|
124
|
+
if (rejected)
|
|
125
|
+
throw new ResultRejectedError({
|
|
126
|
+
placer,
|
|
127
|
+
constraint: rejected.kind,
|
|
128
|
+
message: rejected.message,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The check is loaded only for `strict`, so plain layout stays small. */
|
|
133
|
+
async function strict(
|
|
134
|
+
source: SourceMap | ResolvedMap,
|
|
135
|
+
resolved: ResolvedMap,
|
|
136
|
+
measure: import("./types.js").LabelMeasurer,
|
|
137
|
+
options: LayoutOptions,
|
|
138
|
+
): Promise<ResolvedMap> {
|
|
139
|
+
if (!options.strict) return resolved;
|
|
140
|
+
const { check, describeDefects } = await import("./stages/report.js");
|
|
141
|
+
const report = check(source, resolved, { measureLabel: measure });
|
|
142
|
+
if (!report.hard) return resolved;
|
|
143
|
+
throw new LayoutDefectsError(
|
|
144
|
+
report,
|
|
145
|
+
`The layout has hard defects:\n${describeDefects(report).join("\n")}`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -4,6 +4,7 @@ import type { Measurer, Placer } from "./ports.js";
|
|
|
4
4
|
import type { RouteRefinement } from "./inspect-routes.js";
|
|
5
5
|
import { place } from "./place.js";
|
|
6
6
|
import { problemGraph } from "./build-problem.js";
|
|
7
|
+
import { sketchConflicts } from "./sketch-conflicts.js";
|
|
7
8
|
import { routeSketch } from "./sketch-route.js";
|
|
8
9
|
|
|
9
10
|
/** Optional preferred-pin pass after an engine places the boxes. */
|
|
@@ -18,17 +19,21 @@ export async function placeSketch(
|
|
|
18
19
|
const outcome = await place(problem, placer);
|
|
19
20
|
if (outcome.kind !== "placed") return outcome;
|
|
20
21
|
const graph = problemGraph(problem);
|
|
22
|
+
const diagnostics = sketchConflicts(problem);
|
|
23
|
+
const result = routeSketch(
|
|
24
|
+
source,
|
|
25
|
+
problem,
|
|
26
|
+
graph,
|
|
27
|
+
outcome.result,
|
|
28
|
+
measurer,
|
|
29
|
+
refinement,
|
|
30
|
+
sizingWidthEm,
|
|
31
|
+
diagnostics.record,
|
|
32
|
+
);
|
|
21
33
|
return {
|
|
22
34
|
...outcome,
|
|
35
|
+
dropped: diagnostics.hints,
|
|
23
36
|
unsupported: outcome.unsupported.filter((hint) => hint.kind !== "pin"),
|
|
24
|
-
result
|
|
25
|
-
source,
|
|
26
|
-
problem,
|
|
27
|
-
graph,
|
|
28
|
-
outcome.result,
|
|
29
|
-
measurer,
|
|
30
|
-
refinement,
|
|
31
|
-
sizingWidthEm,
|
|
32
|
-
),
|
|
37
|
+
result,
|
|
33
38
|
};
|
|
34
39
|
}
|
|
@@ -4,10 +4,16 @@ import { checkRelations } from "./check.js";
|
|
|
4
4
|
import { solveRelations } from "./solve.js";
|
|
5
5
|
import type { DifferenceRelation, RelationSystem } from "./types.js";
|
|
6
6
|
|
|
7
|
+
export type RecordSketchConflict = (
|
|
8
|
+
relation: DifferenceRelation,
|
|
9
|
+
cycle: readonly string[],
|
|
10
|
+
) => void;
|
|
11
|
+
|
|
7
12
|
/** Restore the engine bound for each sketch pair in a checked positive cycle. */
|
|
8
13
|
export function restoreConflicts(
|
|
9
14
|
system: RelationSystem,
|
|
10
15
|
originals: ReadonlyMap<string, DifferenceRelation | null>,
|
|
16
|
+
record?: RecordSketchConflict,
|
|
11
17
|
): DifferenceRelation[] | null {
|
|
12
18
|
const dropped: DifferenceRelation[] = [];
|
|
13
19
|
for (;;) {
|
|
@@ -23,6 +29,10 @@ export function restoreConflicts(
|
|
|
23
29
|
const engine = originals.get(relation.id);
|
|
24
30
|
if (engine === undefined || !pairs.has(relation.id)) return relation;
|
|
25
31
|
dropped.push(relation);
|
|
32
|
+
record?.(
|
|
33
|
+
relation,
|
|
34
|
+
result.cycle.map((source) => source.id),
|
|
35
|
+
);
|
|
26
36
|
return engine ?? [];
|
|
27
37
|
});
|
|
28
38
|
if (dropped.length === count) return null;
|
|
@@ -45,6 +55,7 @@ export function followSketchOrder(
|
|
|
45
55
|
system: RelationSystem,
|
|
46
56
|
cross: 0 | 1,
|
|
47
57
|
gap: number,
|
|
58
|
+
record?: RecordSketchConflict,
|
|
48
59
|
): DifferenceRelation[] | null {
|
|
49
60
|
const rank = 1 - cross;
|
|
50
61
|
const pins = preferredPins(problem);
|
|
@@ -75,5 +86,5 @@ export function followSketchOrder(
|
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
|
-
return restoreConflicts(system, originals);
|
|
89
|
+
return restoreConflicts(system, originals, record);
|
|
79
90
|
}
|
|
@@ -8,6 +8,7 @@ import { solveRelations } from "./solve.js";
|
|
|
8
8
|
import type { RelationGraph, RelationSystem } from "./types.js";
|
|
9
9
|
import { arrowObjective } from "./objective.js";
|
|
10
10
|
import { optimiseArrows } from "./optimise.js";
|
|
11
|
+
import type { RecordSketchConflict } from "./sketch-order.js";
|
|
11
12
|
import { followSketchOrder, restoreConflicts } from "./sketch-order.js";
|
|
12
13
|
|
|
13
14
|
/** Measure centre-to-pin distance against the graph's fixed zero vertex. */
|
|
@@ -40,6 +41,7 @@ export function sketchPlacement(
|
|
|
40
41
|
original: LayoutResult,
|
|
41
42
|
minimum?: number,
|
|
42
43
|
sketchOrder = true,
|
|
44
|
+
record?: RecordSketchConflict,
|
|
43
45
|
): LayoutResult["nodes"] | null {
|
|
44
46
|
const direction = problem.constraints.find((c) => c.kind === "direction");
|
|
45
47
|
const cross = direction?.direction === "right" ? 1 : 0;
|
|
@@ -48,7 +50,7 @@ export function sketchPlacement(
|
|
|
48
50
|
containMembers(problem, original, system, cross);
|
|
49
51
|
if (
|
|
50
52
|
sketchOrder
|
|
51
|
-
? !followSketchOrder(problem, system, cross, gap)
|
|
53
|
+
? !followSketchOrder(problem, system, cross, gap, record)
|
|
52
54
|
: solveRelations(system).status === "contradictory"
|
|
53
55
|
)
|
|
54
56
|
return null;
|
|
@@ -104,6 +106,7 @@ export function sketchRankPlacement(
|
|
|
104
106
|
problem: LayoutProblem,
|
|
105
107
|
original: LayoutResult,
|
|
106
108
|
groupRanks = false,
|
|
109
|
+
record?: RecordSketchConflict,
|
|
107
110
|
) {
|
|
108
111
|
const direction = problem.constraints.find((c) => c.kind === "direction");
|
|
109
112
|
const rank = direction?.direction === "right" ? 0 : 1;
|
|
@@ -112,7 +115,9 @@ export function sketchRankPlacement(
|
|
|
112
115
|
const groups = groupRanks ? hintRelations(sketchRanks(problem, rank)) : [];
|
|
113
116
|
if (groupRanks && !groups.length) return null;
|
|
114
117
|
system.relations.push(...groups);
|
|
115
|
-
if (
|
|
118
|
+
if (
|
|
119
|
+
!restoreConflicts(system, new Map(groups.map((r) => [r.id, null])), record)
|
|
120
|
+
)
|
|
116
121
|
return null;
|
|
117
122
|
const graph = normalizeRelations(system);
|
|
118
123
|
return placeAxis(original, graph, rank, pinObjective(problem, graph, rank));
|
|
@@ -151,17 +156,18 @@ function placeAxis(
|
|
|
151
156
|
export function sketchPlacements(
|
|
152
157
|
problem: LayoutProblem,
|
|
153
158
|
original: LayoutResult,
|
|
159
|
+
record?: RecordSketchConflict,
|
|
154
160
|
) {
|
|
155
161
|
const placements = [
|
|
156
162
|
sketchPlacement(problem, original, 0, false),
|
|
157
|
-
sketchPlacement(problem, original, 0),
|
|
163
|
+
sketchPlacement(problem, original, 0, true, record),
|
|
158
164
|
];
|
|
159
165
|
for (const grouped of [false, true]) {
|
|
160
|
-
const ranked = sketchRankPlacement(problem, original, grouped);
|
|
166
|
+
const ranked = sketchRankPlacement(problem, original, grouped, record);
|
|
161
167
|
if (!ranked) continue;
|
|
162
168
|
placements.push(
|
|
163
169
|
ranked,
|
|
164
|
-
sketchPlacement(problem, { ...original, nodes: ranked }, 0),
|
|
170
|
+
sketchPlacement(problem, { ...original, nodes: ranked }, 0, true, record),
|
|
165
171
|
);
|
|
166
172
|
}
|
|
167
173
|
return placements;
|