@mark1russell7/layout-contract 0.3.12 → 0.4.0

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.
@@ -426,7 +426,7 @@ interface ShapeGeometry {
426
426
  readonly area: boolean;
427
427
  /** The test that the shape is inside a region: `rectInRegion` for a `rect`. */
428
428
  readonly contains: boolean;
429
- /** The test that two shapes overlap: `overlapOf` for two `rect` shapes. */
429
+ /** The test that two shapes of this kind overlap: `overlapOf` for two `rect` shapes, `shapesOverlap` for two `circle` shapes. */
430
430
  readonly overlap: boolean;
431
431
  }
432
432
  /** The facts of one shape kind: its fields, the kinds of `Region` that give it, and its geometry. */
@@ -440,7 +440,7 @@ interface ShapeKindSpec {
440
440
  }
441
441
  /**
442
442
  * The declared shape kinds, in their order. Only `rect` has all of its geometry.
443
- * `polygon` and `circle` have their bounding box and their exact area. `free` has its bounding box only.
443
+ * `polygon` and `circle` have their bounding box and their exact area. A `circle` also has the overlap test of two circles. `free` has its bounding box only.
444
444
  */
445
445
  declare const SHAPE_KINDS: readonly ShapeKindSpec[];
446
446
  /** The ids of `SHAPE_KINDS`, in their order. */
@@ -462,6 +462,21 @@ interface ShapeSupport<Id extends string = string> {
462
462
  * A kind is in one list only: `shapes`, `safe` or `bound.shapes`. `docs/SHAPES.md` tells what a bound value proves.
463
463
  */
464
464
  readonly bound?: ShapeBound;
465
+ /** The inputs where the exact count of this rule is only safe, with the reason and the date of the fix. `inputShapeLevel` reads it. */
466
+ readonly limit?: ShapeLimit;
467
+ }
468
+ /**
469
+ * A stated limit of an exact rule on circles. An input that the limit names gets the level `safe` for each kind that is exact.
470
+ *
471
+ * - `neighbours`: the input has a circle beside another shape kind or an obstacle.
472
+ * - `container`: the input has a circle in a container that is a polygon or an ellipse.
473
+ */
474
+ interface ShapeLimit {
475
+ readonly reads: "neighbours" | "container";
476
+ /** The reason, in words. */
477
+ readonly because: string;
478
+ /** The date of the fix, as `YYYY-MM-DD`. */
479
+ readonly until: string;
465
480
  }
466
481
  /**
467
482
  * The kinds where a measure gives a bound of the true value, and the side of the bound.
@@ -497,10 +512,18 @@ type ShapeLevel = RuleLevel | "bound";
497
512
  * A kind of `shapesOf` is `exact`, a kind of `safe` is `safe`, a kind of `bound.shapes` is `bound`, and another kind is `none`.
498
513
  */
499
514
  declare function shapeLevel(use: Pick<ShapeSupport, "shapes" | "safe" | "bound">, kind: ShapeKind): ShapeLevel;
515
+ /** The parts of an input that `inputShapeLevel` and `checkShapes` read. */
516
+ type ShapeInput = Pick<LayoutInput, "id" | "boxes"> & Partial<Pick<LayoutInput, "obstacles" | "container">>;
517
+ /**
518
+ * This function gives the level of a measure or a rule on a shape kind for one input. It is `shapeLevel` with the `limit` of the rule.
519
+ * When the limit names the input, the level `exact` becomes `safe`. Each other level does not change.
520
+ */
521
+ declare function inputShapeLevel(use: Pick<ShapeSupport, "shapes" | "safe" | "bound" | "limit">, kind: ShapeKind, input: ShapeInput): ShapeLevel;
500
522
  /**
501
523
  * This function gives the problems of a list of measures and rules. An empty list tells that the list is good.
502
524
  * It refuses an unknown kind, a kind two times in one list, and a kind in more than one of `shapesOf`, `safe` and `bound.shapes`.
503
525
  * It also refuses a `bound` without a list of kinds, and a `side` that is not `upper` or `lower`.
526
+ * It also refuses a `limit` with a bad `reads` or a bad `until`.
504
527
  */
505
528
  declare function shapeSupportProblems(uses: readonly ShapeSupport[]): string[];
506
529
  /** This function tells if a value is a declared shape kind. */
@@ -540,7 +563,7 @@ interface ShapeCheck {
540
563
  * By default, a kind of `safe` or of `bound.shapes` is a break, because the result is not exact.
541
564
  * With the level `safe`, a kind of `safe` is not a break. With the level `bound`, a kind of `safe` and a kind of `bound.shapes` are not a break.
542
565
  */
543
- declare function checkShapes(input: Pick<LayoutInput, "id" | "boxes">, uses: readonly ShapeSupport[], options?: ShapeCheck): ClaimBreak[];
566
+ declare function checkShapes(input: ShapeInput, uses: readonly ShapeSupport[], options?: ShapeCheck): ClaimBreak[];
544
567
  /** The direction of a measure: the side of the better values. */
545
568
  type Direction = "lower" | "higher";
546
569
  /**
@@ -603,5 +626,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
603
626
  * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
604
627
  */
605
628
  declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
606
- export { FAMILY_ANY_KIND as $, shapesOf as A, toSizedRect as At, PackInputOptions as B, itemShapeOf as C, grow as Ct, shapeKindsOf as D, regionArea as Dt, shapeKindProblem as E, pointSegmentDistance as Et, LayoutEdge as F, packLinks as G, PairGap as H, LayoutGenerator as I, ClaimBreak as J, portPoint as K, LayoutInput as L, LayoutBox as M, LayoutCell as N, shapeLevel as O, segmentsCross as Ot, LayoutContainer as P, Declares as Q, Obstacle as R, isShapeKind as S, boundsOf as St, shapeKindOf as T, overlapOf as Tt, Port as U, PackLink as V, canonicalInput as W, CorpusSplit as X, CorpusEntry as Y, DeclaredClaim as Z, ShapeKindSpec as _, Region as _t, MeasureSpec as a, checkDeclared as at, boxArea as b, Sides as bt, minEffectOf as c, declaredClaimOf as ct, SHAPE_KINDS as d, leaveOneSeedOut as dt, FamilyBy as et, SHAPE_KIND_IDS as f, splitFileName as ft, ShapeKind as g, Rect as gt, ShapeGeometry as h, Point as ht, JointMeasureId as i, SplitFold as it, Item as j, translate as jt, shapeSupportProblems as k, toRect as kt, DEFAULT_SHAPES as l, declaredCounts as lt, ShapeCheck as m, Margin as mt, JOINT_MEASURES as n, SPLIT_SCHEMA as nt, Verdict as o, checkSplit as ot, ShapeBound as p, splitFolds as pt, toPackInput as q, JOINT_MOVED_MIN as r, SplitCorpus as rt, compareMeasure as s, corpusHashOf as st, Direction as t, FamilyCell as tt, RuleLevel as u, familyOf as ut, ShapeLevel as v, SIDES as vt, ruleLevel as w, marginSides as wt, checkShapes as x, SizedRect as xt, ShapeSupport as y, Side as yt, PackInput as z };
607
- //# sourceMappingURL=measures-C-Tuv8GU.d.ts.map
629
+ export { CorpusSplit as $, shapeKindsOf as A, regionArea as At, LayoutInput as B, checkShapes as C, Sides as Ct, ruleLevel as D, marginSides as Dt, itemShapeOf as E, grow as Et, LayoutBox as F, PairGap as G, PackInput as H, LayoutCell as I, packLinks as J, Port as K, LayoutContainer as L, shapeSupportProblems as M, toRect as Mt, shapesOf as N, toSizedRect as Nt, shapeKindOf as O, overlapOf as Ot, Item as P, translate as Pt, CorpusEntry as Q, LayoutEdge as R, boxArea as S, Side as St, isShapeKind as T, boundsOf as Tt, PackInputOptions as U, Obstacle as V, PackLink as W, toPackInput as X, portPoint as Y, ClaimBreak as Z, ShapeKind as _, Margin as _t, MeasureSpec as a, SPLIT_SCHEMA as at, ShapeLimit as b, Region as bt, minEffectOf as c, checkDeclared as ct, SHAPE_KINDS as d, declaredClaimOf as dt, DeclaredClaim as et, SHAPE_KIND_IDS as f, declaredCounts as ft, ShapeInput as g, splitFolds as gt, ShapeGeometry as h, splitFileName as ht, JointMeasureId as i, FamilyCell as it, shapeLevel as j, segmentsCross as jt, shapeKindProblem as k, pointSegmentDistance as kt, DEFAULT_SHAPES as l, checkSplit as lt, ShapeCheck as m, leaveOneSeedOut as mt, JOINT_MEASURES as n, FAMILY_ANY_KIND as nt, Verdict as o, SplitCorpus as ot, ShapeBound as p, familyOf as pt, canonicalInput as q, JOINT_MOVED_MIN as r, FamilyBy as rt, compareMeasure as s, SplitFold as st, Direction as t, Declares as tt, RuleLevel as u, corpusHashOf as ut, ShapeKindSpec as v, Point as vt, inputShapeLevel as w, SizedRect as wt, ShapeSupport as x, SIDES as xt, ShapeLevel as y, Rect as yt, LayoutGenerator as z };
630
+ //# sourceMappingURL=measures-KWg_was6.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"measures-C-Tuv8GU.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KACY;;cAGC,gBAAgB;UAEZ;WACN;W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;;WAEA;;;UAIM;WACN,IAAI;;WAEJ;;WAEA,kBAAkB;WAClB,UAAU;;;;;;cAOR,sBAAsB;;cAQtB,yBAAyB;;cAGzB,yBAAyB;;UAGrB,aAAa;WACnB,IAAI;;WAEJ,kBAAkB;;;;;WAKlB,gBAAgB;;;;;WAKhB,QAAQ;;;;;;;;;;;;;;;;;;;;;UAsBF;WACN,iBAAiB;WACjB;;;KAIC;;iBAGI,UAAU,MAAM,KAAK,kCAAkC,MAAM,YAAY;;KAM7E,aAAa;;;;;iBAMT,WAAW,KAAK,KAAK,4CAA4C,MAAM,YAAY;;;;;;iBAWnF,qBAAqB,eAAe;;iBAoCpC,YAAY,iBAAiB,SAAS;;;;;iBAQtC,YAAY,KAAK,YAAY;;;;;;;iBAW7B,QAAQ,KAAK;;iBAQb,aAAa,OAAO,KAAK,wBAAwB;;iBAMjD,YAAY,OAAO,KAAK,wBAAwB;;iBAMhD,iBAAiB,KAAK;;iBAWtB,SAAS,KAAK,KAAK,mCAAmC;;UAKrD;;;;;;WAMN;;;;;;;;iBASK,YAAY,OAAO,KAAK,8BAA8B,eAAe,gBAAgB,UAAS,aAAkB;;KC5NpH;;;;;;UAOK,YAAY;WAClB,IAAI;WACJ;WACA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;KAIP;;;;;cAoBC,yBAAyB,YAAY;;cAarC;;KAGD;;;;;;iBAOI,YAAY,MAAM,KAAK,2BAA2B,YAAO;;;;;;;iBAezD,eAAe,mBAAmB,kBAAkB,MAAM,KAAK,0CAA0C"}
1
+ {"version":3,"file":"measures-KWg_was6.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KACY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;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
3
3
  * The advance function of a host: the width of a run of text in a font, in pixels.
4
4
  * A browser host gives `canvasAdvance(context)`. A test or a server host gives a function of a font file.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/layout-contract",
4
- "version": "0.3.12",
4
+ "version": "0.4.0",
5
5
  "description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
6
6
  "keywords": [
7
7
  "layout",
package/src/record.ts CHANGED
@@ -30,6 +30,8 @@ export interface LayoutRecord {
30
30
  readonly hard: Readonly<Record<string, number>>;
31
31
  /** The tolerance of each hard rule of the run. */
32
32
  readonly tolerance?: Readonly<Partial<Tolerance>>;
33
+ /** The version of the rules that made the counts of `hard`: `HARD_RULE_VERSION` at the run. `hardRuleOf` reads it. */
34
+ readonly hardRule?: number;
33
35
  /**
34
36
  * The value is `true` when two runs with the same seed give the same positions.
35
37
  * A skipped record has `null`, because no run made a claim. Each other record has a boolean.
@@ -117,7 +119,7 @@ const STAGES: readonly string[] = ["pack", "route", "joint"];
117
119
  const RECORD_STRINGS = ["step", "strategy", "corpus", "input", "inputHash", "set"] as const;
118
120
  const RECORD_NUMBERS = ["seed", "nodes", "edges", "ms"] as const;
119
121
  const RECORD_OPTIONAL_STRINGS = ["prediction", "outputHash", "skipped", "commit"] as const;
120
- const RECORD_OPTIONAL_NUMBERS = ["budgetMs", "msAtLeast"] as const;
122
+ const RECORD_OPTIONAL_NUMBERS = ["budgetMs", "msAtLeast", "hardRule"] as const;
121
123
  const ENV_STRINGS = ["node", "os", "arch", "runner", "cpu"] as const;
122
124
  const ENV_OPTIONAL_STRINGS = ["mode", "context"] as const;
123
125
 
@@ -140,6 +142,14 @@ function envProblems(env: unknown): string[] {
140
142
  return out;
141
143
  }
142
144
 
145
+ /**
146
+ * This function gives the version of the rules that made the counts of `hard` of a record. A record without `hardRule` has version 1.
147
+ * On version 1, a count on a circle is by its bounding box. So it is an upper bound, and a count over 0 proves nothing.
148
+ */
149
+ export function hardRuleOf(record: Pick<LayoutRecord, "hardRule">): number {
150
+ return record.hardRule ?? 1;
151
+ }
152
+
143
153
  /**
144
154
  * This function gives the problems of one `layout-record/1` value. An empty list means a good record.
145
155
  * A record that has `skipped` has `deterministic: null`. An old skipped record with a boolean is also correct.
package/src/rules.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { boundsOf, grow, overlapOf, type Rect, type Region } from "./geometry.ts";
2
- import type { LayoutBox, LayoutInput, Obstacle, PairGap, Port } from "./input.ts";
1
+ import { boundsOf, grow, marginSides, overlapOf, type Margin, type Rect, type Region } from "./geometry.ts";
2
+ import type { LayoutBox, LayoutContainer, LayoutInput, Obstacle, PairGap, Port } from "./input.ts";
3
3
  import { applyPack, type PackOutput } from "./output.ts";
4
4
  import { SHAPE_KIND_IDS, shapeKindProblem, type ShapeSupport } from "./shapes.ts";
5
5
  import { DEFAULT_TOLERANCE, EPS, RECORD_EPS } from "./tolerance.ts";
@@ -13,32 +13,92 @@ export function placedRect(box: LayoutBox): Rect | undefined {
13
13
  }
14
14
 
15
15
  /**
16
- * This function counts the pairs of placed boxes whose insides, with their margins, overlap by more than `tolerance` on each axis.
17
- * A box with a shape counts as its bounding box. That area is larger, thus the count is safe.
16
+ * The version of the rules that count `no-overlap` and `in-container`. A record states it in `LayoutRecord.hardRule`.
18
17
  *
19
- * A pair of `pairGaps`, in either order, uses its `gap` in place of the two margins. One box grows by the gap, and the other box does not grow.
20
- * Thus the pair breaks the rule only when the boxes are nearer than the gap on each axis. The other pairs do not change.
18
+ * - Version 1 counts each shape by its bounding box. On a circle, that count is an upper bound. A count over 0 proves nothing.
19
+ * - Version 2 counts two circles, and a circle in a circle container, by the distance of the centers. The other pairs stay on the bounding box.
21
20
  */
22
- export function countOverlaps(boxes: readonly LayoutBox[], tolerance: number = DEFAULT_TOLERANCE.overlap, pairGaps?: readonly PairGap[]): number {
23
- if (pairGaps === undefined || pairGaps.length === 0) return marginOverlaps(boxes, tolerance, undefined);
21
+ export const HARD_RULE_VERSION = 2;
22
+
23
+ /** A circle at its place on the board: its center and its radius, without a margin. */
24
+ export interface PlacedCircle {
25
+ readonly cx: number;
26
+ readonly cy: number;
27
+ readonly r: number;
28
+ }
29
+
30
+ /** This function gives the circle of a placed box. A box without a position, or with another shape, gives `undefined`. */
31
+ export function placedCircle(box: LayoutBox): PlacedCircle | undefined {
32
+ if (box.shape?.kind !== "circle" || box.x === undefined || box.y === undefined) return undefined;
33
+ return { cx: box.x + box.shape.cx, cy: box.y + box.shape.cy, r: box.shape.r };
34
+ }
35
+
36
+ /** This function gives the largest side of a margin. A circle has one distance to the things near it, so its margin is this side. */
37
+ function marginReach(margin: Margin | undefined): number {
38
+ const m = marginSides(margin);
39
+ return Math.max(m.top, m.right, m.bottom, m.left);
40
+ }
41
+
42
+ /** This function tells if the centers of two circles are nearer than `need`. It compares the squares, so it does not take a root. */
43
+ function nearerThan(a: PlacedCircle, b: PlacedCircle, need: number): boolean {
44
+ if (need <= 0) return false;
45
+ const dx = a.cx - b.cx;
46
+ const dy = a.cy - b.cy;
47
+ return dx * dx + dy * dy < need * need;
48
+ }
49
+
50
+ /**
51
+ * This function tells if two placed boxes break `no-overlap`. It is the rule for one pair of `countOverlaps`.
52
+ *
53
+ * - Two circles break the rule when their centers are nearer than the two radii and the two margins, less `tolerance`. The margin of a circle is the largest side of its margin.
54
+ * - Another pair breaks the rule when the bounding boxes with their margins overlap by more than `tolerance` on each axis. With a shape that is not a rectangle, this test is an upper bound.
55
+ * - With `gap`, the gap replaces the two margins. Two circles are then apart by the two radii and the gap. For another pair, one box grows by the gap.
56
+ * - A box without a position does not overlap.
57
+ */
58
+ export function shapesOverlap(a: LayoutBox, b: LayoutBox, tolerance: number = DEFAULT_TOLERANCE.overlap, gap?: number): boolean {
59
+ const ca = placedCircle(a);
60
+ const cb = placedCircle(b);
61
+ if (ca !== undefined && cb !== undefined) return nearerThan(ca, cb, ca.r + cb.r + (gap ?? marginReach(a.margin) + marginReach(b.margin)) - tolerance);
62
+ const ra = placedRect(a);
63
+ const rb = placedRect(b);
64
+ if (ra === undefined || rb === undefined) return false;
65
+ const o = gap === undefined ? overlapOf(grow(ra, a.margin), grow(rb, b.margin)) : overlapOf(grow(ra, gap), rb);
66
+ return o.x > tolerance && o.y > tolerance;
67
+ }
68
+
69
+ /** This function gives the gap of each pair of `pairGaps` by `pairKey`. The first entry of a pair wins. A pair of one box has no gap. */
70
+ function gapsOf(pairGaps: readonly PairGap[] | undefined): Map<string, number> {
24
71
  const gaps = new Map<string, number>();
25
- for (const p of pairGaps) {
72
+ for (const p of pairGaps ?? []) {
26
73
  const key = pairKey(p.a, p.b);
27
74
  if (p.a !== p.b && !gaps.has(key)) gaps.set(key, p.gap);
28
75
  }
29
- const raw = new Map<string, Rect>();
76
+ return gaps;
77
+ }
78
+
79
+ /**
80
+ * This function counts the pairs of placed boxes that break `no-overlap`. `shapesOverlap` is the rule for one pair.
81
+ * Two circles count by the distance of their centers. Each other pair counts by the bounding boxes, so a circle beside another shape is an upper bound (roadmap item L107).
82
+ *
83
+ * A pair of `pairGaps`, in either order, uses its `gap` in place of the two margins. One box grows by the gap, and the other box does not grow.
84
+ * Thus the pair breaks the rule only when the boxes are nearer than the gap on each axis. The other pairs do not change.
85
+ */
86
+ export function countOverlaps(boxes: readonly LayoutBox[], tolerance: number = DEFAULT_TOLERANCE.overlap, pairGaps?: readonly PairGap[]): number {
87
+ const circles = circleOverlaps(boxes, tolerance, pairGaps);
88
+ if (pairGaps === undefined || pairGaps.length === 0) return circles + marginOverlaps(boxes, tolerance, undefined);
89
+ const gaps = gapsOf(pairGaps);
90
+ const raw = new Map<string, LayoutBox>();
30
91
  for (const box of boxes) {
31
- const r = placedRect(box);
32
- if (r !== undefined && !raw.has(box.id)) raw.set(box.id, r);
92
+ if (placedRect(box) !== undefined && !raw.has(box.id)) raw.set(box.id, box);
33
93
  }
34
- let count = marginOverlaps(boxes, tolerance, gaps);
94
+ let count = circles + marginOverlaps(boxes, tolerance, gaps);
35
95
  for (const [key, gap] of gaps) {
36
96
  const [a, b] = JSON.parse(key) as [string, string];
37
- const ra = raw.get(a);
38
- const rb = raw.get(b);
39
- if (ra === undefined || rb === undefined) continue;
40
- const o = overlapOf(grow(ra, gap), rb);
41
- if (o.x > tolerance && o.y > tolerance) count++;
97
+ const ba = raw.get(a);
98
+ const bb = raw.get(b);
99
+ if (ba === undefined || bb === undefined) continue;
100
+ if (placedCircle(ba) !== undefined && placedCircle(bb) !== undefined) continue;
101
+ if (shapesOverlap(ba, bb, tolerance, gap)) count++;
42
102
  }
43
103
  return count;
44
104
  }
@@ -46,12 +106,50 @@ export function countOverlaps(boxes: readonly LayoutBox[], tolerance: number = D
46
106
  /** This function gives the key of a pair of box ids, with the same key for each order. */
47
107
  const pairKey = (a: string, b: string): string => JSON.stringify(a < b ? [a, b] : [b, a]);
48
108
 
49
- /** This function counts the overlaps of the boxes with their margins. It skips the pairs of `skip`. Without `skip`, it is the rule of 0.2.13. */
109
+ /**
110
+ * This function counts the pairs of placed circles that break `no-overlap`, by the distance of their centers. Each other box does not count.
111
+ *
112
+ * - Two circles break the rule when their centers are nearer than the two radii, the two margins and `gap`, less `tolerance`.
113
+ * - The margin of a circle is the largest side of its margin.
114
+ * - A pair of `pairGaps` is apart by the two radii and its gap, in place of the margins and `gap`.
115
+ * - `gap` has the default 0. The rule `no-overlap` does not read `LayoutInput.gap`, so `countOverlaps` gives no value. An engine that keeps the gap between circles gives it here.
116
+ */
117
+ export function circleOverlaps(boxes: readonly LayoutBox[], tolerance: number = DEFAULT_TOLERANCE.overlap, pairGaps?: readonly PairGap[], gap = 0): number {
118
+ const gaps = gapsOf(pairGaps);
119
+ const discs: { readonly id: string; readonly c: PlacedCircle; readonly reach: number }[] = [];
120
+ const first = new Map<string, PlacedCircle>();
121
+ for (const box of boxes) {
122
+ const c = placedCircle(box);
123
+ if (c === undefined) continue;
124
+ discs.push({ id: box.id, c, reach: c.r + marginReach(box.margin) + gap / 2 });
125
+ if (!first.has(box.id)) first.set(box.id, c);
126
+ }
127
+ discs.sort((a, b) => a.c.cx - a.reach - (b.c.cx - b.reach));
128
+ let count = 0;
129
+ for (let i = 0; i < discs.length; i++) {
130
+ const a = discs[i]!;
131
+ for (let j = i + 1; j < discs.length; j++) {
132
+ const b = discs[j]!;
133
+ if (b.c.cx - b.reach >= a.c.cx + a.reach - tolerance) break;
134
+ if (gaps.has(pairKey(a.id, b.id))) continue;
135
+ if (nearerThan(a.c, b.c, a.reach + b.reach - tolerance)) count++;
136
+ }
137
+ }
138
+ for (const [key, g] of gaps) {
139
+ const [a, b] = JSON.parse(key) as [string, string];
140
+ const ca = first.get(a);
141
+ const cb = first.get(b);
142
+ if (ca !== undefined && cb !== undefined && nearerThan(ca, cb, ca.r + cb.r + g - tolerance)) count++;
143
+ }
144
+ return count;
145
+ }
146
+
147
+ /** This function counts the overlaps by the bounding boxes with their margins. It skips the pairs of `skip` and the pairs of two circles. */
50
148
  function marginOverlaps(boxes: readonly LayoutBox[], tolerance: number, skip: ReadonlyMap<string, number> | undefined): number {
51
- const rects: { readonly id: string; readonly r: Rect }[] = [];
149
+ const rects: { readonly id: string; readonly r: Rect; readonly circle: boolean }[] = [];
52
150
  for (const box of boxes) {
53
151
  const r = placedRect(box);
54
- if (r !== undefined) rects.push({ id: box.id, r: grow(r, box.margin) });
152
+ if (r !== undefined) rects.push({ id: box.id, r: grow(r, box.margin), circle: box.shape?.kind === "circle" });
55
153
  }
56
154
  rects.sort((a, b) => a.r.x - b.r.x);
57
155
  let count = 0;
@@ -60,6 +158,7 @@ function marginOverlaps(boxes: readonly LayoutBox[], tolerance: number, skip: Re
60
158
  for (let j = i + 1; j < rects.length; j++) {
61
159
  const b = rects[j]!.r;
62
160
  if (b.x >= a.x + a.w - tolerance) break;
161
+ if (rects[i]!.circle && rects[j]!.circle) continue;
63
162
  if (skip !== undefined && skip.has(pairKey(rects[i]!.id, rects[j]!.id))) continue;
64
163
  const o = overlapOf(a, b);
65
164
  if (o.x > tolerance && o.y > tolerance) count++;
@@ -72,23 +171,65 @@ function marginOverlaps(boxes: readonly LayoutBox[], tolerance: number, skip: Re
72
171
  export interface ContainerTest {
73
172
  /**
74
173
  * With `true`, a box of a shaped container with the size `fixed` must stay inside the shape, not only inside its bounding box.
75
- * The default is `false`. The default changes to `true` at the next breaking version.
174
+ * A circle in a circle container is tested by distance. The default is `true` since 0.4.0. With `false`, only the bounding box counts.
76
175
  */
77
176
  readonly exactContainer?: boolean;
78
177
  }
79
178
 
179
+ /** This function gives the circle of a circle container. A free size reads its radius from `w`, and the corner of the shape stays. Another container, or a free size without `w`, gives `undefined`. */
180
+ function containerCircle(c: LayoutContainer): PlacedCircle | undefined {
181
+ const s = c.shape;
182
+ if (s?.kind !== "circle") return undefined;
183
+ if (c.fixed === "size") return s;
184
+ if (c.w === undefined) return undefined;
185
+ const r = c.w / 2;
186
+ return { cx: s.cx - s.r + r, cy: s.cy - s.r + r, r };
187
+ }
188
+
189
+ /** This function tells if a circle goes out of a circle container. The reach is the center distance, the radius and `extra`. It compares the squares. */
190
+ function circleOutside(disc: PlacedCircle, extra: number, ring: PlacedCircle, tolerance: number): boolean {
191
+ const room = ring.r + tolerance - disc.r - extra;
192
+ if (room < 0) return true;
193
+ const dx = disc.cx - ring.cx;
194
+ const dy = disc.cy - ring.cy;
195
+ return dx * dx + dy * dy > room * room;
196
+ }
197
+
198
+ /**
199
+ * This function counts the placed circles that go out of a circle container, by the distance of the centers.
200
+ *
201
+ * - The reach of a circle is the sum of the center distance, the radius, the largest side of the margin and the inset.
202
+ * - A circle breaks the rule when its reach is more than the container radius plus `tolerance`.
203
+ * - A container with a free size reads its radius from `w`, and its center is the corner of the shape plus that radius. `applyPack` writes that `w`.
204
+ * - Each other box does not count. The function throws a `RangeError` for a container that is not a circle.
205
+ */
206
+ export function circlesOutside(input: LayoutInput, tolerance: number = DEFAULT_TOLERANCE.overlap): number {
207
+ const c = input.container;
208
+ const ring = c === undefined ? undefined : containerCircle(c);
209
+ if (c === undefined || ring === undefined) throw new RangeError("The function circlesOutside needs a circle container, with w when its size is free.");
210
+ let count = 0;
211
+ for (const box of input.boxes) {
212
+ const disc = placedCircle(box);
213
+ if (disc !== undefined && circleOutside(disc, marginReach(box.margin) + (c.inset ?? 0), ring, tolerance)) count++;
214
+ }
215
+ return count;
216
+ }
217
+
80
218
  /**
81
219
  * This function counts the placed boxes that go out of the container.
82
220
  * Each box with its margin must stay inside the container made smaller by `inset`. Only the fixed sides of the size count. A shaped container counts as its bounding box.
83
221
  *
84
- * With `exactContainer`, a box of a shaped container with the size `fixed` also counts when `rectInRegion` tells that it is not inside the shape.
222
+ * With `exactContainer`, the default, a box of a shaped container with the size `fixed` also counts when it is not inside the shape, by `rectInRegion`.
85
223
  * For that test, the box grows by `inset` and becomes smaller by `tolerance` on each side. A shaped container with a free side keeps the bounding test only.
224
+ * A circle in a circle container does not use `rectInRegion`. It counts by distance, as in `circlesOutside`, also when the size is free.
86
225
  * An input without a container gives 0.
87
226
  */
88
227
  export function countOutside(input: LayoutInput, tolerance: number = DEFAULT_TOLERANCE.overlap, options: ContainerTest = {}): number {
89
228
  const c = input.container;
90
229
  if (c === undefined) return 0;
91
- const shape = options.exactContainer === true && c.fixed === "size" ? c.shape : undefined;
230
+ const exact = options.exactContainer !== false;
231
+ const shape = exact && c.fixed === "size" ? c.shape : undefined;
232
+ const ring = exact ? containerCircle(c) : undefined;
92
233
  const area = c.shape === undefined ? { x: 0, y: 0, w: c.w ?? Infinity, h: c.h ?? Infinity } : boundsOf(c.shape);
93
234
  const inset = c.inset ?? 0;
94
235
  const fixW = c.fixed === "size" || c.fixed === "width";
@@ -100,8 +241,11 @@ export function countOutside(input: LayoutInput, tolerance: number = DEFAULT_TOL
100
241
  const r = grow(r0, box.margin);
101
242
  const outX = r.x < area.x + inset - tolerance || r.x + r.w > area.x + area.w - inset + tolerance;
102
243
  const outY = r.y < area.y + inset - tolerance || r.y + r.h > area.y + area.h - inset + tolerance;
244
+ const disc = ring === undefined ? undefined : placedCircle(box);
103
245
  if ((fixW && outX) || (fixH && outY)) count++;
104
- else if (shape !== undefined && !rectInRegion(shape, shrink(grow(r, inset), tolerance))) count++;
246
+ else if (ring !== undefined && disc !== undefined) {
247
+ if (circleOutside(disc, marginReach(box.margin) + inset, ring, tolerance)) count++;
248
+ } else if (shape !== undefined && !rectInRegion(shape, shrink(grow(r, inset), tolerance))) count++;
105
249
  }
106
250
  return count;
107
251
  }
@@ -131,13 +275,23 @@ export interface PackHard {
131
275
 
132
276
  /**
133
277
  * The hard rules of a pack, with the shape kinds that each rule supports.
134
- * `no-overlap` and `in-container` test the bounding box of a shape. That count is exact only for a `rect`.
135
- * For the other kinds, the count is safe: a shape is inside its bounding box, so the count is an upper bound. A count of 0 tells that the rule has no break.
278
+ * `no-overlap` and `in-container` are exact for a `rect` and a `circle`. `limit` tells the inputs where the count of a circle is only safe (roadmap item L107).
279
+ * For the other kinds, these rules test the bounding box. The count is safe: a shape is inside its bounding box, so the count is an upper bound. A count of 0 tells that the rule has no break.
136
280
  * `locked-kept` and `complete` read only the positions and the ids, so they support each kind.
137
281
  */
138
282
  export const PACK_HARD_RULES: readonly ShapeSupport<keyof PackHard>[] = /* @__PURE__ */ Object.freeze([
139
- { id: "no-overlap", shapes: ["rect"], safe: ["polygon", "circle", "free"] },
140
- { id: "in-container", shapes: ["rect"], safe: ["polygon", "circle", "free"] },
283
+ {
284
+ id: "no-overlap",
285
+ shapes: ["rect", "circle"],
286
+ safe: ["polygon", "free"],
287
+ limit: { reads: "neighbours", because: "A circle beside another shape kind or an obstacle counts by its bounding box.", until: "2026-11-28" },
288
+ },
289
+ {
290
+ id: "in-container",
291
+ shapes: ["rect", "circle"],
292
+ safe: ["polygon", "free"],
293
+ limit: { reads: "container", because: "A circle in a polygon or an ellipse container counts by its bounding box.", until: "2026-11-28" },
294
+ },
141
295
  { id: "locked-kept", shapes: SHAPE_KIND_IDS },
142
296
  { id: "complete", shapes: SHAPE_KIND_IDS },
143
297
  ] as const);
@@ -312,7 +466,7 @@ export function countObstacleHits(
312
466
  /**
313
467
  * This function gives the count of each hard rule of the output of a packer.
314
468
  * It applies the output with `applyPack`. Only the placed boxes and the locked boxes count for the overlaps and the container.
315
- * `no-overlap` counts the pairs of boxes and the pairs of a box and an obstacle. A pair of `pairGaps` uses its gap in place of the margins.
469
+ * `no-overlap` counts the pairs of boxes and the pairs of a box and an obstacle. A pair of `pairGaps` uses its gap in place of the margins. `HARD_RULE_VERSION` tells the version of these counts.
316
470
  *
317
471
  * A locked box without a placement, or with a move of more than `RECORD_EPS`, breaks `locked-kept`.
318
472
  * A locked box without a position in the input is a bad input, not a break. `checkInput` finds it.
package/src/shapes.ts CHANGED
@@ -17,7 +17,7 @@ export interface ShapeGeometry {
17
17
  readonly area: boolean;
18
18
  /** The test that the shape is inside a region: `rectInRegion` for a `rect`. */
19
19
  readonly contains: boolean;
20
- /** The test that two shapes overlap: `overlapOf` for two `rect` shapes. */
20
+ /** The test that two shapes of this kind overlap: `overlapOf` for two `rect` shapes, `shapesOverlap` for two `circle` shapes. */
21
21
  readonly overlap: boolean;
22
22
  }
23
23
 
@@ -33,12 +33,12 @@ export interface ShapeKindSpec {
33
33
 
34
34
  /**
35
35
  * The declared shape kinds, in their order. Only `rect` has all of its geometry.
36
- * `polygon` and `circle` have their bounding box and their exact area. `free` has its bounding box only.
36
+ * `polygon` and `circle` have their bounding box and their exact area. A `circle` also has the overlap test of two circles. `free` has its bounding box only.
37
37
  */
38
38
  export const SHAPE_KINDS: readonly ShapeKindSpec[] = /* @__PURE__ */ Object.freeze([
39
39
  { id: "rect", fields: ["w", "h"], regions: ["rect"], geometry: { bounds: true, area: true, contains: true, overlap: true } },
40
40
  { id: "polygon", fields: ["points", "holes?"], regions: ["polygon"], geometry: { bounds: true, area: true, contains: false, overlap: false } },
41
- { id: "circle", fields: ["cx", "cy", "r"], regions: ["circle"], geometry: { bounds: true, area: true, contains: false, overlap: false } },
41
+ { id: "circle", fields: ["cx", "cy", "r"], regions: ["circle"], geometry: { bounds: true, area: true, contains: false, overlap: true } },
42
42
  { id: "free", fields: ["w", "h", "shape?"], regions: ["rect", "polygon", "circle", "ellipse"], geometry: { bounds: true, area: false, contains: false, overlap: false } },
43
43
  ] as const);
44
44
 
@@ -63,6 +63,22 @@ export interface ShapeSupport<Id extends string = string> {
63
63
  * A kind is in one list only: `shapes`, `safe` or `bound.shapes`. `docs/SHAPES.md` tells what a bound value proves.
64
64
  */
65
65
  readonly bound?: ShapeBound;
66
+ /** The inputs where the exact count of this rule is only safe, with the reason and the date of the fix. `inputShapeLevel` reads it. */
67
+ readonly limit?: ShapeLimit;
68
+ }
69
+
70
+ /**
71
+ * A stated limit of an exact rule on circles. An input that the limit names gets the level `safe` for each kind that is exact.
72
+ *
73
+ * - `neighbours`: the input has a circle beside another shape kind or an obstacle.
74
+ * - `container`: the input has a circle in a container that is a polygon or an ellipse.
75
+ */
76
+ export interface ShapeLimit {
77
+ readonly reads: "neighbours" | "container";
78
+ /** The reason, in words. */
79
+ readonly because: string;
80
+ /** The date of the fix, as `YYYY-MM-DD`. */
81
+ readonly until: string;
66
82
  }
67
83
 
68
84
  /**
@@ -111,14 +127,40 @@ export function shapeLevel(use: Pick<ShapeSupport, "shapes" | "safe" | "bound">,
111
127
  return use.bound?.shapes.includes(kind) === true ? "bound" : "none";
112
128
  }
113
129
 
130
+ /** The parts of an input that `inputShapeLevel` and `checkShapes` read. */
131
+ export type ShapeInput = Pick<LayoutInput, "id" | "boxes"> & Partial<Pick<LayoutInput, "obstacles" | "container">>;
132
+
133
+ /** This function tells if a limit names an input. An input without a circle box is not in a limit. */
134
+ function inLimit(limit: ShapeLimit, input: ShapeInput): boolean {
135
+ const kinds = shapeKindsOf(input);
136
+ if (!kinds.includes("circle")) return false;
137
+ if (limit.reads === "neighbours") return kinds.length > 1 || (input.obstacles?.length ?? 0) > 0;
138
+ const shape = input.container?.shape?.kind;
139
+ return shape === "polygon" || shape === "ellipse";
140
+ }
141
+
142
+ /**
143
+ * This function gives the level of a measure or a rule on a shape kind for one input. It is `shapeLevel` with the `limit` of the rule.
144
+ * When the limit names the input, the level `exact` becomes `safe`. Each other level does not change.
145
+ */
146
+ export function inputShapeLevel(use: Pick<ShapeSupport, "shapes" | "safe" | "bound" | "limit">, kind: ShapeKind, input: ShapeInput): ShapeLevel {
147
+ const level = shapeLevel(use, kind);
148
+ return level === "exact" && use.limit !== undefined && inLimit(use.limit, input) ? "safe" : level;
149
+ }
150
+
114
151
  /**
115
152
  * This function gives the problems of a list of measures and rules. An empty list tells that the list is good.
116
153
  * It refuses an unknown kind, a kind two times in one list, and a kind in more than one of `shapesOf`, `safe` and `bound.shapes`.
117
154
  * It also refuses a `bound` without a list of kinds, and a `side` that is not `upper` or `lower`.
155
+ * It also refuses a `limit` with a bad `reads` or a bad `until`.
118
156
  */
119
157
  export function shapeSupportProblems(uses: readonly ShapeSupport[]): string[] {
120
158
  const out: string[] = [];
121
159
  for (const use of uses) {
160
+ if (use.limit !== undefined) {
161
+ if (use.limit.reads !== "neighbours" && use.limit.reads !== "container") out.push(`${use.id}: the limit reads ${String(use.limit.reads)}, not neighbours or container`);
162
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(String(use.limit.until))) out.push(`${use.id}: the limit date ${String(use.limit.until)} is not YYYY-MM-DD`);
163
+ }
122
164
  const bound: unknown = use.bound;
123
165
  const isBound = typeof bound === "object" && bound !== null && !Array.isArray(bound);
124
166
  if (bound !== undefined && !isBound) out.push(`${use.id}: the bound value is not an object with shapes and a side`);
@@ -222,13 +264,13 @@ export interface ShapeCheck {
222
264
  * By default, a kind of `safe` or of `bound.shapes` is a break, because the result is not exact.
223
265
  * With the level `safe`, a kind of `safe` is not a break. With the level `bound`, a kind of `safe` and a kind of `bound.shapes` are not a break.
224
266
  */
225
- export function checkShapes(input: Pick<LayoutInput, "id" | "boxes">, uses: readonly ShapeSupport[], options: ShapeCheck = {}): ClaimBreak[] {
267
+ export function checkShapes(input: ShapeInput, uses: readonly ShapeSupport[], options: ShapeCheck = {}): ClaimBreak[] {
226
268
  const kinds = shapeKindsOf(input);
227
269
  const out: ClaimBreak[] = [];
228
270
  for (const use of uses) {
229
271
  const shapes = shapesOf(use);
230
272
  for (const kind of kinds) {
231
- const level = shapeLevel(use, kind);
273
+ const level = inputShapeLevel(use, kind, input);
232
274
  const accepts = level === "exact" || (level === "safe" && (options.level === "safe" || options.level === "bound")) || (level === "bound" && options.level === "bound");
233
275
  if (accepts) continue;
234
276
  const ids = input.boxes.filter((b) => shapeKindOf(b) === kind).map((b) => b.id);