@mark1russell7/layout-contract 0.2.12 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/build/index.d.ts +475 -150
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1022 -40
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/families.ts +618 -0
- package/src/hash.ts +4 -2
- package/src/index.ts +2 -0
- package/src/input.ts +41 -0
- package/src/measures.ts +21 -10
- package/src/record.ts +11 -2
- package/src/rules.ts +84 -9
- package/src/shapes.ts +119 -0
- package/src/strategy-space.ts +177 -19
package/build/index.d.ts
CHANGED
|
@@ -64,33 +64,128 @@ export declare function overlapOf(a: Rect, b: Rect): {
|
|
|
64
64
|
readonly x: number;
|
|
65
65
|
readonly y: number;
|
|
66
66
|
};
|
|
67
|
-
/**
|
|
68
|
-
export
|
|
67
|
+
/** One broken claim of a corpus, with the ids of the inputs that break it. */
|
|
68
|
+
export interface ClaimBreak {
|
|
69
|
+
/** The name of the claim, for example `declared`, `split` or `index`. */
|
|
70
|
+
readonly claim: string;
|
|
71
|
+
/** The text of the break. */
|
|
72
|
+
readonly detail: string;
|
|
73
|
+
/** The ids of the inputs that break the claim. The list is empty when the break has no input. */
|
|
74
|
+
readonly inputs: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
/** The claim `claims.declared` of a manifest: the count of the inputs for each declared property. */
|
|
77
|
+
export interface DeclaredClaim {
|
|
78
|
+
/** A property with fewer inputs than this count is thin. */
|
|
79
|
+
readonly minCount: number;
|
|
80
|
+
/** The ids of the properties with a count below `minCount`. */
|
|
81
|
+
readonly thin: readonly string[];
|
|
82
|
+
/** The count of the inputs for each property id. */
|
|
83
|
+
readonly counts: Readonly<Record<string, number>>;
|
|
84
|
+
/** The key of the family of an input. `familyOf` gives the key of one cell. The family is the unit of a verdict. */
|
|
85
|
+
readonly familyBy?: FamilyBy;
|
|
86
|
+
/** The minimum count of the inputs of each family. Without it, `checkDeclared` does not count the families. */
|
|
87
|
+
readonly familyMin?: number;
|
|
88
|
+
}
|
|
69
89
|
/**
|
|
70
|
-
* The
|
|
71
|
-
*
|
|
90
|
+
* The key of the family of a cell (`docs/CORPUS-CHECKS.md`).
|
|
91
|
+
*
|
|
92
|
+
* - The flat form is a list of dimensions. The key is the values of these dimensions of the cell, in order, with `/` between them.
|
|
93
|
+
* - 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.
|
|
72
94
|
*/
|
|
73
|
-
export
|
|
95
|
+
export type FamilyBy = readonly string[] | {
|
|
96
|
+
readonly [kind: string]: readonly string[];
|
|
97
|
+
};
|
|
98
|
+
/** A cell of an input: one value for each dimension. The map form of `FamilyBy` also reads the field `kind`. */
|
|
99
|
+
export type FamilyCell = Readonly<Record<string, unknown>>;
|
|
100
|
+
/** The entry of the map form of `FamilyBy` for each kind without its own entry. */
|
|
101
|
+
export declare const FAMILY_ANY_KIND = "*";
|
|
74
102
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
103
|
+
* This function gives the family key of a cell. It throws a `RangeError` when the cell does not have a dimension of the key.
|
|
104
|
+
* In the map form, it also throws for a cell without `kind`, and for a kind with no entry and no entry `"*"`.
|
|
105
|
+
* For example, `{ "rect-grid": ["obstacles"], "*": [] }` gives `rect-grid/wall` for a `rect-grid` cell and `gallery` for a `gallery` cell.
|
|
77
106
|
*/
|
|
78
|
-
export declare
|
|
107
|
+
export declare function familyOf(cell: FamilyCell, familyBy: FamilyBy): string;
|
|
108
|
+
/** The hook that gives the ids of the properties that one input declares. */
|
|
109
|
+
export type Declares<I> = (input: I) => readonly string[];
|
|
79
110
|
/**
|
|
80
|
-
*
|
|
81
|
-
* in
|
|
111
|
+
* 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.
|
|
112
|
+
* 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.
|
|
82
113
|
*/
|
|
83
|
-
export
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
export declare function declaredCounts<I>(inputs: Iterable<I>, declares: Declares<I>, ids?: readonly string[]): Record<string, number>;
|
|
115
|
+
/**
|
|
116
|
+
* This function reads the field `claims.declared` of a manifest. A manifest without it gives `undefined`.
|
|
117
|
+
* It throws an `Error` for a claim without a whole `minCount`, a list `thin` of ids and a whole count for each id.
|
|
118
|
+
*/
|
|
119
|
+
export declare function declaredClaimOf(manifest: object): DeclaredClaim | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* 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.
|
|
122
|
+
*
|
|
123
|
+
* - `ids` are the property ids. The default is the ids of `claim.counts`.
|
|
124
|
+
* - 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.
|
|
125
|
+
* - An id with a count below `minCount` is in `thin`. Each id of `thin` is an id of `ids`.
|
|
126
|
+
* - Each id that `declares` gives is an id of `ids`.
|
|
127
|
+
*
|
|
128
|
+
* With `claim.familyBy`, the hook `cellOf` gives the cell of each input. The default reads the field `cell` of the input.
|
|
129
|
+
*
|
|
130
|
+
* - 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.
|
|
131
|
+
* - Two cells with different dimension values do not give the same key.
|
|
132
|
+
* - With `claim.familyMin`, each family has `familyMin` inputs or more.
|
|
133
|
+
*/
|
|
134
|
+
export declare function checkDeclared<I>(inputs: Iterable<I>, declares: Declares<I>, claim: DeclaredClaim, ids?: readonly string[], cellOf?: (input: I) => FamilyCell | undefined): ClaimBreak[];
|
|
135
|
+
/** The id and the hash of one input of a corpus. */
|
|
136
|
+
export interface CorpusEntry {
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly hash: string;
|
|
88
139
|
}
|
|
89
140
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
141
|
+
* 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`
|
|
142
|
+
* 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.
|
|
92
143
|
*/
|
|
93
|
-
export declare
|
|
144
|
+
export declare function corpusHashOf(corpus: string, inputs: readonly CorpusEntry[]): string;
|
|
145
|
+
/** The schema of a split file. */
|
|
146
|
+
export declare const SPLIT_SCHEMA = "corpus-split/1";
|
|
147
|
+
/** One fold of a split: the seeds that fit a selector and the seeds that score it. */
|
|
148
|
+
export interface SplitFold {
|
|
149
|
+
readonly train: readonly number[];
|
|
150
|
+
readonly heldOut: readonly number[];
|
|
151
|
+
}
|
|
152
|
+
/** 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. */
|
|
153
|
+
export interface CorpusSplit {
|
|
154
|
+
readonly schema: typeof SPLIT_SCHEMA;
|
|
155
|
+
readonly corpus: string;
|
|
156
|
+
/** The hash of the corpus: `corpusHashOf` of its manifest. */
|
|
157
|
+
readonly corpusHash: string;
|
|
158
|
+
/** The splits by name. Each split has one fold or more. */
|
|
159
|
+
readonly splits: Readonly<Record<string, {
|
|
160
|
+
readonly folds: readonly SplitFold[];
|
|
161
|
+
}>>;
|
|
162
|
+
}
|
|
163
|
+
/** The fields of a manifest that the split check reads. */
|
|
164
|
+
export interface SplitCorpus {
|
|
165
|
+
readonly corpus: string;
|
|
166
|
+
readonly specs: readonly {
|
|
167
|
+
readonly seeds: readonly number[];
|
|
168
|
+
}[];
|
|
169
|
+
readonly inputs: readonly CorpusEntry[];
|
|
170
|
+
}
|
|
171
|
+
/** This function gives the name of the split file of a corpus. */
|
|
172
|
+
export declare function splitFileName(corpus: string, hash: string): string;
|
|
173
|
+
/**
|
|
174
|
+
* 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.
|
|
175
|
+
*
|
|
176
|
+
* - The schema is `corpus-split/1`, the corpus is the id of the manifest and `corpusHash` is `corpusHashOf` of the manifest.
|
|
177
|
+
* - Each split has one fold or more. In each fold, `train` and `heldOut` are lists of seeds, not empty and with no common seed.
|
|
178
|
+
* - Each seed is a seed of a spec of the manifest.
|
|
179
|
+
* - With `name`, the file has the split `name`.
|
|
180
|
+
*/
|
|
181
|
+
export declare function checkSplit(split: unknown, corpus: SplitCorpus, name?: string): ClaimBreak[];
|
|
182
|
+
/**
|
|
183
|
+
* 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.
|
|
184
|
+
* It throws an `Error` for each problem of `checkSplit`, and then for an unknown split name.
|
|
185
|
+
*/
|
|
186
|
+
export declare function splitFolds(split: unknown, corpus: SplitCorpus, name: string, where?: string): SplitFold[];
|
|
187
|
+
/** This function gives the folds that hold out one seed each, in the order of the seeds. Each fold trains on the other seeds. */
|
|
188
|
+
export declare function leaveOneSeedOut(seeds: readonly number[]): SplitFold[];
|
|
94
189
|
/**
|
|
95
190
|
* A port of a box: a place where edges go into the box.
|
|
96
191
|
* With `x` and `y`, the port is fixed on the border of the box, relative to its top-left corner.
|
|
@@ -118,6 +213,11 @@ export interface LayoutBox {
|
|
|
118
213
|
readonly group?: string;
|
|
119
214
|
/** A region relative to the origin of the box. Without it, the box is the rectangle `w` by `h`. */
|
|
120
215
|
readonly shape?: Region;
|
|
216
|
+
/**
|
|
217
|
+
* The shape kind of the box (`docs/SHAPES.md`). Without it, `shapeKindOf` gives the kind of `shape`, or `rect` without a shape.
|
|
218
|
+
* The kind `free` tells that the contract knows only the bounding box `w` by `h`.
|
|
219
|
+
*/
|
|
220
|
+
readonly shapeKind?: ShapeKind;
|
|
121
221
|
readonly ports?: readonly Port[];
|
|
122
222
|
/** 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. */
|
|
123
223
|
readonly margin?: Margin;
|
|
@@ -166,6 +266,18 @@ export interface LayoutGenerator {
|
|
|
166
266
|
readonly params: Readonly<Record<string, unknown>>;
|
|
167
267
|
readonly seed: number;
|
|
168
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* One minimum distance between two boxes (`a` and `b`). It replaces the two margins of the boxes for this pair, and the global `gap`.
|
|
271
|
+
* The order of `a` and `b` has no meaning. A pair without an entry keeps the margins and the `gap`.
|
|
272
|
+
*/
|
|
273
|
+
export interface PairGap {
|
|
274
|
+
readonly a: string;
|
|
275
|
+
readonly b: string;
|
|
276
|
+
/** The minimum distance between the two boxes, in units: a finite number of 0 or more. */
|
|
277
|
+
readonly gap: number;
|
|
278
|
+
/** The count of the channels that the gap has space for. It is information only: a whole number of 0 or more. */
|
|
279
|
+
readonly lanes?: number;
|
|
280
|
+
}
|
|
169
281
|
/** The cell of an input in the taxonomy: one value for each dimension. The dimensions are in `docs/FORMAT.md` of `packing`. */
|
|
170
282
|
export interface LayoutCell {
|
|
171
283
|
readonly containerSize?: "fixed" | "freeHeight" | "freeWidth" | "freeAspect" | "freeArea";
|
|
@@ -178,6 +290,8 @@ export interface LayoutCell {
|
|
|
178
290
|
readonly edgeShape?: "random" | "clustered" | "hubChain" | "longRange" | "tree" | "bundled";
|
|
179
291
|
readonly groups?: "none" | "flat" | "nested";
|
|
180
292
|
readonly ports?: "free" | "sides" | "fixed";
|
|
293
|
+
/** The shape kinds of the boxes: one kind, or `mixed` for more kinds. Without it, each box is a `rect`. `itemShapeOf` gives the value. */
|
|
294
|
+
readonly itemShape?: ShapeKind | "mixed";
|
|
181
295
|
}
|
|
182
296
|
/** An input of the corpus: the format `layout-input/1`. */
|
|
183
297
|
export interface LayoutInput {
|
|
@@ -201,6 +315,8 @@ export interface LayoutInput {
|
|
|
201
315
|
readonly container?: LayoutContainer;
|
|
202
316
|
/** The free space between two boxes with their margins. Routes use it. */
|
|
203
317
|
readonly gap?: number;
|
|
318
|
+
/** The distances of some pairs of boxes. An entry replaces the margins and the `gap` for its pair. `canonicalInput` sorts the list. */
|
|
319
|
+
readonly pairGaps?: readonly PairGap[];
|
|
204
320
|
readonly boxes: readonly LayoutBox[];
|
|
205
321
|
readonly edges?: readonly LayoutEdge[];
|
|
206
322
|
readonly obstacles?: readonly Obstacle[];
|
|
@@ -217,9 +333,99 @@ export interface PackInput {
|
|
|
217
333
|
readonly items: readonly Item[];
|
|
218
334
|
readonly obstacles?: readonly Obstacle[];
|
|
219
335
|
readonly gap?: number;
|
|
336
|
+
readonly pairGaps?: readonly PairGap[];
|
|
220
337
|
}
|
|
221
338
|
/** This function gives the packer input of a file. An input without a container gets `{ fixed: "none" }`, so the packer picks the size. */
|
|
222
339
|
export declare function toPackInput(input: LayoutInput): PackInput;
|
|
340
|
+
/**
|
|
341
|
+
* This function gives the canonical form of an input. `documentHash` uses it for each `layout-input/1` document.
|
|
342
|
+
* Each pair of `pairGaps` gets `a` before `b`, and the list is sorted by `a` and then by `b`.
|
|
343
|
+
* An input without `pairGaps` is the same object, so its hash does not change.
|
|
344
|
+
*/
|
|
345
|
+
export declare function canonicalInput<T extends LayoutInput>(input: T): T;
|
|
346
|
+
/**
|
|
347
|
+
* The kind of the shape of an item. A box without `shape` and without `shapeKind` is a `rect`.
|
|
348
|
+
* 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.
|
|
349
|
+
*/
|
|
350
|
+
export type ShapeKind = "rect" | "polygon" | "circle" | "free";
|
|
351
|
+
/** 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. */
|
|
352
|
+
export interface ShapeGeometry {
|
|
353
|
+
/** The bounding box: `boundsOf` and `placedRect`. */
|
|
354
|
+
readonly bounds: boolean;
|
|
355
|
+
/** The area of the shape. */
|
|
356
|
+
readonly area: boolean;
|
|
357
|
+
/** The test that the shape is inside a region: `rectInRegion` for a `rect`. */
|
|
358
|
+
readonly contains: boolean;
|
|
359
|
+
/** The test that two shapes overlap: `overlapOf` for two `rect` shapes. */
|
|
360
|
+
readonly overlap: boolean;
|
|
361
|
+
}
|
|
362
|
+
/** The facts of one shape kind: its fields, the kinds of `Region` that give it, and its geometry. */
|
|
363
|
+
export interface ShapeKindSpec {
|
|
364
|
+
readonly id: ShapeKind;
|
|
365
|
+
/** The fields of the outline, relative to the top-left corner of the box. A name with `?` is optional. */
|
|
366
|
+
readonly fields: readonly string[];
|
|
367
|
+
/** The kinds of `LayoutBox.shape` that agree with this kind. */
|
|
368
|
+
readonly regions: readonly Region["kind"][];
|
|
369
|
+
readonly geometry: ShapeGeometry;
|
|
370
|
+
}
|
|
371
|
+
/** The declared shape kinds, in their order. Only `rect` has all of its geometry. The other kinds have their bounding box only. */
|
|
372
|
+
export declare const SHAPE_KINDS: readonly ShapeKindSpec[];
|
|
373
|
+
/** The ids of `SHAPE_KINDS`, in their order. */
|
|
374
|
+
export declare const SHAPE_KIND_IDS: readonly ShapeKind[];
|
|
375
|
+
/** The shape kinds of a measure or a rule without `shapes`. The contract measured only rectangles before L46. */
|
|
376
|
+
export declare const DEFAULT_SHAPES: readonly ShapeKind[];
|
|
377
|
+
/** A measure or a rule, with the shape kinds that it supports. Without `shapes`, it supports `DEFAULT_SHAPES`. */
|
|
378
|
+
export interface ShapeSupport<Id extends string = string> {
|
|
379
|
+
readonly id: Id;
|
|
380
|
+
readonly shapes?: readonly ShapeKind[];
|
|
381
|
+
}
|
|
382
|
+
/** This function tells if a value is a declared shape kind. */
|
|
383
|
+
export declare function isShapeKind(value: unknown): value is ShapeKind;
|
|
384
|
+
/**
|
|
385
|
+
* This function gives the shape kind of a box. A box with `shapeKind` has that kind.
|
|
386
|
+
* Without it, the kind comes from `shape`: no shape is a `rect`, and an ellipse is `free`.
|
|
387
|
+
*/
|
|
388
|
+
export declare function shapeKindOf(box: LayoutBox): ShapeKind;
|
|
389
|
+
/** 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. */
|
|
390
|
+
export declare function shapeKindsOf(input: Pick<LayoutInput, "boxes">): ShapeKind[];
|
|
391
|
+
/** This function gives the value of the cell dimension `itemShape` of an input: its one kind, `mixed` for more kinds, or `rect` without boxes. */
|
|
392
|
+
export declare function itemShapeOf(input: Pick<LayoutInput, "boxes">): ShapeKind | "mixed";
|
|
393
|
+
/** This function gives the problem of the shape kind of a box, or `undefined` when `shapeKind` and `shape` agree. */
|
|
394
|
+
export declare function shapeKindProblem(box: LayoutBox): string | undefined;
|
|
395
|
+
/** This function gives the shape kinds that a measure or a rule supports. */
|
|
396
|
+
export declare function shapesOf(use: Pick<ShapeSupport, "shapes">): readonly ShapeKind[];
|
|
397
|
+
/**
|
|
398
|
+
* 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.
|
|
399
|
+
* Each break has the claim `shape`, the id of the input, and the first 5 ids of the boxes of the kind.
|
|
400
|
+
*/
|
|
401
|
+
export declare function checkShapes(input: Pick<LayoutInput, "id" | "boxes">, uses: readonly ShapeSupport[]): ClaimBreak[];
|
|
402
|
+
/** The epsilon for the float compares in an engine. */
|
|
403
|
+
export declare const EPS = 1e-6;
|
|
404
|
+
/**
|
|
405
|
+
* The count of grid steps in one unit of a written file. A file rounds each number `v` to `Math.round(v * RECORD_SCALE) / RECORD_SCALE`.
|
|
406
|
+
* Use a multiplication by this value, not a division by `RECORD_EPS`. The two differ at some half steps.
|
|
407
|
+
*/
|
|
408
|
+
export declare const RECORD_SCALE = 1e3;
|
|
409
|
+
/**
|
|
410
|
+
* The epsilon for the float compares on a written file. A file rounds each number to 3 decimals,
|
|
411
|
+
* so a difference of two values can move by up to 0.001. It is `1 / RECORD_SCALE`.
|
|
412
|
+
*/
|
|
413
|
+
export declare const RECORD_EPS = .001;
|
|
414
|
+
/**
|
|
415
|
+
* The tolerance of each hard rule, in layout units. A record writes the tolerance that its run used,
|
|
416
|
+
* in its field `tolerance`, next to `hard`.
|
|
417
|
+
*/
|
|
418
|
+
export interface Tolerance {
|
|
419
|
+
/** Two boxes with their margins break `no-overlap` when their insides overlap by more than this on each axis. */
|
|
420
|
+
readonly overlap: number;
|
|
421
|
+
/** A route breaks `no-pass-through` when a part longer than this is inside a box made this much smaller. */
|
|
422
|
+
readonly through: number;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* The default tolerance of each rule. The packer is exact, so `overlap` is one unit of the rounding.
|
|
426
|
+
* Routes are sampled curves that follow the margin line, so `through` is larger.
|
|
427
|
+
*/
|
|
428
|
+
export declare const DEFAULT_TOLERANCE: Tolerance;
|
|
223
429
|
/** The position of one item. `turn` is 90 when the packer turned a turnable item. */
|
|
224
430
|
export interface Placement {
|
|
225
431
|
readonly id: string;
|
|
@@ -276,6 +482,8 @@ export interface LayoutRecord {
|
|
|
276
482
|
readonly seed: number;
|
|
277
483
|
readonly nodes: number;
|
|
278
484
|
readonly edges: number;
|
|
485
|
+
/** The shape kinds of the boxes of the input, in the order of `SHAPE_KINDS`. Without it, each box is a `rect`. */
|
|
486
|
+
readonly shapes?: readonly ShapeKind[];
|
|
279
487
|
/** The value of each measure, by its name: `pack.*`, `route.*` or `joint.*`. */
|
|
280
488
|
readonly measures: Readonly<Record<string, number>>;
|
|
281
489
|
/** The count of the breaks of each hard rule. A good run has 0 for each rule. */
|
|
@@ -319,16 +527,22 @@ export interface RunEnv {
|
|
|
319
527
|
readonly cpus: number;
|
|
320
528
|
}
|
|
321
529
|
/** The facts of a run that the input does not give. */
|
|
322
|
-
export type RunFacts = Omit<LayoutRecord, "schema" | "input" | "inputHash" | "set" | "nodes" | "edges">;
|
|
323
|
-
/**
|
|
530
|
+
export type RunFacts = Omit<LayoutRecord, "schema" | "input" | "inputHash" | "set" | "nodes" | "edges" | "shapes">;
|
|
531
|
+
/**
|
|
532
|
+
* This function gives the record of a run. The input gives its id, its hash, its set and the counts of the nodes and the edges.
|
|
533
|
+
* The input also gives `shapes`. An input with only `rect` boxes gets no `shapes`, so its record does not change.
|
|
534
|
+
*/
|
|
324
535
|
export declare function toLayoutRecord(input: LayoutInput, run: RunFacts): LayoutRecord;
|
|
325
536
|
/** This function gives the area of a placed box: its shape or its rectangle, at its position. A box without a position gives `undefined`. */
|
|
326
537
|
export declare function placedRect(box: LayoutBox): Rect | undefined;
|
|
327
538
|
/**
|
|
328
539
|
* This function counts the pairs of placed boxes whose insides, with their margins, overlap by more than `tolerance` on each axis.
|
|
329
540
|
* A box with a shape counts as its bounding box. That area is larger, thus the count is safe.
|
|
541
|
+
*
|
|
542
|
+
* 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.
|
|
543
|
+
* Thus the pair breaks the rule only when the boxes are nearer than the gap on each axis. The other pairs do not change.
|
|
330
544
|
*/
|
|
331
|
-
export declare function countOverlaps(boxes: readonly LayoutBox[], tolerance?: number): number;
|
|
545
|
+
export declare function countOverlaps(boxes: readonly LayoutBox[], tolerance?: number, pairGaps?: readonly PairGap[]): number;
|
|
332
546
|
/** The options of the container test of `countOutside` and `packHard`. */
|
|
333
547
|
export interface ContainerTest {
|
|
334
548
|
/**
|
|
@@ -355,6 +569,12 @@ export interface PackHard {
|
|
|
355
569
|
readonly "locked-kept": number;
|
|
356
570
|
readonly complete: number;
|
|
357
571
|
}
|
|
572
|
+
/**
|
|
573
|
+
* The hard rules of a pack, with the shape kinds that each rule supports.
|
|
574
|
+
* `no-overlap` and `in-container` test the bounding box of a shape. That count is exact only for a `rect`.
|
|
575
|
+
* `locked-kept` and `complete` read only the positions and the ids, so they support each kind.
|
|
576
|
+
*/
|
|
577
|
+
export declare const PACK_HARD_RULES: readonly ShapeSupport<keyof PackHard>[];
|
|
358
578
|
/** This function tells if the inside of `region` and the inside of `rect` have a common point. */
|
|
359
579
|
export declare function regionHitsRect(region: Region, rect: Rect): boolean;
|
|
360
580
|
/**
|
|
@@ -370,7 +590,8 @@ export declare function countObstacleHits(boxes: readonly LayoutBox[], obstacles
|
|
|
370
590
|
/**
|
|
371
591
|
* This function gives the count of each hard rule of the output of a packer.
|
|
372
592
|
* It applies the output with `applyPack`. Only the placed boxes and the locked boxes count for the overlaps and the container.
|
|
373
|
-
* `no-overlap` counts the pairs of boxes and the pairs of a box and an obstacle.
|
|
593
|
+
* `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.
|
|
594
|
+
*
|
|
374
595
|
* A locked box without a placement, or with a move of more than `RECORD_EPS`, breaks `locked-kept`.
|
|
375
596
|
* A locked box without a position in the input is a bad input, not a break. `checkInput` finds it.
|
|
376
597
|
* Another box without a placement that is not in `overflow` breaks `complete`.
|
|
@@ -381,6 +602,7 @@ export declare function packHard(input: LayoutInput, output: PackOutput, toleran
|
|
|
381
602
|
/**
|
|
382
603
|
* This function gives the problems of an input file. An empty list tells that the file is good.
|
|
383
604
|
* A problem is a bad input, not a break of a hard rule. Thus an engine refuses the input.
|
|
605
|
+
* In `pairGaps`, an unknown box, a pair of one box, a repeated pair in either order, a bad `gap` and bad `lanes` are problems.
|
|
384
606
|
*/
|
|
385
607
|
export declare function checkInput(input: LayoutInput): readonly string[];
|
|
386
608
|
/** This function gives the side after a turn of 90 degrees clockwise. */
|
|
@@ -425,10 +647,15 @@ export interface MeasureSpec<Id extends string = string> {
|
|
|
425
647
|
};
|
|
426
648
|
/** The role of the measure in the joint selector. */
|
|
427
649
|
readonly role?: "guard" | "change-guard" | "diagnostic" | "time";
|
|
650
|
+
/** The shape kinds of the boxes that the measure supports. Without it, the measure supports only `rect`. `checkShapes` refuses the other kinds. */
|
|
651
|
+
readonly shapes?: readonly ShapeKind[];
|
|
428
652
|
}
|
|
429
653
|
/** The id of a joint measure. `docs/JOINT-MEASURES.md` gives the definitions. */
|
|
430
654
|
export 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";
|
|
431
|
-
/**
|
|
655
|
+
/**
|
|
656
|
+
* The specs of the joint measures, in the order of `docs/JOINT-MEASURES.md`.
|
|
657
|
+
* `joint.fill` and `joint.straight.length` read the area of each box, so they support only `rect`. `docs/SHAPES.md` tells the reasons.
|
|
658
|
+
*/
|
|
432
659
|
export declare const JOINT_MEASURES: readonly MeasureSpec<JointMeasureId>[];
|
|
433
660
|
/** The threshold of `joint.stability.moved`, in widths `W` of the base. */
|
|
434
661
|
export declare const JOINT_MOVED_MIN = .01;
|
|
@@ -530,6 +757,7 @@ export declare function outputHash(value: unknown, options?: HashOptions): strin
|
|
|
530
757
|
/**
|
|
531
758
|
* This function gives the hash of a document. It uses the rule of `outputHash`, but the form does not include the field `hash` of the document.
|
|
532
759
|
* With the default grid, it is the input hash of `docs/FORMAT.md` of `packing`.
|
|
760
|
+
* A document with the schema `layout-input/1` goes through `canonicalInput` first. Thus the order of its `pairGaps` does not change the hash.
|
|
533
761
|
*/
|
|
534
762
|
export declare function documentHash(doc: object, options?: HashOptions): string;
|
|
535
763
|
/** One output group: the candidates with the same output hash on each decision input. */
|
|
@@ -697,128 +925,6 @@ export declare function pickMoves(trace: Pick<PortfolioTrace, "picked">): {
|
|
|
697
925
|
* It also throws a `RangeError` for an empty list of members, or for two members with the same id.
|
|
698
926
|
*/
|
|
699
927
|
export declare function portfolio<I, O>(id: string, members: readonly Member<I, O>[] | ((input: I) => readonly Member<I, O>[]), key: PortfolioKey<I, O>, options?: PortfolioOptions): Portfolio<I, O>;
|
|
700
|
-
/** One broken claim of a corpus, with the ids of the inputs that break it. */
|
|
701
|
-
export interface ClaimBreak {
|
|
702
|
-
/** The name of the claim, for example `declared`, `split` or `index`. */
|
|
703
|
-
readonly claim: string;
|
|
704
|
-
/** The text of the break. */
|
|
705
|
-
readonly detail: string;
|
|
706
|
-
/** The ids of the inputs that break the claim. The list is empty when the break has no input. */
|
|
707
|
-
readonly inputs: readonly string[];
|
|
708
|
-
}
|
|
709
|
-
/** The claim `claims.declared` of a manifest: the count of the inputs for each declared property. */
|
|
710
|
-
export interface DeclaredClaim {
|
|
711
|
-
/** A property with fewer inputs than this count is thin. */
|
|
712
|
-
readonly minCount: number;
|
|
713
|
-
/** The ids of the properties with a count below `minCount`. */
|
|
714
|
-
readonly thin: readonly string[];
|
|
715
|
-
/** The count of the inputs for each property id. */
|
|
716
|
-
readonly counts: Readonly<Record<string, number>>;
|
|
717
|
-
/** The key of the family of an input. `familyOf` gives the key of one cell. The family is the unit of a verdict. */
|
|
718
|
-
readonly familyBy?: FamilyBy;
|
|
719
|
-
/** The minimum count of the inputs of each family. Without it, `checkDeclared` does not count the families. */
|
|
720
|
-
readonly familyMin?: number;
|
|
721
|
-
}
|
|
722
|
-
/**
|
|
723
|
-
* The key of the family of a cell (`docs/CORPUS-CHECKS.md`).
|
|
724
|
-
*
|
|
725
|
-
* - The flat form is a list of dimensions. The key is the values of these dimensions of the cell, in order, with `/` between them.
|
|
726
|
-
* - 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.
|
|
727
|
-
*/
|
|
728
|
-
export type FamilyBy = readonly string[] | {
|
|
729
|
-
readonly [kind: string]: readonly string[];
|
|
730
|
-
};
|
|
731
|
-
/** A cell of an input: one value for each dimension. The map form of `FamilyBy` also reads the field `kind`. */
|
|
732
|
-
export type FamilyCell = Readonly<Record<string, unknown>>;
|
|
733
|
-
/** The entry of the map form of `FamilyBy` for each kind without its own entry. */
|
|
734
|
-
export declare const FAMILY_ANY_KIND = "*";
|
|
735
|
-
/**
|
|
736
|
-
* This function gives the family key of a cell. It throws a `RangeError` when the cell does not have a dimension of the key.
|
|
737
|
-
* In the map form, it also throws for a cell without `kind`, and for a kind with no entry and no entry `"*"`.
|
|
738
|
-
* For example, `{ "rect-grid": ["obstacles"], "*": [] }` gives `rect-grid/wall` for a `rect-grid` cell and `gallery` for a `gallery` cell.
|
|
739
|
-
*/
|
|
740
|
-
export declare function familyOf(cell: FamilyCell, familyBy: FamilyBy): string;
|
|
741
|
-
/** The hook that gives the ids of the properties that one input declares. */
|
|
742
|
-
export type Declares<I> = (input: I) => readonly string[];
|
|
743
|
-
/**
|
|
744
|
-
* 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.
|
|
745
|
-
* 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.
|
|
746
|
-
*/
|
|
747
|
-
export declare function declaredCounts<I>(inputs: Iterable<I>, declares: Declares<I>, ids?: readonly string[]): Record<string, number>;
|
|
748
|
-
/**
|
|
749
|
-
* This function reads the field `claims.declared` of a manifest. A manifest without it gives `undefined`.
|
|
750
|
-
* It throws an `Error` for a claim without a whole `minCount`, a list `thin` of ids and a whole count for each id.
|
|
751
|
-
*/
|
|
752
|
-
export declare function declaredClaimOf(manifest: object): DeclaredClaim | undefined;
|
|
753
|
-
/**
|
|
754
|
-
* 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.
|
|
755
|
-
*
|
|
756
|
-
* - `ids` are the property ids. The default is the ids of `claim.counts`.
|
|
757
|
-
* - 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.
|
|
758
|
-
* - An id with a count below `minCount` is in `thin`. Each id of `thin` is an id of `ids`.
|
|
759
|
-
* - Each id that `declares` gives is an id of `ids`.
|
|
760
|
-
*
|
|
761
|
-
* With `claim.familyBy`, the hook `cellOf` gives the cell of each input. The default reads the field `cell` of the input.
|
|
762
|
-
*
|
|
763
|
-
* - 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.
|
|
764
|
-
* - Two cells with different dimension values do not give the same key.
|
|
765
|
-
* - With `claim.familyMin`, each family has `familyMin` inputs or more.
|
|
766
|
-
*/
|
|
767
|
-
export declare function checkDeclared<I>(inputs: Iterable<I>, declares: Declares<I>, claim: DeclaredClaim, ids?: readonly string[], cellOf?: (input: I) => FamilyCell | undefined): ClaimBreak[];
|
|
768
|
-
/** The id and the hash of one input of a corpus. */
|
|
769
|
-
export interface CorpusEntry {
|
|
770
|
-
readonly id: string;
|
|
771
|
-
readonly hash: string;
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* 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`
|
|
775
|
-
* 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.
|
|
776
|
-
*/
|
|
777
|
-
export declare function corpusHashOf(corpus: string, inputs: readonly CorpusEntry[]): string;
|
|
778
|
-
/** The schema of a split file. */
|
|
779
|
-
export declare const SPLIT_SCHEMA = "corpus-split/1";
|
|
780
|
-
/** One fold of a split: the seeds that fit a selector and the seeds that score it. */
|
|
781
|
-
export interface SplitFold {
|
|
782
|
-
readonly train: readonly number[];
|
|
783
|
-
readonly heldOut: readonly number[];
|
|
784
|
-
}
|
|
785
|
-
/** 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. */
|
|
786
|
-
export interface CorpusSplit {
|
|
787
|
-
readonly schema: typeof SPLIT_SCHEMA;
|
|
788
|
-
readonly corpus: string;
|
|
789
|
-
/** The hash of the corpus: `corpusHashOf` of its manifest. */
|
|
790
|
-
readonly corpusHash: string;
|
|
791
|
-
/** The splits by name. Each split has one fold or more. */
|
|
792
|
-
readonly splits: Readonly<Record<string, {
|
|
793
|
-
readonly folds: readonly SplitFold[];
|
|
794
|
-
}>>;
|
|
795
|
-
}
|
|
796
|
-
/** The fields of a manifest that the split check reads. */
|
|
797
|
-
export interface SplitCorpus {
|
|
798
|
-
readonly corpus: string;
|
|
799
|
-
readonly specs: readonly {
|
|
800
|
-
readonly seeds: readonly number[];
|
|
801
|
-
}[];
|
|
802
|
-
readonly inputs: readonly CorpusEntry[];
|
|
803
|
-
}
|
|
804
|
-
/** This function gives the name of the split file of a corpus. */
|
|
805
|
-
export declare function splitFileName(corpus: string, hash: string): string;
|
|
806
|
-
/**
|
|
807
|
-
* 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.
|
|
808
|
-
*
|
|
809
|
-
* - The schema is `corpus-split/1`, the corpus is the id of the manifest and `corpusHash` is `corpusHashOf` of the manifest.
|
|
810
|
-
* - Each split has one fold or more. In each fold, `train` and `heldOut` are lists of seeds, not empty and with no common seed.
|
|
811
|
-
* - Each seed is a seed of a spec of the manifest.
|
|
812
|
-
* - With `name`, the file has the split `name`.
|
|
813
|
-
*/
|
|
814
|
-
export declare function checkSplit(split: unknown, corpus: SplitCorpus, name?: string): ClaimBreak[];
|
|
815
|
-
/**
|
|
816
|
-
* 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.
|
|
817
|
-
* It throws an `Error` for each problem of `checkSplit`, and then for an unknown split name.
|
|
818
|
-
*/
|
|
819
|
-
export declare function splitFolds(split: unknown, corpus: SplitCorpus, name: string, where?: string): SplitFold[];
|
|
820
|
-
/** This function gives the folds that hold out one seed each, in the order of the seeds. Each fold trains on the other seeds. */
|
|
821
|
-
export declare function leaveOneSeedOut(seeds: readonly number[]): SplitFold[];
|
|
822
928
|
/** The schema of a strategy space. */
|
|
823
929
|
export declare const STRATEGY_SPACE_SCHEMA = "strategy-space/1";
|
|
824
930
|
/** The kind of a param: a whole number, a real number, one value of a list, or `true` and `false`. */
|
|
@@ -856,12 +962,30 @@ export interface MemberRule {
|
|
|
856
962
|
readonly min: number;
|
|
857
963
|
readonly max: number;
|
|
858
964
|
readonly ordered: boolean;
|
|
965
|
+
/**
|
|
966
|
+
* The member lists that the option permits. Each entry is a list of whole configs of the space of the members.
|
|
967
|
+
* Without `pool`, each list of base configs with a good count is a member list.
|
|
968
|
+
* With `pool`, a config of the option has the members of one entry, and `spaceSize` counts each entry one time.
|
|
969
|
+
*/
|
|
970
|
+
readonly pool?: readonly (readonly StrategyConfig[])[];
|
|
971
|
+
}
|
|
972
|
+
/** The inputs that an option supports. A missing field supports each value. */
|
|
973
|
+
export interface OptionSupports {
|
|
974
|
+
/** The shape kinds of the boxes (`docs/SHAPES.md`). Without it, the option supports each kind. */
|
|
975
|
+
readonly shape?: readonly ShapeKind[];
|
|
859
976
|
}
|
|
860
977
|
/** One implementation of a stage. An option with `members` is a meta option: it chooses between whole configs, or wraps them. */
|
|
861
978
|
export interface StageOption {
|
|
862
979
|
readonly id: string;
|
|
863
980
|
readonly params: readonly SpaceParam[];
|
|
864
981
|
readonly members?: MemberRule;
|
|
982
|
+
/** The inputs that the option supports. It describes the option, so it is not part of a config or of its id. */
|
|
983
|
+
readonly supports?: OptionSupports;
|
|
984
|
+
}
|
|
985
|
+
/** The shape kinds of the inputs of a check, a count or an enumeration. Without `shapes`, each option counts. */
|
|
986
|
+
export interface ShapeFilter {
|
|
987
|
+
/** The shape kinds of the input. Only the options that support each of these kinds count. */
|
|
988
|
+
readonly shapes?: readonly ShapeKind[];
|
|
865
989
|
}
|
|
866
990
|
/** One stage of the pipeline of an engine. A config of an `optional` stage can have no option. */
|
|
867
991
|
export interface SpaceStage {
|
|
@@ -917,40 +1041,50 @@ export interface SpaceSize {
|
|
|
917
1041
|
readonly meta: bigint | null;
|
|
918
1042
|
}
|
|
919
1043
|
/** The options of `spaceSize`. */
|
|
920
|
-
export interface SpaceSizeOptions {
|
|
1044
|
+
export interface SpaceSizeOptions extends ShapeFilter {
|
|
921
1045
|
/** The count of the levels of each numeric param, a whole number of 1 or more. */
|
|
922
1046
|
readonly levels: number;
|
|
923
1047
|
/** The largest meta count that `spaceSize` gives. The default is `10n ** 18n`. */
|
|
924
1048
|
readonly maxMeta?: bigint;
|
|
925
1049
|
}
|
|
926
1050
|
/** The options of a grid. The grid gives only the configs without a meta option. */
|
|
927
|
-
export interface GridOptions {
|
|
1051
|
+
export interface GridOptions extends ShapeFilter {
|
|
928
1052
|
readonly mode: "grid";
|
|
929
1053
|
readonly levels: number;
|
|
930
1054
|
/** The largest count of configs. A larger grid causes a `RangeError`. The default is 100000. */
|
|
931
1055
|
readonly limit?: number;
|
|
932
1056
|
}
|
|
933
1057
|
/** The options of a sample. */
|
|
934
|
-
export interface SampleOptions {
|
|
1058
|
+
export interface SampleOptions extends ShapeFilter {
|
|
935
1059
|
readonly mode: "sample";
|
|
936
1060
|
/** The count of the configs, a whole number of 0 or more. */
|
|
937
1061
|
readonly n: number;
|
|
938
1062
|
readonly seed: number;
|
|
939
|
-
/** With `skip` (the default), the sample has no meta option. With `sample`, a meta option draws its members from base samples
|
|
1063
|
+
/** With `skip` (the default), the sample has no meta option. With `sample`, a meta option draws its members from base samples, or one entry of its `pool`. */
|
|
940
1064
|
readonly meta?: "skip" | "sample";
|
|
941
1065
|
/** The largest count of option draws. The default is the larger value of 1000 and `100 * n`. */
|
|
942
1066
|
readonly maxTries?: number;
|
|
943
1067
|
}
|
|
944
1068
|
/** The options of `enumerateSpace`. */
|
|
945
1069
|
export type EnumerateOptions = GridOptions | SampleOptions;
|
|
1070
|
+
/** This function gives the problem of a value of a param, or `undefined` for a value in its range. The corpus dimensions of `families.ts` use it. */
|
|
1071
|
+
export declare function paramProblem(param: SpaceParam, value: unknown): string | undefined;
|
|
1072
|
+
/** This function tells if a param is active for the values of the earlier params. A param without `when` is always active. */
|
|
1073
|
+
export declare function paramActive(param: SpaceParam, values: Readonly<Record<string, ParamValue>>): boolean;
|
|
1074
|
+
/** This function gives the stable form of a value of a param: a real number gets 12 significant digits, and `-0` becomes `0`. */
|
|
1075
|
+
export declare function paramValue(param: SpaceParam, value: ParamValue): ParamValue;
|
|
946
1076
|
/**
|
|
947
1077
|
* This function checks one config of a space. It gives one break for each problem. An empty list tells that the config is good.
|
|
948
1078
|
* The `claim` of a break is the kind of the problem, for example `missing`, `unknown`, `inactive`, `param`, `constraint`, `members` or `depth`.
|
|
1079
|
+
*
|
|
1080
|
+
* A member list that is not an entry of the `pool` of its option gives the claim `pool`.
|
|
1081
|
+
* With `shapes`, an option that does not support a kind of the list gives the claim `shape`. A member of a meta option gets the same check.
|
|
949
1082
|
*/
|
|
950
|
-
export declare function checkConfig(space: StrategySpace, config: StrategyConfig): ClaimBreak[];
|
|
1083
|
+
export declare function checkConfig(space: StrategySpace, config: StrategyConfig, options?: ShapeFilter): ClaimBreak[];
|
|
951
1084
|
/**
|
|
952
1085
|
* This function checks a space. It gives one break for each problem. An empty list tells that the space is good.
|
|
953
1086
|
* It finds duplicate names, empty ranges, defaults out of range, enums without values, bad log scales, unknown names and bad named configs.
|
|
1087
|
+
* It also checks each entry of a `pool`: the count of its members, each member and a repeated entry.
|
|
954
1088
|
* The `inputs` of a break of a named config have the name of the config.
|
|
955
1089
|
*/
|
|
956
1090
|
export declare function checkSpace(space: StrategySpace): ClaimBreak[];
|
|
@@ -973,6 +1107,8 @@ export declare function paramLevels(param: SpaceParam, levels: number): ParamVal
|
|
|
973
1107
|
/**
|
|
974
1108
|
* This function gives the count of the grid points of a space, with `levels` levels for each numeric param.
|
|
975
1109
|
* It counts only the active params and the combinations that keep the constraints. It gives the meta configs apart.
|
|
1110
|
+
* A meta option with a `pool` counts each entry of the pool one time.
|
|
1111
|
+
* With `shapes`, it counts only the options that support each kind of the list.
|
|
976
1112
|
*/
|
|
977
1113
|
export declare function spaceSize(space: StrategySpace, options: SpaceSizeOptions): SpaceSize;
|
|
978
1114
|
/**
|
|
@@ -981,8 +1117,15 @@ export declare function spaceSize(space: StrategySpace, options: SpaceSizeOption
|
|
|
981
1117
|
* - The mode `grid` gives each grid point without a meta option, in a stable order. Stages, options and values go in the order of the space.
|
|
982
1118
|
* - The mode `sample` gives `n` configs of a seeded Latin hypercube. The options of a stage get equal strata, and each active param gets its own strata.
|
|
983
1119
|
* - A sample draws again when a point breaks a constraint. After `maxTries` draws, it throws an `Error`. Two sampled configs can be equal.
|
|
1120
|
+
* - With `shapes`, only the options that support each kind of the list count. Without `shapes`, the result does not change.
|
|
1121
|
+
* - A meta option with a `pool` gives only the entries of its pool. With `shapes`, only the entries whose members support each kind count.
|
|
984
1122
|
*/
|
|
985
1123
|
export declare function enumerateSpace(space: StrategySpace, options: EnumerateOptions): StrategyConfig[];
|
|
1124
|
+
/**
|
|
1125
|
+
* This function gives the shape kinds that a space accepts, in the order of `SHAPE_KINDS`. The value comes from the `supports` of the options.
|
|
1126
|
+
* A space accepts a kind when it has at least one config without a meta option on that kind.
|
|
1127
|
+
*/
|
|
1128
|
+
export declare function spaceShapeKinds(space: StrategySpace): ShapeKind[];
|
|
986
1129
|
/**
|
|
987
1130
|
* This function joins configs of the parts of a product space into one config of the space `space`.
|
|
988
1131
|
* The name of each stage gets the prefix `<space of the part>.`. The members of a meta option do not change.
|
|
@@ -1128,4 +1271,186 @@ export interface VerdictResult {
|
|
|
1128
1271
|
* It throws a `RangeError` for a missing `tie` or `level`, and for no pair. Two records of one side and input, or a value that is not finite, also cause a `RangeError`.
|
|
1129
1272
|
*/
|
|
1130
1273
|
export declare function verdict<R extends VerdictRecord>(records: Iterable<R>, options: VerdictOptions<R>): VerdictResult;
|
|
1274
|
+
/**
|
|
1275
|
+
* One dimension of a corpus: a param of `strategy-space.ts` with its meaning and the engines that use it.
|
|
1276
|
+
* The field `when` has the form of `SpaceParam.when`: the dimension is active only for some values of an earlier dimension.
|
|
1277
|
+
*/
|
|
1278
|
+
export interface CorpusDimension extends SpaceParam {
|
|
1279
|
+
/** The meaning of the dimension, in one sentence. */
|
|
1280
|
+
readonly meaning: string;
|
|
1281
|
+
/** The engines that read the dimension, for example `packing`, `highways` and `joint`. */
|
|
1282
|
+
readonly engines: readonly string[];
|
|
1283
|
+
/** The values of a sweep. Without them, a sweep uses the values of an `enum`, `false` and `true` of a `bool`, or the default. */
|
|
1284
|
+
readonly levels?: readonly ParamValue[];
|
|
1285
|
+
}
|
|
1286
|
+
/** The values of the dimensions of one input: one value for each name. */
|
|
1287
|
+
export type DimensionValues = Readonly<Record<string, ParamValue>>;
|
|
1288
|
+
/** A factory of seeded random numbers: it gives a source of numbers in [0, 1) for a seed. */
|
|
1289
|
+
export type RngFactory = (seed: number) => () => number;
|
|
1290
|
+
/**
|
|
1291
|
+
* The cross-engine note of a family. `exact` tells that each JavaScript engine gives the same output.
|
|
1292
|
+
* `libm-dependent` tells that the family uses a function that is not correctly rounded in each engine, for example `Math.log`, `Math.cos` or `**`.
|
|
1293
|
+
*/
|
|
1294
|
+
export type CrossEngine = "exact" | "libm-dependent";
|
|
1295
|
+
/** The random numbers of the default factory: `mulberry32` of `random.ts`. Its stream is pinned in `families.test.ts`. */
|
|
1296
|
+
export declare const DEFAULT_RNG: RngFactory;
|
|
1297
|
+
/** The context that a registry gives to `generate`. */
|
|
1298
|
+
export interface GenerateContext {
|
|
1299
|
+
/** The random factory of the family: its own `rng`, or `DEFAULT_RNG`. */
|
|
1300
|
+
readonly rng: RngFactory;
|
|
1301
|
+
/** The source of random numbers of the input: `rng(rngSeed(seed, dims))`. A family that does not use it takes no numbers from it. */
|
|
1302
|
+
readonly random: () => number;
|
|
1303
|
+
/** The name of the corpus of the input, when the caller gives one. */
|
|
1304
|
+
readonly set?: string;
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* A family of a corpus: a seeded generator with declared dimensions. The engine that owns it gives it to a registry.
|
|
1308
|
+
* The registry gives `generate` the raw seed and the full dimension values. It does not change the output, and it does not calculate a hash.
|
|
1309
|
+
*/
|
|
1310
|
+
export interface CorpusFamily<O = LayoutInput> {
|
|
1311
|
+
/** The name of the family, for example `rect-grid`. */
|
|
1312
|
+
readonly name: string;
|
|
1313
|
+
/** The version. A change of the output of the family needs a new version. A dimension of only some versions is in the list of those versions only. */
|
|
1314
|
+
readonly version: number;
|
|
1315
|
+
/** The engine that owns the definition of the family, for example `packing`. */
|
|
1316
|
+
readonly owner: string;
|
|
1317
|
+
/** The meaning of the family, in one sentence. */
|
|
1318
|
+
readonly meaning: string;
|
|
1319
|
+
/** The dimensions of the family, in their order. A dimension with `when` comes after the dimension that its `when` names. The name `kind` is reserved. */
|
|
1320
|
+
readonly dimensions: readonly CorpusDimension[];
|
|
1321
|
+
/** The text of the rule that gives the random numbers of an input from its seed and its dimensions. */
|
|
1322
|
+
readonly seeding: string;
|
|
1323
|
+
/** The cross-engine note of the family. */
|
|
1324
|
+
readonly crossEngine: CrossEngine;
|
|
1325
|
+
/** The random factory of the family. The default is `DEFAULT_RNG`. */
|
|
1326
|
+
readonly rng?: RngFactory;
|
|
1327
|
+
/** This function gives the seed of `context.random` from the input seed and the full dimension values. The default gives the input seed. */
|
|
1328
|
+
readonly rngSeed?: (seed: number, dims: DimensionValues) => number;
|
|
1329
|
+
/** The dimensions of the family key of `familyBy`, after the kind of the cell. A dimension with `when` is not permitted. The default is no dimension. */
|
|
1330
|
+
readonly familyBy?: readonly string[];
|
|
1331
|
+
/** This function gives the input of a seed. `dims` has a value for each dimension, also for an inactive dimension. */
|
|
1332
|
+
generate(seed: number, dims: DimensionValues, context: GenerateContext): O;
|
|
1333
|
+
}
|
|
1334
|
+
/** The options of `generate` of a registry. */
|
|
1335
|
+
export interface GenerateOptions {
|
|
1336
|
+
/** The version of the family. The default is the first version that the registry got. */
|
|
1337
|
+
readonly version?: number;
|
|
1338
|
+
/** The name of the corpus. The registry gives it to the family in `context.set`. */
|
|
1339
|
+
readonly set?: string;
|
|
1340
|
+
}
|
|
1341
|
+
/** The options of `cells` and `cellCount` of a registry. */
|
|
1342
|
+
export interface CellsOptions {
|
|
1343
|
+
readonly version?: number;
|
|
1344
|
+
/** The dimensions of the sweep. The other dimensions keep their defaults. The default is each dimension of the family. */
|
|
1345
|
+
readonly sweep?: readonly string[];
|
|
1346
|
+
/** The values of a sweep for some dimensions, in place of the levels of the dimensions. */
|
|
1347
|
+
readonly levels?: Readonly<Record<string, readonly ParamValue[]>>;
|
|
1348
|
+
}
|
|
1349
|
+
/** The cell of an input of a registry: `<name>@<version>` of its family in `kind` (`familyKind`), and the value of each active dimension. */
|
|
1350
|
+
export type RegistryCell = Readonly<Record<string, ParamValue>> & {
|
|
1351
|
+
readonly kind: string;
|
|
1352
|
+
};
|
|
1353
|
+
/** This function gives the `kind` of the cells of a version of a family: `<name>@<version>`, for example `rect-grid@2`. Thus two versions do not share a family key. */
|
|
1354
|
+
export declare function familyKind(name: string, version: number): string;
|
|
1355
|
+
/** A registry of families. An import registers nothing: a host makes a registry from the lists of families of the engines. */
|
|
1356
|
+
export interface FamilyRegistry<O = LayoutInput> {
|
|
1357
|
+
/** This method adds a family. It throws a `RangeError` for a second family with the same name and version, or for a bad dimension. */
|
|
1358
|
+
register(family: CorpusFamily<O>): FamilyRegistry<O>;
|
|
1359
|
+
/** This method gives a family. Without a version, it gives the first version that the registry got. It throws a `RangeError` for an unknown family. */
|
|
1360
|
+
family(name: string, version?: number): CorpusFamily<O>;
|
|
1361
|
+
/** This method gives each family, in the order of registration. */
|
|
1362
|
+
families(): readonly CorpusFamily<O>[];
|
|
1363
|
+
/**
|
|
1364
|
+
* This method gives the full dimension values of an input. It throws a `RangeError` for an unknown dimension or a bad value.
|
|
1365
|
+
* The methods with `dims` accept a cell of `cellOf`: they ignore a `kind` that is the `familyKind` of the family, and refuse another `kind`.
|
|
1366
|
+
*/
|
|
1367
|
+
resolve(name: string, dims?: Readonly<Record<string, ParamValue>>, version?: number): DimensionValues;
|
|
1368
|
+
/** This method gives the input of a seed. The output is the output of the family, with no change. */
|
|
1369
|
+
generate(name: string, seed: number, dims?: Readonly<Record<string, ParamValue>>, options?: GenerateOptions): O;
|
|
1370
|
+
/** This method gives the cell of an input: the `familyKind` of the family version and the value of each active dimension. */
|
|
1371
|
+
cellOf(name: string, dims?: Readonly<Record<string, ParamValue>>, version?: number): RegistryCell;
|
|
1372
|
+
/** This method gives the full dimension values of each cell of a sweep, without the dead combinations of `when`. */
|
|
1373
|
+
cells(name: string, options?: CellsOptions): Generator<DimensionValues>;
|
|
1374
|
+
/** This method gives the count of the cells of `cells`. It makes no input. */
|
|
1375
|
+
cellCount(name: string, options?: CellsOptions): number;
|
|
1376
|
+
/** This method gives the defaults, and each end of each numeric range. The dimensions that a `when` needs get its first value. The other dimensions keep their defaults. */
|
|
1377
|
+
boundaryCells(name: string, version?: number): DimensionValues[];
|
|
1378
|
+
/** This method gives the random source of an input: the stream that `generate` gets in `context.random`. */
|
|
1379
|
+
rngOf(name: string, version?: number): (seed: number, dims?: Readonly<Record<string, ParamValue>>) => () => number;
|
|
1380
|
+
/** This method gives the map form of `FamilyBy` for the cells of `cellOf`: the `familyKind` of each family version, with its own `familyBy`. */
|
|
1381
|
+
familyBy(): FamilyBy;
|
|
1382
|
+
}
|
|
1383
|
+
/** The default key of a family in a manifest: the kind of the cell alone. It is the map form of `FamilyBy` with the entry `"*"`. */
|
|
1384
|
+
export declare const DEFAULT_FAMILY_BY: FamilyBy;
|
|
1385
|
+
/**
|
|
1386
|
+
* The shared dimension table. A family takes a dimension of it with `sharedDimension`, or declares its own dimension.
|
|
1387
|
+
* The coverage table of each dimension and each engine is in `docs/CORPUS.md`.
|
|
1388
|
+
*/
|
|
1389
|
+
export declare const CORPUS_DIMENSIONS: Readonly<Record<string, CorpusDimension>>;
|
|
1390
|
+
/** This function gives a dimension of `CORPUS_DIMENSIONS`, with the fields of `patch` over it. It throws a `RangeError` for an unknown name. */
|
|
1391
|
+
export declare function sharedDimension(name: string, patch?: Partial<CorpusDimension>): CorpusDimension;
|
|
1392
|
+
/**
|
|
1393
|
+
* This function gives the value at the fraction `t` of the range of a numeric dimension, on its scale. A slider of a site uses it.
|
|
1394
|
+
* A log scale with a `min` of 0 or less is the log of `1 + x - min`. An `int` dimension gives a whole number.
|
|
1395
|
+
*/
|
|
1396
|
+
export declare function dimensionAt(dim: SpaceParam, t: number): number;
|
|
1397
|
+
/** This function gives the fraction of the range of a numeric dimension at a value, on its scale. It is the inverse of `dimensionAt`. */
|
|
1398
|
+
export declare function dimensionUnit(dim: SpaceParam, value: number): number;
|
|
1399
|
+
/**
|
|
1400
|
+
* This function gives the values of a sweep of a dimension. `levels` of the dimension come first. Then an `enum` gives its values, and a `bool` gives `false` and `true`.
|
|
1401
|
+
* With `steps`, a numeric dimension gives `steps` points from `min` to `max` on its scale. Else it gives its default.
|
|
1402
|
+
*/
|
|
1403
|
+
export declare function levelsOf(dim: CorpusDimension, steps?: number): ParamValue[];
|
|
1404
|
+
/**
|
|
1405
|
+
* This function gives the full dimension values of an input. A missing dimension gets its default. An inactive dimension of `when` also gets its default.
|
|
1406
|
+
* Thus a default that the caller gives, a missing value and an inactive value give the same values. A real number gets its stable form.
|
|
1407
|
+
* The function throws a `RangeError` for an unknown dimension or a bad value, also for a bad value of an inactive dimension.
|
|
1408
|
+
*/
|
|
1409
|
+
export declare function resolveDimensions(dimensions: readonly CorpusDimension[], dims?: Readonly<Record<string, ParamValue>>, where?: string): DimensionValues;
|
|
1410
|
+
/** This function gives a new registry with the families of the list. Each engine gives the list of its families. An import registers nothing. */
|
|
1411
|
+
export declare function createFamilyRegistry<O = LayoutInput>(families?: Iterable<CorpusFamily<O>>): FamilyRegistry<O>;
|
|
1412
|
+
/** A step of a composed family: a pure function that changes an input after its base family, as `edgeStep` does. */
|
|
1413
|
+
export interface CorpusStep {
|
|
1414
|
+
readonly name: string;
|
|
1415
|
+
readonly version: number;
|
|
1416
|
+
/** The engine that owns the definition of the step. */
|
|
1417
|
+
readonly owner: string;
|
|
1418
|
+
readonly meaning: string;
|
|
1419
|
+
/** The dimensions of the step. Their names are not names of the dimensions of the base family. */
|
|
1420
|
+
readonly dimensions: readonly CorpusDimension[];
|
|
1421
|
+
/** The text of the rule that gives the random numbers of the step from the seed. */
|
|
1422
|
+
readonly seeding: string;
|
|
1423
|
+
readonly crossEngine: CrossEngine;
|
|
1424
|
+
/** This function gives the part of the family of the input that tells the values of the step. Without it, the family does not change. */
|
|
1425
|
+
readonly familyPart?: (dims: DimensionValues) => string;
|
|
1426
|
+
/** This function gives the changed input. It removes the old `hash` of the input. */
|
|
1427
|
+
apply(input: LayoutInput, seed: number, dims: DimensionValues): LayoutInput;
|
|
1428
|
+
}
|
|
1429
|
+
/** The options of `composeFamily`. */
|
|
1430
|
+
export interface ComposeOptions {
|
|
1431
|
+
/** The default is the name of the base family and the names of the steps, with `+` between them. */
|
|
1432
|
+
readonly name?: string;
|
|
1433
|
+
/** The default is the owner of the base family. */
|
|
1434
|
+
readonly owner?: string;
|
|
1435
|
+
readonly meaning?: string;
|
|
1436
|
+
/** The hash of the composed input. The default is `documentHash` of `hash.ts`. */
|
|
1437
|
+
readonly hash?: (input: LayoutInput) => string;
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* This function gives a family that runs the base family and then each step, with the same seed.
|
|
1441
|
+
* The family of the input gets the part of each step after a dot. The id becomes `<set>/<family>/s<seed>`, and the input gets the hash of `options.hash`.
|
|
1442
|
+
* The function throws a `RangeError` when a step has a dimension with the name of an earlier dimension.
|
|
1443
|
+
*/
|
|
1444
|
+
export declare function composeFamily(base: CorpusFamily<LayoutInput>, steps: readonly CorpusStep[], options?: ComposeOptions): CorpusFamily<LayoutInput>;
|
|
1445
|
+
/**
|
|
1446
|
+
* The step `edges` of `edgeStep` (version 1), as a corpus step. Its family part is `e-<edgeDensity>.<edgeShape>.<groups>.<ports>`.
|
|
1447
|
+
* The value `random` of `hubBy` adds the part `.hub-random`.
|
|
1448
|
+
*/
|
|
1449
|
+
export declare const EDGES_STEP: CorpusStep;
|
|
1450
|
+
/**
|
|
1451
|
+
* The shared family `rect-scattered`, version 1: a fixed rectangle container, rectangle obstacles at random places and boxes without positions.
|
|
1452
|
+
* It is the one copy of the generator of `docs/FORMAT.md` of `packing`. Its input is the input of `packing`, byte for byte.
|
|
1453
|
+
* The steps `container`, `obstacles` and `boxes` each have a stream of `stepRandom`. Each value is a whole number, so the family is `exact`.
|
|
1454
|
+
*/
|
|
1455
|
+
export declare const RECT_SCATTERED: CorpusFamily<LayoutInput>;
|
|
1131
1456
|
//# sourceMappingURL=index.d.ts.map
|