@mark1russell7/layout-contract 0.9.4 → 0.9.6

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.
@@ -57,8 +57,8 @@ type Region = {
57
57
  readonly h: number;
58
58
  } | {
59
59
  readonly kind: "polygon";
60
- readonly points: readonly (readonly [number, number])[];
61
- readonly holes?: readonly (readonly (readonly [number, number])[])[];
60
+ readonly points: Ring;
61
+ readonly holes?: readonly Ring[];
62
62
  } | {
63
63
  readonly kind: "circle";
64
64
  readonly cx: number;
@@ -97,15 +97,28 @@ declare function overlapOf(a: Rect, b: Rect): {
97
97
  /**
98
98
  * This function tells if the segments `ab` and `cd` cross at one point inside both of them.
99
99
  * Segments that only touch at an end, or that are collinear, do not cross. The test has no tolerance.
100
+ * The signs are exact, so an input that is almost collinear gets the correct answer. A coordinate that is not finite gives `false`.
100
101
  */
101
102
  declare function segmentsCross(a: Point, b: Point, c: Point, d: Point): boolean;
102
103
  /**
103
104
  * This function gives the point where the segments `ab` and `cd` cross, or `undefined`.
104
105
  * It gives a point exactly when `segmentsCross` is true, so a touch at an end and collinear segments give `undefined`.
106
+ * The point comes from float cross products. For an input that is almost collinear, the point stays on `ab`.
105
107
  */
106
108
  declare function crossingPoint(a: Point, b: Point, c: Point, d: Point): Point | undefined;
107
109
  /** This function gives the shortest distance from `p` to the segment `ab`. A segment of length 0 is the point `a`. */
108
110
  declare function pointSegmentDistance(p: Point, a: Point, b: Point): number;
111
+ /** A ring of a polygon: its corners in order, as `[x, y]` pairs. The last corner connects to the first. */
112
+ type Ring = readonly (readonly [number, number])[];
113
+ /** This function tells if the point (`x`, `y`) is inside a ring, by the even-odd rule. A ring can be concave. The answer for a point on the border can be each value. */
114
+ declare function pointInRing(x: number, y: number, ring: Ring): boolean;
115
+ /**
116
+ * This function tells if the point (`x`, `y`) is inside a set of rings, by the even-odd rule over all their sides.
117
+ * Thus a point inside the outer ring and inside a hole is out. The answer for a point on a border can be each value.
118
+ */
119
+ declare function pointInRings(x: number, y: number, rings: readonly Ring[]): boolean;
120
+ /** This function gives the distance between the centers of two rectangles. */
121
+ declare function boxCenterDistance(a: Rect, b: Rect): number;
109
122
  /**
110
123
  * This function gives the index at which a point goes among the items of a list on the screen.
111
124
  * The reading order is the rows from top to bottom, and each row from left to right.
@@ -267,6 +280,18 @@ interface Port {
267
280
  * Another port gives `undefined`, because the router picks its point.
268
281
  */
269
282
  declare function portPoint(box: Pick<LayoutBox, "w" | "h">, port: Port): Point | undefined;
283
+ /**
284
+ * The sizes that a packer can give a box. Each bound is in the axes of the box before a turn.
285
+ * A bound that the value does not set is the size of the box. Thus `{ maxW: 300 }` lets the width grow from `w` to 300, and the height stays `h`.
286
+ * With `aspect: "keep"`, the ratio of the width to the height stays the ratio of `w` to `h`. The default is `free`.
287
+ */
288
+ interface Resize {
289
+ readonly minW?: number;
290
+ readonly maxW?: number;
291
+ readonly minH?: number;
292
+ readonly maxH?: number;
293
+ readonly aspect?: "keep" | "free";
294
+ }
270
295
  /** A box of an input. In the packer, its name is item. */
271
296
  interface LayoutBox {
272
297
  readonly id: string;
@@ -293,6 +318,8 @@ interface LayoutBox {
293
318
  readonly margin?: Margin;
294
319
  /** The packer can turn the box by 90 degrees. The output has the turned box and ports. */
295
320
  readonly turnable?: boolean;
321
+ /** The packer can give the box another size in these bounds. The placement has the new size. Only a `rect` box without a shape can have it. */
322
+ readonly resize?: Resize;
296
323
  /** The free data of the node. The grouping rule `keys` of `highways` reads `data.group`. */
297
324
  readonly data?: Readonly<Record<string, unknown>>;
298
325
  }
@@ -657,5 +684,5 @@ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b
657
684
  * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
658
685
  */
659
686
  declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
660
- export { CorpusSplit as $, shapeKindsOf as A, overlapOf as At, LayoutInput as B, checkShapes as C, Sides as Ct, ruleLevel as D, dropIndex as Dt, itemShapeOf as E, crossingPoint as Et, LayoutBox as F, snapRect as Ft, PairGap as G, PackInput as H, LayoutCell as I, toRect as It, packLinks as J, Port as K, LayoutContainer as L, toSizedRect as Lt, shapeSupportProblems as M, regionArea as Mt, shapesOf as N, scaleRect as Nt, shapeKindOf as O, grow as Ot, Item as P, segmentsCross as Pt, CorpusEntry as Q, LayoutEdge as R, translate as Rt, 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, pointSegmentDistance as jt, shapeKindProblem as k, marginSides 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 };
661
- //# sourceMappingURL=measures-B_n_KDMd.d.ts.map
687
+ export { CorpusEntry as $, shapeKindsOf as A, dropIndex as At, LayoutInput as B, snapRect as Bt, checkShapes as C, SIDES as Ct, ruleLevel as D, boundsOf as Dt, itemShapeOf as E, SizedRect as Et, LayoutBox as F, pointInRings as Ft, PairGap as G, PackInput as H, toSizedRect as Ht, LayoutCell as I, pointSegmentDistance as It, canonicalInput as J, Port as K, LayoutContainer as L, regionArea as Lt, shapeSupportProblems as M, marginSides as Mt, shapesOf as N, overlapOf as Nt, shapeKindOf as O, boxCenterDistance as Ot, Item as P, pointInRing as Pt, ClaimBreak as Q, LayoutEdge as R, scaleRect as Rt, boxArea as S, Ring as St, isShapeKind as T, Sides as Tt, PackInputOptions as U, translate as Ut, Obstacle as V, toRect as Vt, PackLink as W, portPoint as X, packLinks as Y, toPackInput as Z, ShapeKind as _, splitFolds as _t, MeasureSpec as a, FamilyCell as at, ShapeLimit as b, Rect as bt, minEffectOf as c, SplitFold as ct, SHAPE_KINDS as d, corpusHashOf as dt, CorpusSplit as et, SHAPE_KIND_IDS as f, declaredClaimOf as ft, ShapeInput as g, splitFileName as gt, ShapeGeometry as h, leaveOneSeedOut as ht, JointMeasureId as i, FamilyBy as it, shapeLevel as j, grow as jt, shapeKindProblem as k, crossingPoint as kt, DEFAULT_SHAPES as l, checkDeclared as lt, ShapeCheck as m, familyOf as mt, JOINT_MEASURES as n, Declares as nt, Verdict as o, SPLIT_SCHEMA as ot, ShapeBound as p, declaredCounts as pt, Resize as q, JOINT_MOVED_MIN as r, FAMILY_ANY_KIND as rt, compareMeasure as s, SplitCorpus as st, Direction as t, DeclaredClaim as tt, RuleLevel as u, checkSplit as ut, ShapeKindSpec as v, Margin as vt, inputShapeLevel as w, Side as wt, ShapeSupport as x, Region as xt, ShapeLevel as y, Point as yt, LayoutGenerator as z, segmentsCross as zt };
688
+ //# sourceMappingURL=measures-Aan-rHz1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measures-Aan-rHz1.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/measures.ts"],"mappings":";KAGY;;cAGC,gBAAgB;UAEZ;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;;;iBAIK,OAAO,MAAM,YAAY;;iBAKzB,YAAY,MAAM,OA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AAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;KAIP;;;;;cAqBC,yBAAyB,YAAY;;cAcrC;;KAGD;;;;;;iBAOI,YAAY,MAAM,KAAK,2BAA2B,YAAO;;;;;;;iBAezD,eAAe,mBAAmB,kBAAkB,MAAM,KAAK,0CAA0C"}
package/build/text.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as MeasureSpec } from "./measures-B_n_KDMd.js";
1
+ import { a as MeasureSpec } from "./measures-Aan-rHz1.js";
2
2
  /**
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.9.4",
4
+ "version": "0.9.6",
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",
@@ -51,7 +51,7 @@
51
51
  "devDependencies": {
52
52
  "@mark1russell7/cue": "^2.1.1",
53
53
  "@types/node": "^26.6.4",
54
- "@vitest/coverage-v8": "5.0.5",
54
+ "@vitest/coverage-v8": "5.1.0",
55
55
  "esbuild": "^0.28.2",
56
56
  "fast-check": "^4.10.2",
57
57
  "layout-contract-0221": "npm:@mark1russell7/layout-contract@0.2.21",
@@ -60,6 +60,7 @@
60
60
  "vitest": "^5.0.3"
61
61
  },
62
62
  "dependencies": {
63
+ "@mark1russell7/predicates": "^0.1.1",
63
64
  "@mark1russell7/rigor-generators": "^0.1.8",
64
65
  "@mark1russell7/rigor-statistics": "^0.1.23",
65
66
  "@mark1russell7/strategy-space": "^0.0.2",
package/src/frame.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // The frames of a layout change (`docs/FRAMES.md`): the record `layout-frame/1`, the frame at a time between two layouts, and the move between two frames.
2
2
  // A frame is a layout at one time of a change. A caller can stop at a frame and start the next layout from it.
3
3
  import type { PlacedBox } from "./balance.ts";
4
+ import { boxCenterDistance } from "./geometry.ts";
4
5
  import type { Placement } from "./output.ts";
5
6
 
6
7
  /** The schema of a frame. */
@@ -141,7 +142,7 @@ export function frameMove(a: LayoutFrame, b: LayoutFrame): number {
141
142
  for (const q of b.boxes) {
142
143
  const p = before.get(q.id);
143
144
  if (p === undefined) continue;
144
- sum += Math.hypot(q.x + q.w / 2 - (p.x + p.w / 2), q.y + q.h / 2 - (p.y + p.h / 2));
145
+ sum += boxCenterDistance(p, q);
145
146
  }
146
147
  return sum;
147
148
  }
package/src/geometry.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { orient2dSign } from "@mark1russell7/predicates";
2
+
1
3
  /** A side of a box. The y axis points down, so `top` has the smallest y. */
2
4
  export type Side = "top" | "right" | "bottom" | "left";
3
5
 
@@ -77,8 +79,8 @@ export type Region =
77
79
  | { readonly kind: "rect"; readonly x: number; readonly y: number; readonly w: number; readonly h: number }
78
80
  | {
79
81
  readonly kind: "polygon";
80
- readonly points: readonly (readonly [number, number])[];
81
- readonly holes?: readonly (readonly (readonly [number, number])[])[];
82
+ readonly points: Ring;
83
+ readonly holes?: readonly Ring[];
82
84
  }
83
85
  | { readonly kind: "circle"; readonly cx: number; readonly cy: number; readonly r: number }
84
86
  | { readonly kind: "ellipse"; readonly cx: number; readonly cy: number; readonly rx: number; readonly ry: number };
@@ -185,27 +187,36 @@ function orient(a: Point, b: Point, c: Point): number {
185
187
  return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
186
188
  }
187
189
 
188
- /** This function tells if two numbers have opposite signs. Zero and NaN give false, so a touch at an end does not count. */
189
- function opposite(p: number, q: number): boolean {
190
- return (p < 0 && q > 0) || (p > 0 && q < 0);
190
+ /** This function gives the exact sign of the cross product of `ab` and `ac`, from `orient2dSign` of `@mark1russell7/predicates`. */
191
+ function side(a: Point, b: Point, c: Point): number {
192
+ return orient2dSign(a.x, a.y, b.x, b.y, c.x, c.y);
193
+ }
194
+
195
+ /** This function tells if each coordinate of the points is finite. */
196
+ function allFinite(...points: readonly Point[]): boolean {
197
+ return points.every((p) => Number.isFinite(p.x) && Number.isFinite(p.y));
191
198
  }
192
199
 
193
200
  /**
194
201
  * This function tells if the segments `ab` and `cd` cross at one point inside both of them.
195
202
  * Segments that only touch at an end, or that are collinear, do not cross. The test has no tolerance.
203
+ * The signs are exact, so an input that is almost collinear gets the correct answer. A coordinate that is not finite gives `false`.
196
204
  */
197
205
  export function segmentsCross(a: Point, b: Point, c: Point, d: Point): boolean {
198
- return opposite(orient(c, d, a), orient(c, d, b)) && opposite(orient(a, b, c), orient(a, b, d));
206
+ if (!allFinite(a, b, c, d)) return false;
207
+ return side(c, d, a) * side(c, d, b) === -1 && side(a, b, c) * side(a, b, d) === -1;
199
208
  }
200
209
 
201
210
  /**
202
211
  * This function gives the point where the segments `ab` and `cd` cross, or `undefined`.
203
212
  * It gives a point exactly when `segmentsCross` is true, so a touch at an end and collinear segments give `undefined`.
213
+ * The point comes from float cross products. For an input that is almost collinear, the point stays on `ab`.
204
214
  */
205
215
  export function crossingPoint(a: Point, b: Point, c: Point, d: Point): Point | undefined {
206
216
  if (!segmentsCross(a, b, c, d)) return undefined;
207
217
  const from = orient(c, d, a);
208
- const t = from / (from - orient(c, d, b));
218
+ const r = from / (from - orient(c, d, b));
219
+ const t = Number.isNaN(r) ? 0.5 : Math.min(1, Math.max(0, r));
209
220
  return { x: a.x + t * (b.x - a.x), y: a.y + t * (b.y - a.y) };
210
221
  }
211
222
 
@@ -218,6 +229,35 @@ export function pointSegmentDistance(p: Point, a: Point, b: Point): number {
218
229
  return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
219
230
  }
220
231
 
232
+ /** A ring of a polygon: its corners in order, as `[x, y]` pairs. The last corner connects to the first. */
233
+ export type Ring = readonly (readonly [number, number])[];
234
+
235
+ /** This function tells if the point (`x`, `y`) is inside a ring, by the even-odd rule. A ring can be concave. The answer for a point on the border can be each value. */
236
+ export function pointInRing(x: number, y: number, ring: Ring): boolean {
237
+ return pointInRings(x, y, [ring]);
238
+ }
239
+
240
+ /**
241
+ * This function tells if the point (`x`, `y`) is inside a set of rings, by the even-odd rule over all their sides.
242
+ * Thus a point inside the outer ring and inside a hole is out. The answer for a point on a border can be each value.
243
+ */
244
+ export function pointInRings(x: number, y: number, rings: readonly Ring[]): boolean {
245
+ let inside = false;
246
+ for (const ring of rings) {
247
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
248
+ const [xi, yi] = ring[i]!;
249
+ const [xj, yj] = ring[j]!;
250
+ if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
251
+ }
252
+ }
253
+ return inside;
254
+ }
255
+
256
+ /** This function gives the distance between the centers of two rectangles. */
257
+ export function boxCenterDistance(a: Rect, b: Rect): number {
258
+ return Math.hypot(b.x + b.w / 2 - (a.x + a.w / 2), b.y + b.h / 2 - (a.y + a.h / 2));
259
+ }
260
+
221
261
  /**
222
262
  * This function gives the index at which a point goes among the items of a list on the screen.
223
263
  * The reading order is the rows from top to bottom, and each row from left to right.
package/src/hash.ts CHANGED
@@ -95,13 +95,17 @@ function byId(a: { readonly id: string }, b: { readonly id: string }): number {
95
95
  * The placements, the moved obstacles and the overflow are in the order of their ids. A placement without `turn` gets `turn: 0`.
96
96
  * Thus two packers with the same result in a different order have the same form.
97
97
  * The function throws a `RangeError` when `placements`, `overflow` or `moved` has an id two times.
98
+ *
99
+ * A placement has `w` and `h` only when the packer set them, so the form of an output without a resize does not change.
98
100
  */
99
101
  export function packOutputForm(output: PackOutput): unknown {
100
102
  uniqueIds("placements", output.placements.map((p) => p.id));
101
103
  uniqueIds("overflow", output.overflow);
102
104
  uniqueIds("moved", output.moved.map((m) => m.id));
103
105
  return {
104
- placements: output.placements.map((p) => ({ id: p.id, x: p.x, y: p.y, turn: p.turn ?? 0 })).sort(byId),
106
+ placements: output.placements
107
+ .map((p) => ({ id: p.id, x: p.x, y: p.y, turn: p.turn ?? 0, ...(p.w === undefined ? {} : { w: p.w }), ...(p.h === undefined ? {} : { h: p.h }) }))
108
+ .sort(byId),
105
109
  overflow: [...output.overflow].sort(),
106
110
  size: { w: output.size.w, h: output.size.h },
107
111
  moved: output.moved.map((m) => ({ id: m.id, x: m.x, y: m.y })).sort(byId),
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./output.ts";
6
6
  export * from "./record.ts";
7
7
  export * from "./rules.ts";
8
8
  export * from "./turn.ts";
9
+ export * from "./resize.ts";
9
10
  export * from "./measures.ts";
10
11
  export * from "./balance.ts";
11
12
  export * from "./frame.ts";
package/src/input.ts CHANGED
@@ -40,6 +40,19 @@ export function portPoint(box: Pick<LayoutBox, "w" | "h">, port: Port): Point |
40
40
  }
41
41
  }
42
42
 
43
+ /**
44
+ * The sizes that a packer can give a box. Each bound is in the axes of the box before a turn.
45
+ * A bound that the value does not set is the size of the box. Thus `{ maxW: 300 }` lets the width grow from `w` to 300, and the height stays `h`.
46
+ * With `aspect: "keep"`, the ratio of the width to the height stays the ratio of `w` to `h`. The default is `free`.
47
+ */
48
+ export interface Resize {
49
+ readonly minW?: number;
50
+ readonly maxW?: number;
51
+ readonly minH?: number;
52
+ readonly maxH?: number;
53
+ readonly aspect?: "keep" | "free";
54
+ }
55
+
43
56
  /** A box of an input. In the packer, its name is item. */
44
57
  export interface LayoutBox {
45
58
  readonly id: string;
@@ -66,6 +79,8 @@ export interface LayoutBox {
66
79
  readonly margin?: Margin;
67
80
  /** The packer can turn the box by 90 degrees. The output has the turned box and ports. */
68
81
  readonly turnable?: boolean;
82
+ /** The packer can give the box another size in these bounds. The placement has the new size. Only a `rect` box without a shape can have it. */
83
+ readonly resize?: Resize;
69
84
  /** The free data of the node. The grouping rule `keys` of `highways` reads `data.group`. */
70
85
  readonly data?: Readonly<Record<string, unknown>>;
71
86
  }
package/src/output.ts CHANGED
@@ -1,13 +1,19 @@
1
1
  import { boundsOf, translate } from "./geometry.ts";
2
2
  import type { LayoutInput } from "./input.ts";
3
+ import { resizeBox } from "./resize.ts";
3
4
  import { turnBox } from "./turn.ts";
4
5
 
5
- /** The position of one item. `turn` is 90 when the packer turned a turnable item. */
6
+ /**
7
+ * The position of one item. `turn` is 90 when the packer turned a turnable item.
8
+ * `w` and `h` are the size of the placed item after the turn, when the packer resized an item with `resize`. Without them, the item keeps its size.
9
+ */
6
10
  export interface Placement {
7
11
  readonly id: string;
8
12
  readonly x: number;
9
13
  readonly y: number;
10
14
  readonly turn?: 0 | 90;
15
+ readonly w?: number;
16
+ readonly h?: number;
11
17
  }
12
18
 
13
19
  /** The facts of one stage of a strategy, for the records and the site. */
@@ -33,6 +39,8 @@ export interface PackOutput {
33
39
  * This function gives the input with the output of a packer applied. Each placed box gets its position.
34
40
  * A turned box gets its turned size, ports, margin and shape. Each moved obstacle moves.
35
41
  * The container gets the size of the output. The router reads this result. It does not read `turn`.
42
+ *
43
+ * A placement with `w` or `h` gives the box that size after the turn (`resizeBox`).
36
44
  */
37
45
  export function applyPack(input: LayoutInput, output: PackOutput): LayoutInput {
38
46
  const at = new Map(output.placements.map((p) => [p.id, p]));
@@ -41,7 +49,8 @@ export function applyPack(input: LayoutInput, output: PackOutput): LayoutInput {
41
49
  const p = at.get(box.id);
42
50
  if (p === undefined) return box;
43
51
  const turned = p.turn === 90 ? turnBox(box) : box;
44
- return { ...turned, x: p.x, y: p.y };
52
+ const sized = p.w === undefined && p.h === undefined ? turned : resizeBox(turned, p.w ?? turned.w, p.h ?? turned.h);
53
+ return { ...sized, x: p.x, y: p.y };
45
54
  });
46
55
  const obstacles = input.obstacles?.map((o) => {
47
56
  const m = moved.get(o.id);
package/src/record.ts CHANGED
@@ -88,6 +88,23 @@ export interface Carried {
88
88
  readonly fingerprints: Readonly<Record<string, string>>;
89
89
  /** The id of the run that measured the record. */
90
90
  readonly run?: string;
91
+ /** The facts of a change of the measure code between the measure and the run that keeps the record. Without the field, the measure code did not change. */
92
+ readonly code?: CarriedCode;
93
+ }
94
+
95
+ /**
96
+ * The facts of a carry over a change of the measure code (L147 rule B). A run kept the record because a code audit gave no difference.
97
+ * Such a record is a bridge only: the next full run at the commit `to` or later measures it again.
98
+ */
99
+ export interface CarriedCode {
100
+ /** The commit of the measure code of the record. A record that a run carried before keeps this commit. */
101
+ readonly from: string;
102
+ /** The commit of the run that keeps the record. */
103
+ readonly to: string;
104
+ /** The count of the pairs of the code audit. Each pair had the same record, without the times, at the two commits. */
105
+ readonly audit: number;
106
+ /** The 95 % upper bound of the rate of a difference, from 0 differences in `audit` pairs (the Wilson interval). It is above 0 and not above 1. */
107
+ readonly upper: number;
91
108
  }
92
109
 
93
110
  /**
@@ -159,18 +176,32 @@ function numberMap(out: string[], v: unknown, name: string): void {
159
176
  /** This function tells if a value is an object whose values are strings. */
160
177
  const isStringMap = (v: unknown): v is Readonly<Record<string, string>> => isFields(v) && Object.values(v).every((s) => typeof s === "string");
161
178
 
179
+ /** This function gives the problems of the field `carried.code` of a record. */
180
+ function codeProblems(code: unknown): string[] {
181
+ if (!isFields(code)) return ["carried.code is not an object"];
182
+ const out: string[] = [];
183
+ for (const key of ["from", "to"] as const) if (typeof code[key] !== "string" || code[key] === "") out.push(`carried.code.${key} is not a commit`);
184
+ if (out.length === 0 && code["from"] === code["to"]) out.push("carried.code.to is the commit of carried.code.from");
185
+ if (!Number.isInteger(code["audit"]) || (code["audit"] as number) < 1) out.push("carried.code.audit is not a count of 1 or more");
186
+ const upper = code["upper"];
187
+ if (typeof upper !== "number" || !(upper > 0 && upper <= 1)) out.push("carried.code.upper is not above 0 and at most 1");
188
+ return out;
189
+ }
190
+
162
191
  /** This function gives the problems of the field `carried` of a record. */
163
192
  function carriedProblems(carried: unknown): string[] {
164
193
  if (!isFields(carried)) return ["carried is not an object"];
165
194
  const out: string[] = [];
166
195
  for (const key of ["from", "to", "fingerprints"] as const) if (!isStringMap(carried[key])) out.push(`carried.${key} is not a map of strings`);
167
196
  if (carried["run"] !== undefined && typeof carried["run"] !== "string") out.push("carried.run is not a string");
197
+ if (carried["code"] !== undefined) out.push(...codeProblems(carried["code"]));
168
198
  if (out.length > 0) return out;
169
199
  const from = carried["from"] as Readonly<Record<string, string>>;
170
200
  const to = carried["to"] as Readonly<Record<string, string>>;
171
201
  const names = (m: Readonly<Record<string, string>>): string => Object.keys(m).sort().join(",");
172
202
  if (names(from) === "" || names(from) !== names(to)) out.push("carried.from and carried.to do not name the same engines");
173
- else if (Object.keys(from).every((name) => from[name] === to[name])) out.push("carried.to has no other version than carried.from");
203
+ // A carry over a change of the measure code can keep the engine versions. Each other carry needs a change of a version.
204
+ else if (carried["code"] === undefined && Object.keys(from).every((name) => from[name] === to[name])) out.push("carried.to has no other version than carried.from");
174
205
  if (Object.keys(carried["fingerprints"] as object).length === 0) out.push("carried.fingerprints is empty");
175
206
  return out;
176
207
  }
@@ -254,10 +285,16 @@ export interface CarryFacts {
254
285
  readonly from?: Readonly<Record<string, string>>;
255
286
  /** The id of the run that measured the record. A record that a run carried before keeps its `carried.run`. */
256
287
  readonly run?: string;
288
+ /**
289
+ * The facts of a change of the measure code, for a carry over such a change. A record with `carried.code` keeps its `carried.code.from`.
290
+ * Without this value, a record keeps its `carried.code`.
291
+ */
292
+ readonly code?: CarriedCode;
257
293
  }
258
294
 
259
295
  /**
260
296
  * This function gives a record that a run keeps after an engine release, with the field `carried` (L147).
297
+ * With `facts.code`, the run keeps the record over a change of the measure code. Then the engine versions can be the same.
261
298
  * A record that a run carried before keeps the versions and the run of its measure, so `carried.from` always names the measure.
262
299
  * The function throws a `RangeError` for a skipped record: a skip makes no claim on an output, so the run measures the pair again.
263
300
  * It also throws a `RangeError` when `checkLayoutRecord` refuses the field `carried` of the result.
@@ -267,7 +304,9 @@ export function carryRecord(record: LayoutRecord, facts: CarryFacts): LayoutReco
267
304
  const from = record.carried?.from ?? facts.from;
268
305
  if (from === undefined) throw new RangeError(`The record of ${record.strategy} on ${record.input} has no carried.from, so the carry needs from.`);
269
306
  const run = record.carried?.run ?? facts.run;
270
- const carried: Carried = { from, to: facts.to, fingerprints: facts.fingerprints, ...(run === undefined ? {} : { run }) };
307
+ const before = record.carried?.code;
308
+ const code = facts.code === undefined ? before : { ...facts.code, from: before?.from ?? facts.code.from };
309
+ const carried: Carried = { from, to: facts.to, fingerprints: facts.fingerprints, ...(run === undefined ? {} : { run }), ...(code === undefined ? {} : { code }) };
271
310
  const problems = carriedProblems(carried);
272
311
  if (problems.length > 0) throw new RangeError(`The carry of ${record.strategy} on ${record.input} is bad: ${problems.join(", ")}.`);
273
312
  return { ...record, carried };
package/src/resize.ts ADDED
@@ -0,0 +1,92 @@
1
+ // The resize of a box (`LayoutBox.resize`): the sizes that a packer can give a box, and the box at a new size.
2
+ import type { LayoutBox, Port } from "./input.ts";
3
+ import { shapeKindOf } from "./shapes.ts";
4
+ import { RECORD_EPS } from "./tolerance.ts";
5
+
6
+ /** The bounds of the size of a box, with each value set. */
7
+ export interface SizeBounds {
8
+ readonly minW: number;
9
+ readonly maxW: number;
10
+ readonly minH: number;
11
+ readonly maxH: number;
12
+ /** With `keep`, the ratio of the width to the height stays the ratio of `w` to `h` of the box. */
13
+ readonly aspect: "keep" | "free";
14
+ }
15
+
16
+ /** The names of the bounds of a resize. */
17
+ const BOUNDS = ["minW", "maxW", "minH", "maxH"] as const;
18
+
19
+ /**
20
+ * This function gives the bounds of the size of a box. A bound that `resize` does not set is the size of the box.
21
+ * A box without `resize` gives the bounds of its own size, so it keeps its size.
22
+ */
23
+ export function sizeBoundsOf(box: LayoutBox): SizeBounds {
24
+ const r = box.resize;
25
+ return {
26
+ minW: r?.minW ?? box.w,
27
+ maxW: r?.maxW ?? box.w,
28
+ minH: r?.minH ?? box.h,
29
+ maxH: r?.maxH ?? box.h,
30
+ aspect: r?.aspect ?? "free",
31
+ };
32
+ }
33
+
34
+ /**
35
+ * This function tells if a size is in the bounds of a box, with the tolerance `RECORD_EPS` of the records.
36
+ * With the aspect `keep`, the ratio of `w` to `h` also stays the ratio of the box, in the same tolerance.
37
+ * A size that is not positive and finite is not in the bounds.
38
+ */
39
+ export function sizeFits(box: LayoutBox, w: number, h: number): boolean {
40
+ if (!(w > 0 && h > 0 && Number.isFinite(w) && Number.isFinite(h))) return false;
41
+ const b = sizeBoundsOf(box);
42
+ if (w < b.minW - RECORD_EPS || w > b.maxW + RECORD_EPS || h < b.minH - RECORD_EPS || h > b.maxH + RECORD_EPS) return false;
43
+ // A grid step of RECORD_EPS on w and h moves w * box.h - h * box.w by up to RECORD_EPS * (box.w + box.h).
44
+ return b.aspect === "free" || Math.abs(w * box.h - h * box.w) <= RECORD_EPS * (box.w + box.h);
45
+ }
46
+
47
+ /** This function gives a port of a box of the size `w` by `h` after a resize to `toW` by `toH`. A port with `along` keeps its value. */
48
+ function resizePort(port: Port, w: number, h: number, toW: number, toH: number): Port {
49
+ return {
50
+ ...port,
51
+ ...(port.x === undefined ? {} : { x: (port.x * toW) / w }),
52
+ ...(port.y === undefined ? {} : { y: (port.y * toH) / h }),
53
+ };
54
+ }
55
+
56
+ /**
57
+ * This function gives a box at the size `w` by `h`. The position, the margin and the other fields stay.
58
+ * A port with `x` or `y` moves with the scale of its axis. A port with `along` keeps its place on its side.
59
+ * The function does not test the bounds: `sizeFits` does. A box with a shape is a bad input for a resize (`resizeProblems`).
60
+ */
61
+ export function resizeBox(box: LayoutBox, w: number, h: number): LayoutBox {
62
+ if (w === box.w && h === box.h) return box;
63
+ return {
64
+ ...box,
65
+ w,
66
+ h,
67
+ ...(box.ports === undefined ? {} : { ports: box.ports.map((p) => resizePort(p, box.w, box.h, w, h)) }),
68
+ };
69
+ }
70
+
71
+ /**
72
+ * This function gives the problems of the `resize` of a box. A box without `resize` has no problem.
73
+ * Only a `rect` box without a shape can have a resize. Each bound is a positive finite number.
74
+ * The size of the box is in its bounds, and `aspect` is `keep` or `free`.
75
+ */
76
+ export function resizeProblems(box: LayoutBox): string[] {
77
+ const r = box.resize;
78
+ if (r === undefined) return [];
79
+ const at = `box ${box.id}`;
80
+ if (typeof r !== "object" || r === null) return [`${at}: the resize is not an object`];
81
+ const problems: string[] = [];
82
+ if (box.shape !== undefined || shapeKindOf(box) !== "rect") problems.push(`${at}: only a rect box without a shape can have a resize`);
83
+ for (const k of BOUNDS) {
84
+ const v = r[k];
85
+ if (v !== undefined && !(typeof v === "number" && v > 0 && Number.isFinite(v))) problems.push(`${at}: the resize bound ${k} ${String(v)} is not positive and finite`);
86
+ }
87
+ if (r.aspect !== undefined && r.aspect !== "keep" && r.aspect !== "free") problems.push(`${at}: the resize aspect ${String(r.aspect)} is not keep or free`);
88
+ const b = sizeBoundsOf(box);
89
+ if (!(b.minW <= box.w && box.w <= b.maxW)) problems.push(`${at}: the width ${box.w} is not in the resize bounds ${b.minW} to ${b.maxW}`);
90
+ if (!(b.minH <= box.h && box.h <= b.maxH)) problems.push(`${at}: the height ${box.h} is not in the resize bounds ${b.minH} to ${b.maxH}`);
91
+ return problems;
92
+ }
package/src/rules.ts CHANGED
@@ -1,8 +1,10 @@
1
- import { boundsOf, grow, marginSides, overlapOf, type Margin, type Point, type Rect, type Region } from "./geometry.ts";
1
+ import { boundsOf, grow, marginSides, overlapOf, pointInRings, type Margin, type Point, type Rect, type Region } from "./geometry.ts";
2
2
  import type { LayoutBox, LayoutContainer, LayoutInput, Obstacle, PairGap, Port } from "./input.ts";
3
3
  import { applyPack, type PackOutput } from "./output.ts";
4
+ import { resizeProblems, sizeFits } from "./resize.ts";
4
5
  import { SHAPE_KIND_IDS, shapeKindProblem, type ShapeSupport } from "./shapes.ts";
5
6
  import { DEFAULT_TOLERANCE, EPS, RECORD_EPS } from "./tolerance.ts";
7
+ import { turnBox } from "./turn.ts";
6
8
 
7
9
  /** This function gives the area of a placed box: its shape or its rectangle, at its position. A box without a position gives `undefined`. */
8
10
  export function placedRect(box: LayoutBox): Rect | undefined {
@@ -374,6 +376,11 @@ export interface PackHard {
374
376
  readonly "in-container": number;
375
377
  readonly "locked-kept": number;
376
378
  readonly complete: number;
379
+ /**
380
+ * The count of the placements whose size is not in the bounds of their box (`countResizeBreaks`).
381
+ * `packHard` gives it only when a box of the input has `resize` or a placement has `w` or `h`. Thus the counts of the other inputs do not change.
382
+ */
383
+ readonly "size-kept"?: number;
377
384
  }
378
385
 
379
386
  /**
@@ -532,19 +539,6 @@ function clipMid(ax: number, ay: number, bx: number, by: number, r: Rect): reado
532
539
  return [ax + t * dx, ay + t * dy];
533
540
  }
534
541
 
535
- /** The even-odd rule over the outer ring and the holes. */
536
- function pointInRings(x: number, y: number, rings: readonly (readonly (readonly [number, number])[])[]): boolean {
537
- let inside = false;
538
- for (const ring of rings) {
539
- for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
540
- const [xi, yi] = ring[i]!;
541
- const [xj, yj] = ring[j]!;
542
- if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
543
- }
544
- }
545
- return inside;
546
- }
547
-
548
542
  /**
549
543
  * This function counts the pairs of a placed box and an obstacle that overlap by more than `tolerance`.
550
544
  * The box counts with its margin. A box with a shape counts as its bounding box.
@@ -566,6 +560,24 @@ export function countObstacleHits(
566
560
  return count;
567
561
  }
568
562
 
563
+ /**
564
+ * This function gives the count of the placements whose size is not in the bounds of their box (`sizeFits`).
565
+ * The bounds are in the axes of the placed box: a turned box has the turned bounds. A placement without `w` or `h` keeps that size of the box.
566
+ * A placement of an id that is not in the input does not count.
567
+ */
568
+ export function countResizeBreaks(input: LayoutInput, output: PackOutput): number {
569
+ const was = new Map(input.boxes.map((b) => [b.id, b]));
570
+ let count = 0;
571
+ for (const p of output.placements) {
572
+ if (p.w === undefined && p.h === undefined) continue;
573
+ const box = was.get(p.id);
574
+ if (box === undefined) continue;
575
+ const placed = p.turn === 90 ? turnBox(box) : box;
576
+ if (!sizeFits(placed, p.w ?? placed.w, p.h ?? placed.h)) count++;
577
+ }
578
+ return count;
579
+ }
580
+
569
581
  /**
570
582
  * This function gives the count of each hard rule of the output of a packer.
571
583
  * It applies the output with `applyPack`. Only the placed boxes and the locked boxes count for the overlaps and the container.
@@ -574,6 +586,7 @@ export function countObstacleHits(
574
586
  * A locked box without a placement, or with a move of more than `RECORD_EPS`, breaks `locked-kept`.
575
587
  * A locked box without a position in the input is a bad input, not a break. `checkInput` finds it.
576
588
  * Another box without a placement that is not in `overflow` breaks `complete`.
589
+ * `size-kept` is in the result only when a box has `resize` or a placement has `w` or `h` (`countResizeBreaks`).
577
590
  *
578
591
  * `options` goes to `countOutside` for `in-container`.
579
592
  */
@@ -603,14 +616,22 @@ export function packHard(input: LayoutInput, output: PackOutput, tolerance: numb
603
616
  "in-container": countOutside({ ...after, boxes: kept }, tolerance, options),
604
617
  "locked-kept": lockedMoved,
605
618
  complete: incomplete,
619
+ ...(resizes(input, output) ? { "size-kept": countResizeBreaks(input, output) } : {}),
606
620
  };
607
621
  }
608
622
 
623
+ /** This function tells if a box of the input has `resize` or a placement of the output has `w` or `h`. */
624
+ function resizes(input: LayoutInput, output: PackOutput): boolean {
625
+ return input.boxes.some((b) => b.resize !== undefined) || output.placements.some((p) => p.w !== undefined || p.h !== undefined);
626
+ }
627
+
609
628
  /**
610
629
  * This function gives the problems of an input file. An empty list tells that the file is good.
611
630
  * A problem is a bad input, not a break of a hard rule. Thus an engine refuses the input.
612
631
  * In `pairGaps`, an unknown box, a pair of one box, a repeated pair in either order, a bad `gap` and bad `lanes` are problems.
613
632
  * A port with `along` and no `side`, with `x` or `y`, or with a value outside [0, 1] is a problem.
633
+ *
634
+ * A bad `resize` is a problem (`resizeProblems`).
614
635
  */
615
636
  export function checkInput(input: LayoutInput): readonly string[] {
616
637
  const problems: string[] = [];
@@ -623,6 +644,7 @@ export function checkInput(input: LayoutInput): readonly string[] {
623
644
  const shape = shapeKindProblem(box);
624
645
  if (shape !== undefined) problems.push(shape);
625
646
  for (const port of box.ports ?? []) problems.push(...alongProblems(box.id, port));
647
+ problems.push(...resizeProblems(box));
626
648
  }
627
649
  if (countPortsOffBorder(input.boxes) > 0) problems.push("a fixed port is not on the border of its box");
628
650
  for (const edge of input.edges ?? []) {