@mark1russell7/layout-contract 0.2.19 → 0.2.20

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.
@@ -0,0 +1,560 @@
1
+ /** A side of a box. The y axis points down, so `top` has the smallest y. */
2
+ type Side = "top" | "right" | "bottom" | "left";
3
+ /** The sides in clockwise order, from the top. */
4
+ declare const SIDES: readonly Side[];
5
+ interface Point {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ }
9
+ /** A rectangle: its top-left corner and its size. */
10
+ interface Rect {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ readonly w: number;
14
+ readonly h: number;
15
+ }
16
+ /** A value for each side of a box. */
17
+ interface Sides {
18
+ readonly top: number;
19
+ readonly right: number;
20
+ readonly bottom: number;
21
+ readonly left: number;
22
+ }
23
+ /**
24
+ * A region. The forms and the rules are those of `docs/FORMAT.md` of `packing`.
25
+ * A ring of a polygon closes without a copy of its first point.
26
+ */
27
+ type Region = {
28
+ readonly kind: "rect";
29
+ readonly x: number;
30
+ readonly y: number;
31
+ readonly w: number;
32
+ readonly h: number;
33
+ } | {
34
+ readonly kind: "polygon";
35
+ readonly points: readonly (readonly [number, number])[];
36
+ readonly holes?: readonly (readonly (readonly [number, number])[])[];
37
+ } | {
38
+ readonly kind: "circle";
39
+ readonly cx: number;
40
+ readonly cy: number;
41
+ readonly r: number;
42
+ } | {
43
+ readonly kind: "ellipse";
44
+ readonly cx: number;
45
+ readonly cy: number;
46
+ readonly rx: number;
47
+ readonly ry: number;
48
+ };
49
+ /** A margin: one value for the four sides, or one value for each side. */
50
+ type Margin = number | Sides;
51
+ /** This function gives the value of each side of a margin. No margin gives 0 on each side. */
52
+ declare function marginSides(margin: Margin | undefined): Sides;
53
+ /** This function gives the rectangle made larger by the margin on each side. */
54
+ declare function grow(rect: Rect, margin: Margin | undefined): Rect;
55
+ /** This function gives the bounding box of a region. */
56
+ declare function boundsOf(region: Region): Rect;
57
+ /**
58
+ * This function gives the exact area of a region. A `rect` gives `w` by `h`, a circle gives `PI * r * r`, and an ellipse gives `PI * rx * ry`.
59
+ * A polygon gives the absolute value of the shoelace formula, less the area of each hole. A ring with fewer than 3 points has the area 0.
60
+ */
61
+ declare function regionArea(region: Region): number;
62
+ /** This function gives the region moved by `dx` and `dy`. */
63
+ declare function translate(region: Region, dx: number, dy: number): Region;
64
+ /**
65
+ * This function gives the overlap of the insides of two rectangles on each axis.
66
+ * A value of 0 or less on an axis is no overlap. Two rectangles with a common edge have an overlap of 0.
67
+ */
68
+ declare function overlapOf(a: Rect, b: Rect): {
69
+ readonly x: number;
70
+ readonly y: number;
71
+ };
72
+ /** One broken claim of a corpus, with the ids of the inputs that break it. */
73
+ interface ClaimBreak {
74
+ /** The name of the claim, for example `declared`, `split` or `index`. */
75
+ readonly claim: string;
76
+ /** The text of the break. */
77
+ readonly detail: string;
78
+ /** The ids of the inputs that break the claim. The list is empty when the break has no input. */
79
+ readonly inputs: readonly string[];
80
+ }
81
+ /** The claim `claims.declared` of a manifest: the count of the inputs for each declared property. */
82
+ interface DeclaredClaim {
83
+ /** A property with fewer inputs than this count is thin. */
84
+ readonly minCount: number;
85
+ /** The ids of the properties with a count below `minCount`. */
86
+ readonly thin: readonly string[];
87
+ /** The count of the inputs for each property id. */
88
+ readonly counts: Readonly<Record<string, number>>;
89
+ /** The key of the family of an input. `familyOf` gives the key of one cell. The family is the unit of a verdict. */
90
+ readonly familyBy?: FamilyBy;
91
+ /** The minimum count of the inputs of each family. Without it, `checkDeclared` does not count the families. */
92
+ readonly familyMin?: number;
93
+ }
94
+ /**
95
+ * The key of the family of a cell (`docs/CORPUS-CHECKS.md`).
96
+ *
97
+ * - The flat form is a list of dimensions. The key is the values of these dimensions of the cell, in order, with `/` between them.
98
+ * - The map form chooses an entry by the field `kind` of the cell, or the entry `"*"`. The key is the kind, then the values of the dimensions of the entry.
99
+ */
100
+ type FamilyBy = readonly string[] | {
101
+ readonly [kind: string]: readonly string[];
102
+ };
103
+ /** A cell of an input: one value for each dimension. The map form of `FamilyBy` also reads the field `kind`. */
104
+ type FamilyCell = Readonly<Record<string, unknown>>;
105
+ /** The entry of the map form of `FamilyBy` for each kind without its own entry. */
106
+ declare const FAMILY_ANY_KIND = "*";
107
+ /**
108
+ * This function gives the family key of a cell. It throws a `RangeError` when the cell does not have a dimension of the key.
109
+ * In the map form, it also throws for a cell without `kind`, and for a kind with no entry and no entry `"*"`.
110
+ * For example, `{ "rect-grid": ["obstacles"], "*": [] }` gives `rect-grid/wall` for a `rect-grid` cell and `gallery` for a `gallery` cell.
111
+ */
112
+ declare function familyOf(cell: FamilyCell, familyBy: FamilyBy): string;
113
+ /** The hook that gives the ids of the properties that one input declares. */
114
+ type Declares<I> = (input: I) => readonly string[];
115
+ /**
116
+ * This function gives the count of the inputs for each property id. Each id of `ids` has a count, also when the count is 0.
117
+ * An id from `declares` that is not in `ids` comes after the ids of `ids`, in the order of the first input that declares it.
118
+ */
119
+ declare function declaredCounts<I>(inputs: Iterable<I>, declares: Declares<I>, ids?: readonly string[]): Record<string, number>;
120
+ /**
121
+ * This function reads the field `claims.declared` of a manifest. A manifest without it gives `undefined`.
122
+ * It throws an `Error` for a claim without a whole `minCount`, a list `thin` of ids and a whole count for each id.
123
+ */
124
+ declare function declaredClaimOf(manifest: object): DeclaredClaim | undefined;
125
+ /**
126
+ * This function checks the claim `claims.declared` against the inputs. It gives one break `declared` for each problem. An empty list tells that the claim is true.
127
+ *
128
+ * - `ids` are the property ids. The default is the ids of `claim.counts`.
129
+ * - Each id of `ids` has a count in `claim.counts`, and `claim.counts` has no other id. Each count is the count of the inputs.
130
+ * - An id with a count below `minCount` is in `thin`. Each id of `thin` is an id of `ids`.
131
+ * - Each id that `declares` gives is an id of `ids`.
132
+ *
133
+ * With `claim.familyBy`, the hook `cellOf` gives the cell of each input. The default reads the field `cell` of the input.
134
+ *
135
+ * - Each cell has each dimension of its key. In the map form, each cell has a `kind`, and the kind has an entry or the entry `"*"` is there.
136
+ * - Two cells with different dimension values do not give the same key.
137
+ * - With `claim.familyMin`, each family has `familyMin` inputs or more.
138
+ */
139
+ declare function checkDeclared<I>(inputs: Iterable<I>, declares: Declares<I>, claim: DeclaredClaim, ids?: readonly string[], cellOf?: (input: I) => FamilyCell | undefined): ClaimBreak[];
140
+ /** The id and the hash of one input of a corpus. */
141
+ interface CorpusEntry {
142
+ readonly id: string;
143
+ readonly hash: string;
144
+ }
145
+ /**
146
+ * This function gives the hash of a corpus: the first 16 hex characters of a SHA-256. The text of the SHA-256 is `canonicalJson`
147
+ * of the corpus id and the `[id, hash]` of each input, in the order of the manifest. A change of one input changes the hash.
148
+ */
149
+ declare function corpusHashOf(corpus: string, inputs: readonly CorpusEntry[]): string;
150
+ /** The schema of a split file. */
151
+ declare const SPLIT_SCHEMA = "corpus-split/1";
152
+ /** One fold of a split: the seeds that fit a selector and the seeds that score it. */
153
+ interface SplitFold {
154
+ readonly train: readonly number[];
155
+ readonly heldOut: readonly number[];
156
+ }
157
+ /** A split file `corpus-split/1`. Its name is `<corpus id>.<corpus hash>.json`. It is beside the corpus, so the corpus does not change. */
158
+ interface CorpusSplit {
159
+ readonly schema: typeof SPLIT_SCHEMA;
160
+ readonly corpus: string;
161
+ /** The hash of the corpus: `corpusHashOf` of its manifest. */
162
+ readonly corpusHash: string;
163
+ /** The splits by name. Each split has one fold or more. */
164
+ readonly splits: Readonly<Record<string, {
165
+ readonly folds: readonly SplitFold[];
166
+ }>>;
167
+ }
168
+ /** The fields of a manifest that the split check reads. */
169
+ interface SplitCorpus {
170
+ readonly corpus: string;
171
+ readonly specs: readonly {
172
+ readonly seeds: readonly number[];
173
+ }[];
174
+ readonly inputs: readonly CorpusEntry[];
175
+ }
176
+ /** This function gives the name of the split file of a corpus. */
177
+ declare function splitFileName(corpus: string, hash: string): string;
178
+ /**
179
+ * This function checks a split file against a manifest. It gives one break `split` for each problem. An empty list tells that the file is good.
180
+ *
181
+ * - The schema is `corpus-split/1`, the corpus is the id of the manifest and `corpusHash` is `corpusHashOf` of the manifest.
182
+ * - Each split has one fold or more. In each fold, `train` and `heldOut` are lists of seeds, not empty and with no common seed.
183
+ * - Each seed is a seed of a spec of the manifest.
184
+ * - With `name`, the file has the split `name`.
185
+ */
186
+ declare function checkSplit(split: unknown, corpus: SplitCorpus, name?: string): ClaimBreak[];
187
+ /**
188
+ * This function gives a copy of the folds of the split `name` of a split file. `where` names the file in the text of an error.
189
+ * It throws an `Error` for each problem of `checkSplit`, and then for an unknown split name.
190
+ */
191
+ declare function splitFolds(split: unknown, corpus: SplitCorpus, name: string, where?: string): SplitFold[];
192
+ /** This function gives the folds that hold out one seed each, in the order of the seeds. Each fold trains on the other seeds. */
193
+ declare function leaveOneSeedOut(seeds: readonly number[]): SplitFold[];
194
+ /**
195
+ * A port of a box: a place where edges go into the box.
196
+ * With `x` and `y`, the port is fixed on the border of the box, relative to its top-left corner.
197
+ * With `side` and `along`, the port is fixed at a fraction of its side.
198
+ * With only a side, the router places the port on that side. Without a side, the router picks the side.
199
+ */
200
+ interface Port {
201
+ readonly id: string;
202
+ readonly side?: Side;
203
+ readonly x?: number;
204
+ readonly y?: number;
205
+ /**
206
+ * The place of the port on its `side`: a fraction from 0 to 1, from the start of the side.
207
+ * The start of `left` and `right` is the top end. The start of `top` and `bottom` is the left end.
208
+ * It needs a `side`. A port with `along` has no `x` and no `y`.
209
+ */
210
+ readonly along?: number;
211
+ }
212
+ /**
213
+ * This function gives the point of a port on the border of its box, relative to the top-left corner of the box.
214
+ * A port with `x` and `y` gives that point. A port with `side` and `along` gives the point at that fraction of the side.
215
+ * Another port gives `undefined`, because the router picks its point.
216
+ */
217
+ declare function portPoint(box: Pick<LayoutBox, "w" | "h">, port: Port): Point | undefined;
218
+ /** A box of an input. In the packer, its name is item. */
219
+ interface LayoutBox {
220
+ readonly id: string;
221
+ readonly w: number;
222
+ readonly h: number;
223
+ /** The packer writes the position. The router reads it. */
224
+ readonly x?: number;
225
+ readonly y?: number;
226
+ /** A locked box keeps `x` and `y`. The packer reads it as an obstacle. */
227
+ readonly locked?: boolean;
228
+ /** The reading order. Without it, the order of the array is the rank. */
229
+ readonly rank?: number;
230
+ readonly parent?: string;
231
+ readonly group?: string;
232
+ /** A region relative to the origin of the box. Without it, the box is the rectangle `w` by `h`. */
233
+ readonly shape?: Region;
234
+ /**
235
+ * The shape kind of the box (`docs/SHAPES.md`). Without it, `shapeKindOf` gives the kind of `shape`, or `rect` without a shape.
236
+ * The kind `free` tells that the contract knows only the bounding box `w` by `h`.
237
+ */
238
+ readonly shapeKind?: ShapeKind;
239
+ readonly ports?: readonly Port[];
240
+ /** A ring around the box. No other box enters it. Only a route from a port of the box enters it, at a right angle. */
241
+ readonly margin?: Margin;
242
+ /** The packer can turn the box by 90 degrees. The output has the turned box and ports. */
243
+ readonly turnable?: boolean;
244
+ /** The free data of the node. The grouping rule `keys` of `highways` reads `data.group`. */
245
+ readonly data?: Readonly<Record<string, unknown>>;
246
+ }
247
+ /** The packer name of a box. It is the same type. */
248
+ type Item = LayoutBox;
249
+ /** An edge between two boxes, with optional ports. */
250
+ interface LayoutEdge {
251
+ readonly id: string;
252
+ readonly source: string;
253
+ readonly target: string;
254
+ readonly sourcePort?: string;
255
+ readonly targetPort?: string;
256
+ readonly data?: Readonly<Record<string, unknown>>;
257
+ }
258
+ /** The container. `fixed` tells which sides of the size stay. */
259
+ interface LayoutContainer {
260
+ readonly w?: number;
261
+ readonly h?: number;
262
+ readonly fixed: "size" | "width" | "height" | "none";
263
+ /** The target aspect: the width divided by the height. The default is 1. */
264
+ readonly aspect?: number;
265
+ /** The weight of the aspect error in the objective. 0 gives the least area. The default is 1. */
266
+ readonly aspectWeight?: number;
267
+ /** The shape. Without it, the container is the rectangle from 0, 0 to `w`, `h`. */
268
+ readonly shape?: Region;
269
+ /** The space between the border and the boxes with their margins. */
270
+ readonly inset?: number;
271
+ }
272
+ /** An area that boxes and routes avoid. Without `move`, it stays. With `move`, the packer can move it for `cost` times the distance. */
273
+ interface Obstacle {
274
+ readonly id: string;
275
+ readonly region: Region;
276
+ readonly move?: {
277
+ readonly cost: number;
278
+ };
279
+ }
280
+ /** The generator of an input. The same name, version, parameters and seed give the same file, byte for byte. */
281
+ interface LayoutGenerator {
282
+ readonly name: string;
283
+ readonly version: number;
284
+ readonly params: Readonly<Record<string, unknown>>;
285
+ readonly seed: number;
286
+ }
287
+ /**
288
+ * One minimum distance between two boxes (`a` and `b`). It replaces the two margins of the boxes for this pair, and the global `gap`.
289
+ * The order of `a` and `b` has no meaning. A pair without an entry keeps the margins and the `gap`.
290
+ */
291
+ interface PairGap {
292
+ readonly a: string;
293
+ readonly b: string;
294
+ /** The minimum distance between the two boxes, in units: a finite number of 0 or more. */
295
+ readonly gap: number;
296
+ /** The count of the channels that the gap has space for. It is information only: a whole number of 0 or more. */
297
+ readonly lanes?: number;
298
+ }
299
+ /** The cell of an input in the taxonomy: one value for each dimension. The dimensions are in `docs/FORMAT.md` of `packing`. */
300
+ interface LayoutCell {
301
+ readonly containerSize?: "fixed" | "freeHeight" | "freeWidth" | "freeAspect" | "freeArea";
302
+ readonly containerShape?: "rect" | "convex" | "polygon" | "circle" | "ellipse" | "holes";
303
+ readonly obstacles?: "none" | "center" | "scattered" | "wall" | "corridors" | "touching" | "edge";
304
+ readonly sizes?: "identical" | "uniform" | "heavyTail" | "bimodal" | "extremeAspect" | "nearIdentical";
305
+ readonly count?: "1" | "10" | "100" | "1k" | "10k";
306
+ readonly mode?: "offline" | "online" | "incremental";
307
+ readonly edgeDensity?: "sparse" | "medium" | "dense";
308
+ readonly edgeShape?: "random" | "clustered" | "hubChain" | "longRange" | "tree" | "bundled";
309
+ readonly groups?: "none" | "flat" | "nested";
310
+ readonly ports?: "free" | "sides" | "fixed";
311
+ /** The shape kinds of the boxes: one kind, or `mixed` for more kinds. Without it, each box is a `rect`. `itemShapeOf` gives the value. */
312
+ readonly itemShape?: ShapeKind | "mixed";
313
+ }
314
+ /** An input of the corpus: the format `layout-input/1`. */
315
+ interface LayoutInput {
316
+ readonly schema: "layout-input/1";
317
+ readonly id: string;
318
+ readonly set?: string;
319
+ readonly family?: string;
320
+ readonly seed?: number;
321
+ /** The origin: `made-up`, `published:<set>` or `known-best:<construction>`. */
322
+ readonly source?: string;
323
+ /** The first 16 hex characters of the SHA-256 of the canonical file without this field. */
324
+ readonly hash?: string;
325
+ /** The generator of the input. `null` or no value tells that a person made the input. */
326
+ readonly generator?: LayoutGenerator | null;
327
+ /** The steps that changed the input after its generator, in their order. `edgeStep` adds one. */
328
+ readonly steps?: readonly LayoutGenerator[];
329
+ readonly cell?: LayoutCell;
330
+ /** The place of the input in a sequence of changes. */
331
+ readonly step?: number;
332
+ /** A router input can have no container. */
333
+ readonly container?: LayoutContainer;
334
+ /** The free space between two boxes with their margins. Routes use it. */
335
+ readonly gap?: number;
336
+ /** The distances of some pairs of boxes. An entry replaces the margins and the `gap` for its pair. `canonicalInput` sorts the list. */
337
+ readonly pairGaps?: readonly PairGap[];
338
+ readonly boxes: readonly LayoutBox[];
339
+ readonly edges?: readonly LayoutEdge[];
340
+ readonly obstacles?: readonly Obstacle[];
341
+ /**
342
+ * A variant names its base input and its change.
343
+ * With `packed`, the variant is the packed output of its base input: the router routes the positions of that pack.
344
+ */
345
+ readonly base?: string;
346
+ readonly change?: "add" | "remove" | "resize" | "reorder" | "packed";
347
+ /**
348
+ * The fields that a corpus registry removed, because a dimension value made them wrong (`CorpusDimension.invalidates`).
349
+ * The names are sorted. An input with no removed field has no `invalidated`.
350
+ */
351
+ readonly invalidated?: readonly string[];
352
+ }
353
+ /** The input of a packer: a `layout-input/1` file without the edges. */
354
+ interface PackInput {
355
+ readonly container: LayoutContainer;
356
+ readonly items: readonly Item[];
357
+ readonly obstacles?: readonly Obstacle[];
358
+ readonly gap?: number;
359
+ readonly pairGaps?: readonly PairGap[];
360
+ }
361
+ /** This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size. */
362
+ declare function toPackInput(input: LayoutInput): PackInput;
363
+ /**
364
+ * This function gives the canonical form of an input. `documentHash` uses it for each `layout-input/1` document.
365
+ * Each pair of `pairGaps` gets `a` before `b`, and the list is sorted by `a` and then by `b`.
366
+ * An input without `pairGaps` is the same object, so its hash does not change.
367
+ */
368
+ declare function canonicalInput<T extends LayoutInput>(input: T): T;
369
+ /**
370
+ * The kind of the shape of an item. A box without `shape` and without `shapeKind` is a `rect`.
371
+ * The set is open: a later version can add a kind. A reader treats an unknown kind as a kind that it does not support.
372
+ */
373
+ type ShapeKind = "rect" | "polygon" | "circle" | "free";
374
+ /** The geometry of a shape kind that this package gives. A `false` value tells that the kind declares the operation, but this package does not supply it. */
375
+ interface ShapeGeometry {
376
+ /** The bounding box: `boundsOf` and `placedRect`. */
377
+ readonly bounds: boolean;
378
+ /** The area of the shape: `regionArea` and `boxArea`. */
379
+ readonly area: boolean;
380
+ /** The test that the shape is inside a region: `rectInRegion` for a `rect`. */
381
+ readonly contains: boolean;
382
+ /** The test that two shapes overlap: `overlapOf` for two `rect` shapes. */
383
+ readonly overlap: boolean;
384
+ }
385
+ /** The facts of one shape kind: its fields, the kinds of `Region` that give it, and its geometry. */
386
+ interface ShapeKindSpec {
387
+ readonly id: ShapeKind;
388
+ /** The fields of the outline, relative to the top-left corner of the box. A name with `?` is optional. */
389
+ readonly fields: readonly string[];
390
+ /** The kinds of `LayoutBox.shape` that agree with this kind. */
391
+ readonly regions: readonly Region["kind"][];
392
+ readonly geometry: ShapeGeometry;
393
+ }
394
+ /**
395
+ * The declared shape kinds, in their order. Only `rect` has all of its geometry.
396
+ * `polygon` and `circle` have their bounding box and their exact area. `free` has its bounding box only.
397
+ */
398
+ declare const SHAPE_KINDS: readonly ShapeKindSpec[];
399
+ /** The ids of `SHAPE_KINDS`, in their order. */
400
+ declare const SHAPE_KIND_IDS: readonly ShapeKind[];
401
+ /** The shape kinds of a measure or a rule without `shapes`. The contract measured only rectangles before L46. */
402
+ declare const DEFAULT_SHAPES: readonly ShapeKind[];
403
+ /** A measure or a rule, with the shape kinds that it supports. Without `shapes`, it supports `DEFAULT_SHAPES`. */
404
+ interface ShapeSupport<Id extends string = string> {
405
+ readonly id: Id;
406
+ /** The kinds with an exact count or value. */
407
+ readonly shapes?: readonly ShapeKind[];
408
+ /**
409
+ * The kinds with a safe count: the rule can count a break that is not real, but it does not miss a real break.
410
+ * Thus a safe count of 0 tells that the rule has no break. A kind is in `shapes` or in `safe`, not in the two lists.
411
+ */
412
+ readonly safe?: readonly ShapeKind[];
413
+ /**
414
+ * The kinds where the value of a measure is a bound of the true value, not the exact value. `ShapeBound` tells the side.
415
+ * A kind is in one list only: `shapes`, `safe` or `bound.shapes`. `docs/SHAPES.md` tells what a bound value proves.
416
+ */
417
+ readonly bound?: ShapeBound;
418
+ }
419
+ /**
420
+ * The kinds where a measure gives a bound of the true value, and the side of the bound.
421
+ * With `upper`, the value is the true value or more. With `lower`, the value is the true value or less.
422
+ *
423
+ * @remarks
424
+ * The side and the `direction` of the measure tell what a bound value `v` proves about a threshold `t`.
425
+ * A bound is optimistic on the better side of the true value, and pessimistic on the worse side.
426
+ *
427
+ * | `direction` | `side` | The bound | The proof | No proof |
428
+ * |---|---|---|---|---|
429
+ * | `higher` | `upper` | optimistic | `v < t`: the true value is less than `t`. | `v >= t` |
430
+ * | `higher` | `lower` | pessimistic | `v >= t`: the true value is `t` or more. | `v < t` |
431
+ * | `lower` | `upper` | pessimistic | `v <= t`: the true value is `t` or less. | `v > t` |
432
+ * | `lower` | `lower` | optimistic | `v > t`: the true value is more than `t`. | `v <= t` |
433
+ *
434
+ * For a floor or a guard, a pessimistic bound proves a pass, and an optimistic bound proves a fail.
435
+ * `compareMeasure` on two bound values proves nothing. A tie with a bound value proves nothing.
436
+ * Against an exact baseline, an optimistic candidate proves only `worse`, and a pessimistic candidate proves only `better`.
437
+ */
438
+ interface ShapeBound {
439
+ readonly shapes: readonly ShapeKind[];
440
+ readonly side: "upper" | "lower";
441
+ }
442
+ /** The level of a rule on a shape kind: an exact count, a safe count (an upper bound), or no support. */
443
+ type RuleLevel = "exact" | "safe" | "none";
444
+ /** This function gives the level of a rule on a shape kind. A kind of `shapesOf` is `exact`, a kind of `safe` is `safe`, and another kind is `none`. It does not read `bound`. */
445
+ declare function ruleLevel(rule: Pick<ShapeSupport, "shapes" | "safe">, kind: ShapeKind): RuleLevel;
446
+ /** The level of a measure or a rule on a shape kind. The level `bound` is a value on one side of the true value (`ShapeBound`). */
447
+ type ShapeLevel = RuleLevel | "bound";
448
+ /**
449
+ * This function gives the level of a measure or a rule on a shape kind. It joins the lists `shapes`, `safe` and `bound.shapes`.
450
+ * A kind of `shapesOf` is `exact`, a kind of `safe` is `safe`, a kind of `bound.shapes` is `bound`, and another kind is `none`.
451
+ */
452
+ declare function shapeLevel(use: Pick<ShapeSupport, "shapes" | "safe" | "bound">, kind: ShapeKind): ShapeLevel;
453
+ /**
454
+ * This function gives the problems of a list of measures and rules. An empty list tells that the list is good.
455
+ * 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`.
456
+ * It also refuses a `bound` without a list of kinds, and a `side` that is not `upper` or `lower`.
457
+ */
458
+ declare function shapeSupportProblems(uses: readonly ShapeSupport[]): string[];
459
+ /** This function tells if a value is a declared shape kind. */
460
+ declare function isShapeKind(value: unknown): value is ShapeKind;
461
+ /**
462
+ * This function gives the shape kind of a box. A box with `shapeKind` has that kind.
463
+ * Without it, the kind comes from `shape`: no shape is a `rect`, and an ellipse is `free`.
464
+ */
465
+ declare function shapeKindOf(box: LayoutBox): ShapeKind;
466
+ /**
467
+ * This function gives the exact area of a box, or `undefined` when the contract knows only its bounding box.
468
+ * A box with `shape` gives `regionArea` of the shape. A `rect` box without `shape` gives `w` by `h`.
469
+ * A box of the kind `free` gives `undefined`, also with a shape. Thus a box with an ellipse shape gives `undefined`, because `shapeKindOf` makes an ellipse `free`.
470
+ * A box of another kind without `shape` is a bad input, and gives `undefined`.
471
+ */
472
+ declare function boxArea(box: LayoutBox): number | undefined;
473
+ /** This function gives the shape kinds of the boxes of an input, in the order of `SHAPE_KINDS`. An input without boxes gives an empty list. */
474
+ declare function shapeKindsOf(input: Pick<LayoutInput, "boxes">): ShapeKind[];
475
+ /** This function gives the value of the cell dimension `itemShape` of an input: its one kind, `mixed` for more kinds, or `rect` without boxes. */
476
+ declare function itemShapeOf(input: Pick<LayoutInput, "boxes">): ShapeKind | "mixed";
477
+ /** This function gives the problem of the shape kind of a box, or `undefined` when `shapeKind` and `shape` agree. */
478
+ declare function shapeKindProblem(box: LayoutBox): string | undefined;
479
+ /** This function gives the shape kinds that a measure or a rule supports. */
480
+ declare function shapesOf(use: Pick<ShapeSupport, "shapes">): readonly ShapeKind[];
481
+ /** The options of `checkShapes`. */
482
+ interface ShapeCheck {
483
+ /**
484
+ * The lowest level that `checkShapes` accepts. The default `exact` refuses a kind with only a safe count or a bound value.
485
+ * The value `safe` also accepts a kind of `safe`, as in 0.2.16. Use it only when the run claims that a rule has no break.
486
+ * The value `bound` also accepts a kind of `safe` and a kind of `bound.shapes`. Use it only when the run reads each bound value for the proofs of its side (`docs/SHAPES.md`).
487
+ */
488
+ readonly level?: "exact" | "safe" | "bound";
489
+ }
490
+ /**
491
+ * This function checks that each measure and each rule of a run supports each shape kind of the input. An empty list tells that the run is good.
492
+ * Each break has the claim `shape`, the id of the input, and the first 5 ids of the boxes of the kind.
493
+ * By default, a kind of `safe` or of `bound.shapes` is a break, because the result is not exact.
494
+ * 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.
495
+ */
496
+ declare function checkShapes(input: Pick<LayoutInput, "id" | "boxes">, uses: readonly ShapeSupport[], options?: ShapeCheck): ClaimBreak[];
497
+ /** The direction of a measure: the side of the better values. */
498
+ type Direction = "lower" | "higher";
499
+ /**
500
+ * The facts of one measure: its unit, its direction and its range.
501
+ * `floor` and `tol` are the parameters of the floor rule of the promotion rule (`docs/PROMOTION.md` of `highways`).
502
+ * Each engine exports the specs of its own measures. This package exports the specs of the `joint.*` measures.
503
+ */
504
+ interface MeasureSpec<Id extends string = string> {
505
+ readonly id: Id;
506
+ readonly unit: string;
507
+ readonly direction: Direction;
508
+ /** The lowest value. */
509
+ readonly min: number;
510
+ /** The highest value. The value `Infinity` tells that the measure has no upper limit. */
511
+ readonly max: number;
512
+ /** The family of the measure in the measure note of its engine. */
513
+ readonly family?: string;
514
+ /** The best value. Without it, the measure has no floor. */
515
+ readonly floor?: number;
516
+ /** The absolute tolerance at the floor. */
517
+ readonly tol?: number;
518
+ /**
519
+ * The smallest change that counts as better or worse. A number is an absolute change. `{ rel }` is a share of the larger of the two values.
520
+ * `docs/JOINT-MEASURES.md` gives the reason of each joint value.
521
+ */
522
+ readonly minEffect?: number | {
523
+ readonly rel: number;
524
+ };
525
+ /** The role of the measure in the joint selector. */
526
+ readonly role?: "guard" | "change-guard" | "diagnostic" | "time";
527
+ /** The shape kinds of the boxes that the measure supports. Without it, the measure supports only `rect`. `checkShapes` refuses the other kinds. */
528
+ readonly shapes?: readonly ShapeKind[];
529
+ /**
530
+ * The kinds where the value is a bound of the true value, and its side. A kind is in `shapes` or in `bound.shapes`, not in the two lists.
531
+ * `checkShapes` refuses a bound kind by default and with `{ level: "safe" }`. With `{ level: "bound" }`, it accepts it. `docs/SHAPES.md` tells what a bound value proves for each `direction`.
532
+ */
533
+ readonly bound?: ShapeBound;
534
+ }
535
+ /** The id of a joint measure. `docs/JOINT-MEASURES.md` gives the definitions. */
536
+ type JointMeasureId = "joint.fill" | "joint.aspectError" | "joint.spill" | "joint.straight.crossings" | "joint.straight.length" | "joint.stability.mean" | "joint.stability.moved" | "joint.proxy.rank" | "joint.ms";
537
+ /**
538
+ * The specs of the joint measures, in the order of `docs/JOINT-MEASURES.md`.
539
+ * `joint.fill` and `joint.straight.length` read the area of each box, so they support only `rect`. `docs/SHAPES.md` tells the reasons.
540
+ */
541
+ declare const JOINT_MEASURES: readonly MeasureSpec<JointMeasureId>[];
542
+ /** The threshold of `joint.stability.moved`, in widths `W` of the base. */
543
+ declare const JOINT_MOVED_MIN = .01;
544
+ /** The result of a compare of a candidate with a baseline on one measure. A tie is not better. */
545
+ type Verdict = "better" | "worse" | "tie";
546
+ /**
547
+ * This function gives the smallest change of a measure that counts between the values `a` and `b`.
548
+ * The value is `max(RECORD_EPS, minEffect)`, or `max(RECORD_EPS, rel * max(|a|, |b|))` for a relative `minEffect`.
549
+ * The larger value makes the threshold the same after a swap of `a` and `b`.
550
+ */
551
+ declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: number, b?: number): number;
552
+ /**
553
+ * This function compares the value `candidate` with the value `baseline` of one measure on one input.
554
+ * The compare uses whole grid steps of `RECORD_EPS`. Thus a live value and its rounded record give the same verdict.
555
+ * A change of at most the threshold of `minEffectOf` in grid steps is a tie. A swap of the two values swaps better and worse.
556
+ * Two equal values are a tie, also two infinite values. A value `NaN` is an error.
557
+ */
558
+ declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
559
+ export { SPLIT_SCHEMA as $, shapesOf as A, PairGap as B, itemShapeOf as C, translate as Ct, shapeKindsOf as D, shapeKindProblem as E, LayoutEdge as F, ClaimBreak as G, canonicalInput as H, LayoutGenerator as I, DeclaredClaim as J, CorpusEntry as K, LayoutInput as L, LayoutBox as M, LayoutCell as N, shapeLevel as O, LayoutContainer as P, FamilyCell as Q, Obstacle as R, isShapeKind as S, regionArea as St, shapeKindOf as T, portPoint as U, Port as V, toPackInput as W, FAMILY_ANY_KIND as X, Declares as Y, FamilyBy as Z, ShapeKindSpec as _, Sides as _t, MeasureSpec as a, declaredClaimOf as at, boxArea as b, marginSides as bt, minEffectOf as c, leaveOneSeedOut as ct, SHAPE_KINDS as d, Margin as dt, SplitCorpus as et, SHAPE_KIND_IDS as f, Point as ft, ShapeKind as g, Side as gt, ShapeGeometry as h, SIDES as ht, JointMeasureId as i, corpusHashOf as it, Item as j, shapeSupportProblems as k, DEFAULT_SHAPES as l, splitFileName as lt, ShapeCheck as m, Region as mt, JOINT_MEASURES as n, checkDeclared as nt, Verdict as o, declaredCounts as ot, ShapeBound as p, Rect as pt, CorpusSplit as q, JOINT_MOVED_MIN as r, checkSplit as rt, compareMeasure as s, familyOf as st, Direction as t, SplitFold as tt, RuleLevel as u, splitFolds as ut, ShapeLevel as v, boundsOf as vt, ruleLevel as w, checkShapes as x, overlapOf as xt, ShapeSupport as y, grow as yt, PackInput as z };
560
+ //# sourceMappingURL=measures-CQAuu3T5.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"measures-CQAuu3T5.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;;;UAIM;WACN;WACA;WACA;WACA;;;;;;KAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA;WACA;;WAEA;WAAyB;WAAqB;WAAqB;;WACnE;WAA0B;WAAqB;WAAqB;WAAqB;;;KAG5F,kBAAkB;;iBAGd,YAAY,QAAQ,qBAAqB;;iBAOzC,KAAK,MAAM,MAAM,QAAQ,qBAAqB;;iBAM9C,SAAS,QAAQ,SAAS;;;;;iBA4B1B,WAAW,QAAQ;;iBAyBnB,UAAU,QAAQ,QAAQ,YAAY,aAAa;;;;;iBAoBnD,UAAU,GAAG,MAAM,GAAG;WAAkB;WAAoB;;;UC/H3D;;WAEN;;WAEA;;WAEA;;;UAIM;;WAEN;;WAEA;;WAEA,QAAQ,SAAS;;WAEjB,WAAW;;WAEX;;;;;;;;KASC;;;;KAGA,aAAa,SAAS;;cAGrB;;;;;;iBA4CG,SAAS,MAAM,YAAY,UAAU;;KAazC,SAAS,MAAM,OAAO;;;;;iBAMlB,eAAe,GAAG,QAAQ,SAAS,IAAI,UAAU,SAAS,IAAI,0BAA8B;;;;;iBAa5F,gBAAgB,mBAAmB;;;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