@mark1russell7/layout-contract 0.2.20 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -1
- package/build/index.d.ts +21 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +146 -14
- package/build/index.js.map +1 -1
- package/build/text.d.ts.map +1 -1
- package/build/text.js +27 -2
- package/build/text.js.map +1 -1
- package/package.json +1 -1
- package/src/hash.ts +7 -6
- package/src/record.ts +82 -3
- package/src/text.ts +34 -4
- package/src/utf8.ts +48 -9
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The package has no runtime dependencies.
|
|
|
12
12
|
| The shape kinds | `ShapeKind`, `SHAPE_KINDS`, `SHAPE_KIND_IDS`, `ShapeKindSpec`, `ShapeGeometry`, `DEFAULT_SHAPES`, `ShapeSupport`, `ShapeBound`, `RuleLevel`, `ShapeLevel`, `ShapeCheck`, `isShapeKind`, `shapeKindOf`, `shapeKindsOf`, `itemShapeOf`, `shapeKindProblem`, `shapesOf`, `ruleLevel`, `shapeLevel`, `shapeSupportProblems`, `boxArea`, `checkShapes` |
|
|
13
13
|
| The input `layout-input/1` | `LayoutInput`, `LayoutBox` (`Item` for the packer), `Port`, `portPoint`, `LayoutEdge`, `LayoutContainer`, `Obstacle`, `LayoutCell`, `LayoutGenerator`, `PairGap`, `canonicalInput` |
|
|
14
14
|
| The packer | `PackInput`, `toPackInput`, `Placement`, `PackOutput`, `StageTrace`, `applyPack` |
|
|
15
|
-
| The record `layout-record/1` | `LayoutRecord`, `Stage`, `Supports`, `RunFacts`, `RunEnv`, `toLayoutRecord` |
|
|
15
|
+
| The record `layout-record/1` | `LayoutRecord`, `Stage`, `Supports`, `RunFacts`, `RunEnv`, `toLayoutRecord`, `checkLayoutRecord`, `parseLayoutRecord` |
|
|
16
16
|
| The strategies | `StrategyInfo` |
|
|
17
17
|
| The measures | `MeasureSpec`, `Direction`, `JointMeasureId`, `JOINT_MEASURES`, `JOINT_MOVED_MIN`, `Verdict`, `compareMeasure`, `minEffectOf` |
|
|
18
18
|
| The balance and stability measures | `balanceOf`, `Balance`, `nearestGaps`, `procrustesOf`, `ProcrustesOptions`, `perChange`, `balanceMeasures`, `balanceMeasureSpecs`, `BALANCE_MEASURE_SUFFIXES`, `BalanceMeasureSuffix`, `BALANCE_SIDE_DEPTH`, `PlacedBox` |
|
|
@@ -69,6 +69,13 @@ The package has no runtime dependencies.
|
|
|
69
69
|
- **The output hash.** `outputHash` gives the first 16 hex characters of the SHA-256 of the canonical JSON of an output. Each number goes to the grid of `RECORD_EPS` first.
|
|
70
70
|
- **The corpus checks.** `checkDeclared` and `checkSplit` give a list of `ClaimBreak`. An empty list tells that each claim is true. `corpusHashOf` gives the corpus hash of `packing`.
|
|
71
71
|
- **The verdict.** `verdict` compares two strategies on one measure, with the family as the unit. A verdict counts only when it holds for the mean of the family means and for the mean of the inputs.
|
|
72
|
+
- **The record.** A run writes one `layout-record/1` line of JSON Lines. The formats of the engines tell the fields. These rules are new in 0.3.0:
|
|
73
|
+
- `deterministic` is `true` when two runs with the same seed give the same output. A skipped record has `null`, because no run made a claim.
|
|
74
|
+
- A record without `skipped` has a boolean `deterministic`. `checkLayoutRecord` refuses `null` on it.
|
|
75
|
+
- An old skipped record has `deterministic: true`. `checkLayoutRecord` accepts it, and `parseLayoutRecord` gives `null` in its place.
|
|
76
|
+
- `env` gives the computer of the run: `node`, `os`, `arch`, `runner`, `cpu` and `cpus`. A timing record also gives `mode`, and it can give `context`.
|
|
77
|
+
- `env.mode` is the mode of the timing, for example `process` or `fresh` of `paired-time/1`. `env.context` is `ci` or `local`, with the Node flags.
|
|
78
|
+
- `checkLayoutRecord(value)` gives the problems of one record. `parseLayoutRecord(value)` throws a `TypeError` with them. Both accept fields that the format does not know.
|
|
72
79
|
- **The tolerances.** `EPS` (`1e-6`) is for the float compares in an engine. `RECORD_EPS` (`1e-3`) is for the compares on a written file. A record writes the tolerance of each hard rule in its field `tolerance`. The defaults are `overlap` `0.001` and `through` `0.5`.
|
|
73
80
|
|
|
74
81
|
## An example
|
package/build/index.d.ts
CHANGED
|
@@ -90,8 +90,11 @@ export interface LayoutRecord {
|
|
|
90
90
|
readonly hard: Readonly<Record<string, number>>;
|
|
91
91
|
/** The tolerance of each hard rule of the run. */
|
|
92
92
|
readonly tolerance?: Readonly<Partial<Tolerance>>;
|
|
93
|
-
/**
|
|
94
|
-
|
|
93
|
+
/**
|
|
94
|
+
* The value is `true` when two runs with the same seed give the same positions.
|
|
95
|
+
* A skipped record has `null`, because no run made a claim. Each other record has a boolean.
|
|
96
|
+
*/
|
|
97
|
+
readonly deterministic: boolean | null;
|
|
95
98
|
/** The id of the prediction that was written before the run. */
|
|
96
99
|
readonly prediction?: string;
|
|
97
100
|
/** The median of `msRuns`, or the time of the one run. */
|
|
@@ -125,6 +128,10 @@ export interface RunEnv {
|
|
|
125
128
|
readonly cpu: string;
|
|
126
129
|
/** The count of the logical processors. */
|
|
127
130
|
readonly cpus: number;
|
|
131
|
+
/** The mode of the timing, for example `process` or `fresh` of `paired-time/1`. Each timing record names its mode. */
|
|
132
|
+
readonly mode?: string;
|
|
133
|
+
/** The context of the run, for example `ci` or `local`, with the Node flags. */
|
|
134
|
+
readonly context?: string;
|
|
128
135
|
}
|
|
129
136
|
/** The facts of a run that the input does not give. */
|
|
130
137
|
export type RunFacts = Omit<LayoutRecord, "schema" | "input" | "inputHash" | "set" | "nodes" | "edges" | "shapes">;
|
|
@@ -133,6 +140,18 @@ export type RunFacts = Omit<LayoutRecord, "schema" | "input" | "inputHash" | "se
|
|
|
133
140
|
* The input also gives `shapes`. An input with only `rect` boxes gets no `shapes`, so its record does not change.
|
|
134
141
|
*/
|
|
135
142
|
export declare function toLayoutRecord(input: LayoutInput, run: RunFacts): LayoutRecord;
|
|
143
|
+
/**
|
|
144
|
+
* This function gives the problems of one `layout-record/1` value. An empty list means a good record.
|
|
145
|
+
* A record that has `skipped` has `deterministic: null`. An old skipped record with a boolean is also correct.
|
|
146
|
+
* A record without `skipped` has a boolean. The check accepts fields that the format does not know.
|
|
147
|
+
*/
|
|
148
|
+
export declare function checkLayoutRecord(value: unknown): string[];
|
|
149
|
+
/**
|
|
150
|
+
* This function reads one `layout-record/1` value, for example one parsed line of a JSON Lines file.
|
|
151
|
+
* It throws a `TypeError` with the problems of `checkLayoutRecord`.
|
|
152
|
+
* An old skipped record has a boolean `deterministic`. The result has `null` in its place, because no run made that claim.
|
|
153
|
+
*/
|
|
154
|
+
export declare function parseLayoutRecord(value: unknown): LayoutRecord;
|
|
136
155
|
/** This function gives the area of a placed box: its shape or its rectangle, at its position. A box without a position gives `undefined`. */
|
|
137
156
|
export declare function placedRect(box: LayoutBox): Rect | undefined;
|
|
138
157
|
/**
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/tolerance.ts","../src/output.ts","../src/record.ts","../src/rules.ts","../src/turn.ts","../src/balance.ts","../src/strategy.ts","../src/random.ts","../src/edges.ts","../src/hash.ts","../src/portfolio.ts","../src/strategy-space.ts","../src/verdict.ts","../src/families.ts"],"mappings":";;qBACa;;;;;qBAMA;;;;;qBAMA;;;;;iBAMI;;WAEN;;WAEA;;;;;;qBAOE,mBAAmB;;iBCzBf;WACN;WACA;WACA;WACA;;;iBAIM;WACN;WACA;WACA,WAAW,SAAS;;;iBAId;WACN,qBAAqB;;WAErB;;WAEA;aAAiB;aAAoB;;;WAErC;aAA2B;aAAqB;aAAoB;;WACpE,iBAAiB;;;;;;;wBAQZ,UAAU,OAAO,aAAa,QAAQ,aAAa;;YC/BvD;;iBAGK;WACN;WACA,OAAO;WACP;WACA;;WAEA,SAAS,SAAS;WAClB;;WAEA;;WAEA;WACA;WACA;WACA;WACA;;WAEA,kBAAkB;;WAElB,UAAU,SAAS;;WAEnB,MAAM,SAAS;;WAEf,YAAY,SAAS,QAAQ;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/tolerance.ts","../src/output.ts","../src/record.ts","../src/rules.ts","../src/turn.ts","../src/balance.ts","../src/strategy.ts","../src/random.ts","../src/edges.ts","../src/hash.ts","../src/portfolio.ts","../src/strategy-space.ts","../src/verdict.ts","../src/families.ts"],"mappings":";;qBACa;;;;;qBAMA;;;;;qBAMA;;;;;iBAMI;;WAEN;;WAEA;;;;;;qBAOE,mBAAmB;;iBCzBf;WACN;WACA;WACA;WACA;;;iBAIM;WACN;WACA;WACA,WAAW,SAAS;;;iBAId;WACN,qBAAqB;;WAErB;;WAEA;aAAiB;aAAoB;;;WAErC;aAA2B;aAAqB;aAAoB;;WACpE,iBAAiB;;;;;;;wBAQZ,UAAU,OAAO,aAAa,QAAQ,aAAa;;YC/BvD;;iBAGK;WACN;WACA,OAAO;WACP;WACA;;WAEA,SAAS,SAAS;WAClB;;WAEA;;WAEA;WACA;WACA;WACA;WACA;;WAEA,kBAAkB;;WAElB,UAAU,SAAS;;WAEnB,MAAM,SAAS;;WAEf,YAAY,SAAS,QAAQ;;;;;WAK7B;;WAEA;;WAEA;;WAEA;;;;;WAKA;;WAEA,MAAM;;WAEN;WACA;;;;;;YAOC,WAAW,SAAS;;iBAGf;WACN;WACA;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;YAIC,WAAW,KAAK;;;;;wBAMZ,eAAe,OAAO,aAAa,KAAK,WAAW;;;;;;wBAkDnD,kBAAkB;;;;;;wBA8BlB,kBAAkB,iBAAiB;;wBC9JnC,WAAW,KAAK,YAAY;;;;;;;;wBAc5B,cAAc,gBAAgB,aAAa,oBAA+C,oBAAoB;;iBAkD7G;;;;;WAKN;;;;;;;;;;wBAWK,aAAa,OAAO,aAAa,oBAA+C,UAAS;;wBAsBzF,oBAAoB,gBAAgB,aAAa;;iBAehD;WACN;WACA;WACA;WACA;;;;;;;;qBASE,0BAA0B,mBAAmB;;wBAQ1C,eAAe,QAAQ,QAAQ,MAAM;;;;;wBAgCrC,aAAa,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,gBAAgB,aAAa"}
|
package/build/index.js
CHANGED
|
@@ -556,6 +556,100 @@ function toLayoutRecord(input, run) {
|
|
|
556
556
|
...onlyRect ? {} : { shapes }
|
|
557
557
|
};
|
|
558
558
|
}
|
|
559
|
+
const isFields = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
560
|
+
const STAGES = [
|
|
561
|
+
"pack",
|
|
562
|
+
"route",
|
|
563
|
+
"joint"
|
|
564
|
+
];
|
|
565
|
+
const RECORD_STRINGS = [
|
|
566
|
+
"step",
|
|
567
|
+
"strategy",
|
|
568
|
+
"corpus",
|
|
569
|
+
"input",
|
|
570
|
+
"inputHash",
|
|
571
|
+
"set"
|
|
572
|
+
];
|
|
573
|
+
const RECORD_NUMBERS = [
|
|
574
|
+
"seed",
|
|
575
|
+
"nodes",
|
|
576
|
+
"edges",
|
|
577
|
+
"ms"
|
|
578
|
+
];
|
|
579
|
+
const RECORD_OPTIONAL_STRINGS = [
|
|
580
|
+
"prediction",
|
|
581
|
+
"outputHash",
|
|
582
|
+
"skipped",
|
|
583
|
+
"commit"
|
|
584
|
+
];
|
|
585
|
+
const ENV_STRINGS = [
|
|
586
|
+
"node",
|
|
587
|
+
"os",
|
|
588
|
+
"arch",
|
|
589
|
+
"runner",
|
|
590
|
+
"cpu"
|
|
591
|
+
];
|
|
592
|
+
const ENV_OPTIONAL_STRINGS = ["mode", "context"];
|
|
593
|
+
/** This function adds a problem for each value of a map that is not a number. */
|
|
594
|
+
function numberMap(out, v, name) {
|
|
595
|
+
if (!isFields(v)) {
|
|
596
|
+
out.push(`${name} is not an object`);
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
for (const [key, n] of Object.entries(v)) if (typeof n !== "number") out.push(`${name}.${key} is not a number`);
|
|
600
|
+
}
|
|
601
|
+
/** This function gives the problems of the field `env` of a record. */
|
|
602
|
+
function envProblems(env) {
|
|
603
|
+
if (!isFields(env)) return ["env is not an object"];
|
|
604
|
+
const out = [];
|
|
605
|
+
for (const key of ENV_STRINGS) if (typeof env[key] !== "string") out.push(`env.${key} is not a string`);
|
|
606
|
+
if (typeof env["cpus"] !== "number") out.push("env.cpus is not a number");
|
|
607
|
+
for (const key of ENV_OPTIONAL_STRINGS) if (env[key] !== void 0 && typeof env[key] !== "string") out.push(`env.${key} is not a string`);
|
|
608
|
+
return out;
|
|
609
|
+
}
|
|
610
|
+
/**
|
|
611
|
+
* This function gives the problems of one `layout-record/1` value. An empty list means a good record.
|
|
612
|
+
* A record that has `skipped` has `deterministic: null`. An old skipped record with a boolean is also correct.
|
|
613
|
+
* A record without `skipped` has a boolean. The check accepts fields that the format does not know.
|
|
614
|
+
*/
|
|
615
|
+
function checkLayoutRecord(value) {
|
|
616
|
+
if (!isFields(value)) return ["the record is not an object"];
|
|
617
|
+
const out = [];
|
|
618
|
+
const v = value;
|
|
619
|
+
if (v["schema"] !== "layout-record/1") out.push("schema is not layout-record/1");
|
|
620
|
+
if (typeof v["stage"] !== "string" || !STAGES.includes(v["stage"])) out.push("stage is not pack, route or joint");
|
|
621
|
+
for (const key of RECORD_STRINGS) if (typeof v[key] !== "string") out.push(`${key} is not a string`);
|
|
622
|
+
for (const key of RECORD_NUMBERS) if (typeof v[key] !== "number") out.push(`${key} is not a number`);
|
|
623
|
+
for (const key of RECORD_OPTIONAL_STRINGS) if (v[key] !== void 0 && typeof v[key] !== "string") out.push(`${key} is not a string`);
|
|
624
|
+
if (!isFields(v["options"])) out.push("options is not an object");
|
|
625
|
+
numberMap(out, v["measures"], "measures");
|
|
626
|
+
numberMap(out, v["hard"], "hard");
|
|
627
|
+
if (v["tolerance"] !== void 0) numberMap(out, v["tolerance"], "tolerance");
|
|
628
|
+
const shapes = v["shapes"];
|
|
629
|
+
if (shapes !== void 0 && (!Array.isArray(shapes) || !shapes.every(isShapeKind))) out.push("shapes is not a list of shape kinds");
|
|
630
|
+
const msRuns = v["msRuns"];
|
|
631
|
+
if (msRuns !== void 0 && (!Array.isArray(msRuns) || !msRuns.every((n) => typeof n === "number"))) out.push("msRuns is not a list of numbers");
|
|
632
|
+
if (v["env"] !== void 0) out.push(...envProblems(v["env"]));
|
|
633
|
+
const deterministic = v["deterministic"];
|
|
634
|
+
if (v["skipped"] === void 0) {
|
|
635
|
+
if (typeof deterministic !== "boolean") out.push("deterministic is not a boolean, and the record has no skipped");
|
|
636
|
+
} else if (deterministic !== null && typeof deterministic !== "boolean") out.push("deterministic of a skipped record is not null or a boolean");
|
|
637
|
+
return out;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* This function reads one `layout-record/1` value, for example one parsed line of a JSON Lines file.
|
|
641
|
+
* It throws a `TypeError` with the problems of `checkLayoutRecord`.
|
|
642
|
+
* An old skipped record has a boolean `deterministic`. The result has `null` in its place, because no run made that claim.
|
|
643
|
+
*/
|
|
644
|
+
function parseLayoutRecord(value) {
|
|
645
|
+
const problems = checkLayoutRecord(value);
|
|
646
|
+
if (problems.length > 0) throw new TypeError(`The record is not a layout-record/1: ${problems.join(", ")}.`);
|
|
647
|
+
const record = value;
|
|
648
|
+
return record.skipped !== void 0 && record.deterministic !== null ? {
|
|
649
|
+
...record,
|
|
650
|
+
deterministic: null
|
|
651
|
+
} : record;
|
|
652
|
+
}
|
|
559
653
|
// src/rules.ts
|
|
560
654
|
/** This function gives the area of a placed box: its shape or its rectangle, at its position. A box without a position gives `undefined`. */
|
|
561
655
|
function placedRect(box) {
|
|
@@ -1376,16 +1470,54 @@ function balanceMeasureSpecs(stage) {
|
|
|
1376
1470
|
]);
|
|
1377
1471
|
}
|
|
1378
1472
|
// src/utf8.ts
|
|
1473
|
+
/**
|
|
1474
|
+
* This function writes the UTF-8 bytes of a string into `out`, from the index `at`, and gives the index after the last byte.
|
|
1475
|
+
* With no `out`, it writes nothing and gives the count of the bytes. A lone surrogate gives the 3 bytes of its code.
|
|
1476
|
+
* It reads the UTF-16 code units, so it makes no string for each character (L81: `sha256Hex` allocated 2 GB in one pair).
|
|
1477
|
+
*/
|
|
1478
|
+
function utf8Write(text, out, at = 0) {
|
|
1479
|
+
let n = at;
|
|
1480
|
+
for (let i = 0; i < text.length; i++) {
|
|
1481
|
+
let c = text.charCodeAt(i);
|
|
1482
|
+
if (c >= 55296 && c < 56320 && i + 1 < text.length) {
|
|
1483
|
+
const low = text.charCodeAt(i + 1);
|
|
1484
|
+
if (low >= 56320 && low < 57344) {
|
|
1485
|
+
c = 65536 + (c - 55296 << 10) + (low - 56320);
|
|
1486
|
+
i++;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
if (c < 128) {
|
|
1490
|
+
if (out !== void 0) out[n] = c;
|
|
1491
|
+
n += 1;
|
|
1492
|
+
} else if (c < 2048) {
|
|
1493
|
+
if (out !== void 0) {
|
|
1494
|
+
out[n] = 192 | c >> 6;
|
|
1495
|
+
out[n + 1] = 128 | c & 63;
|
|
1496
|
+
}
|
|
1497
|
+
n += 2;
|
|
1498
|
+
} else if (c < 65536) {
|
|
1499
|
+
if (out !== void 0) {
|
|
1500
|
+
out[n] = 224 | c >> 12;
|
|
1501
|
+
out[n + 1] = 128 | c >> 6 & 63;
|
|
1502
|
+
out[n + 2] = 128 | c & 63;
|
|
1503
|
+
}
|
|
1504
|
+
n += 3;
|
|
1505
|
+
} else {
|
|
1506
|
+
if (out !== void 0) {
|
|
1507
|
+
out[n] = 240 | c >> 18;
|
|
1508
|
+
out[n + 1] = 128 | c >> 12 & 63;
|
|
1509
|
+
out[n + 2] = 128 | c >> 6 & 63;
|
|
1510
|
+
out[n + 3] = 128 | c & 63;
|
|
1511
|
+
}
|
|
1512
|
+
n += 4;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
return n;
|
|
1516
|
+
}
|
|
1379
1517
|
/** This function gives the UTF-8 bytes of a string. The package has no runtime dependencies, thus it does not use `TextEncoder`. */
|
|
1380
1518
|
function utf8(text) {
|
|
1381
|
-
const bytes =
|
|
1382
|
-
|
|
1383
|
-
const c = ch.codePointAt(0);
|
|
1384
|
-
if (c < 128) bytes.push(c);
|
|
1385
|
-
else if (c < 2048) bytes.push(192 | c >> 6, 128 | c & 63);
|
|
1386
|
-
else if (c < 65536) bytes.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
|
1387
|
-
else bytes.push(240 | c >> 18, 128 | c >> 12 & 63, 128 | c >> 6 & 63, 128 | c & 63);
|
|
1388
|
-
}
|
|
1519
|
+
const bytes = new Uint8Array(utf8Write(text));
|
|
1520
|
+
utf8Write(text, bytes);
|
|
1389
1521
|
return bytes;
|
|
1390
1522
|
}
|
|
1391
1523
|
// src/random.ts
|
|
@@ -1682,12 +1814,12 @@ const K = [
|
|
|
1682
1814
|
* It uses no API of Node or of the browser.
|
|
1683
1815
|
*/
|
|
1684
1816
|
function sha256Hex(text) {
|
|
1685
|
-
const
|
|
1686
|
-
const bits =
|
|
1687
|
-
const total = Math.ceil((
|
|
1817
|
+
const length = utf8Write(text);
|
|
1818
|
+
const bits = length * 8;
|
|
1819
|
+
const total = Math.ceil((length + 9) / 64) * 64;
|
|
1688
1820
|
const data = new Uint8Array(total);
|
|
1689
|
-
data
|
|
1690
|
-
data[
|
|
1821
|
+
utf8Write(text, data);
|
|
1822
|
+
data[length] = 128;
|
|
1691
1823
|
const view = new DataView(data.buffer);
|
|
1692
1824
|
view.setUint32(total - 8, Math.floor(bits / 4294967296));
|
|
1693
1825
|
view.setUint32(total - 4, bits >>> 0);
|
|
@@ -4256,6 +4388,6 @@ const RECT_SCATTERED = Object.freeze({
|
|
|
4256
4388
|
};
|
|
4257
4389
|
}
|
|
4258
4390
|
});
|
|
4259
|
-
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CORPUS_DIMENSIONS, DEFAULT_FAMILY_BY, DEFAULT_RNG, DEFAULT_SHAPES, DEFAULT_TOLERANCE, EDGES_STEP, EDGE_DENSITY, EDGE_STEP_VERSION, EPS, FAMILY_ANY_KIND, INVALIDATED_FIELD, JOINT_MEASURES, JOINT_MOVED_MIN, PACK_HARD_RULES, RECORD_EPS, RECORD_SCALE, RECT_SCATTERED, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, STRATEGY_SPACE_SCHEMA, VERDICT_DRAWS, VERDICT_EXACT_CAP, VERDICT_EXACT_MAX, VERDICT_RUNS, VERDICT_SEED, applyPack, balanceMeasureSpecs, balanceMeasures, balanceOf, boundsOf, boxArea, canonicalConfig, canonicalInput, canonicalJson, checkConfig, checkDeclared, checkInput, checkShapes, checkSpace, checkSplit, compareMeasure, composeFamily, configId, corpusHashOf, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, createFamilyRegistry, declaredClaimOf, declaredCounts, dimensionAt, dimensionSupports, dimensionUnit, documentHash, edgeStep, enumerateSpace, exercised, familyKind, familyOf, fnv1a32, grow, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, marginSides, minEffectOf, mulberry32, nearestGaps, outputGroups, outputHash, overlapOf, ownerDimension, packHard, paramActive, paramLevels, paramProblem, paramValue, perChange, pickMoves, placedRect, portPoint, portfolio, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resolveDimensions, ruleLevel, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, sharedDimension, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, toLayoutRecord, toPackInput, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnSide, verdict };
|
|
4391
|
+
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CORPUS_DIMENSIONS, DEFAULT_FAMILY_BY, DEFAULT_RNG, DEFAULT_SHAPES, DEFAULT_TOLERANCE, EDGES_STEP, EDGE_DENSITY, EDGE_STEP_VERSION, EPS, FAMILY_ANY_KIND, INVALIDATED_FIELD, JOINT_MEASURES, JOINT_MOVED_MIN, PACK_HARD_RULES, RECORD_EPS, RECORD_SCALE, RECT_SCATTERED, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, STRATEGY_SPACE_SCHEMA, VERDICT_DRAWS, VERDICT_EXACT_CAP, VERDICT_EXACT_MAX, VERDICT_RUNS, VERDICT_SEED, applyPack, balanceMeasureSpecs, balanceMeasures, balanceOf, boundsOf, boxArea, canonicalConfig, canonicalInput, canonicalJson, checkConfig, checkDeclared, checkInput, checkLayoutRecord, checkShapes, checkSpace, checkSplit, compareMeasure, composeFamily, configId, corpusHashOf, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, createFamilyRegistry, declaredClaimOf, declaredCounts, dimensionAt, dimensionSupports, dimensionUnit, documentHash, edgeStep, enumerateSpace, exercised, familyKind, familyOf, fnv1a32, grow, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, marginSides, minEffectOf, mulberry32, nearestGaps, outputGroups, outputHash, overlapOf, ownerDimension, packHard, paramActive, paramLevels, paramProblem, paramValue, parseLayoutRecord, perChange, pickMoves, placedRect, portPoint, portfolio, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resolveDimensions, ruleLevel, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, sharedDimension, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, toLayoutRecord, toPackInput, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnSide, verdict };
|
|
4260
4392
|
|
|
4261
4393
|
//# sourceMappingURL=index.js.map
|