@mark1russell7/layout-contract 0.4.0 → 0.5.1
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 +5 -5
- package/build/index.d.ts +90 -8
- package/build/index.d.ts.map +1 -1
- package/build/index.js +334 -11
- package/build/index.js.map +1 -1
- package/build/{measures-KWg_was6.d.ts → measures-COqcrCzv.d.ts} +8 -3
- package/build/measures-COqcrCzv.d.ts.map +1 -0
- package/build/text.d.ts +1 -1
- package/package.json +1 -1
- package/src/families.ts +56 -0
- package/src/geometry.ts +11 -0
- package/src/measures.ts +2 -0
- package/src/record.ts +7 -3
- package/src/rules.ts +104 -1
- package/src/strategy-catalog.ts +140 -10
- package/src/tolerance.ts +3 -0
- package/build/measures-KWg_was6.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -166,6 +166,19 @@ function opposite(p, q) {
|
|
|
166
166
|
function segmentsCross(a, b, c, d) {
|
|
167
167
|
return opposite(orient(c, d, a), orient(c, d, b)) && opposite(orient(a, b, c), orient(a, b, d));
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* This function gives the point where the segments `ab` and `cd` cross, or `undefined`.
|
|
171
|
+
* It gives a point exactly when `segmentsCross` is true, so a touch at an end and collinear segments give `undefined`.
|
|
172
|
+
*/
|
|
173
|
+
function crossingPoint(a, b, c, d) {
|
|
174
|
+
if (!segmentsCross(a, b, c, d)) return void 0;
|
|
175
|
+
const from = orient(c, d, a);
|
|
176
|
+
const t = from / (from - orient(c, d, b));
|
|
177
|
+
return {
|
|
178
|
+
x: a.x + t * (b.x - a.x),
|
|
179
|
+
y: a.y + t * (b.y - a.y)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
169
182
|
/** This function gives the shortest distance from `p` to the segment `ab`. A segment of length 0 is the point `a`. */
|
|
170
183
|
function pointSegmentDistance(p, a, b) {
|
|
171
184
|
const dx = b.x - a.x;
|
|
@@ -402,6 +415,8 @@ function checkShapes(input, uses, options = {}) {
|
|
|
402
415
|
// src/tolerance.ts
|
|
403
416
|
/** The epsilon for the float compares in an engine. */
|
|
404
417
|
const EPS = 1e-6;
|
|
418
|
+
/** The count of `EPS` steps in one layout unit. It is the integer equal to `1 / EPS`. */
|
|
419
|
+
const EPS_STEPS = 1e6;
|
|
405
420
|
/**
|
|
406
421
|
* 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`.
|
|
407
422
|
* Use a multiplication by this value, not a division by `RECORD_EPS`. The two differ at some half steps.
|
|
@@ -725,7 +740,7 @@ function hardRuleOf(record) {
|
|
|
725
740
|
/**
|
|
726
741
|
* This function gives the problems of one `layout-record/1` value. An empty list means a good record.
|
|
727
742
|
* A record that has `skipped` has `deterministic: null`. An old skipped record with a boolean is also correct.
|
|
728
|
-
* A record without `skipped` has a boolean
|
|
743
|
+
* A record without `skipped` has a boolean, or `null` when it has `oneRun: true`. The check accepts fields that the format does not know.
|
|
729
744
|
*/
|
|
730
745
|
function checkLayoutRecord(value) {
|
|
731
746
|
if (!isFields$1(value)) return ["the record is not an object"];
|
|
@@ -751,7 +766,8 @@ function checkLayoutRecord(value) {
|
|
|
751
766
|
if (v["env"] !== void 0) out.push(...envProblems(v["env"]));
|
|
752
767
|
const deterministic = v["deterministic"];
|
|
753
768
|
if (v["skipped"] === void 0) {
|
|
754
|
-
|
|
769
|
+
const noClaim = deterministic === null && v["oneRun"] === true;
|
|
770
|
+
if (typeof deterministic !== "boolean" && !noClaim) out.push("deterministic is not a boolean, and the record has no skipped");
|
|
755
771
|
} else if (deterministic !== null && typeof deterministic !== "boolean") out.push("deterministic of a skipped record is not null or a boolean");
|
|
756
772
|
return out;
|
|
757
773
|
}
|
|
@@ -975,6 +991,111 @@ function circlesOutside(input, tolerance = DEFAULT_TOLERANCE.overlap) {
|
|
|
975
991
|
}
|
|
976
992
|
return count;
|
|
977
993
|
}
|
|
994
|
+
/** This function gives the length of the part of the segment `ab` inside a circle. A radius of 0 or less gives 0. */
|
|
995
|
+
function partInCircle(a, b, cx, cy, r) {
|
|
996
|
+
if (r <= 0) return 0;
|
|
997
|
+
const dx = b.x - a.x;
|
|
998
|
+
const dy = b.y - a.y;
|
|
999
|
+
const fx = a.x - cx;
|
|
1000
|
+
const fy = a.y - cy;
|
|
1001
|
+
const l2 = dx * dx + dy * dy;
|
|
1002
|
+
if (l2 === 0) return 0;
|
|
1003
|
+
const half = fx * dx + fy * dy;
|
|
1004
|
+
const inner = half * half - l2 * (fx * fx + fy * fy - r * r);
|
|
1005
|
+
if (inner <= 0) return 0;
|
|
1006
|
+
const root = Math.sqrt(inner);
|
|
1007
|
+
const t0 = Math.max(0, (-half - root) / l2);
|
|
1008
|
+
const t1 = Math.min(1, (-half + root) / l2);
|
|
1009
|
+
return t1 > t0 ? (t1 - t0) * Math.sqrt(l2) : 0;
|
|
1010
|
+
}
|
|
1011
|
+
/** This function gives the length of the part of the segment `ab` inside the open box from (`x0`, `y0`) to (`x1`, `y1`). A box with no inside gives 0. */
|
|
1012
|
+
function partInBox(a, b, x0, y0, x1, y1) {
|
|
1013
|
+
if (x1 <= x0 || y1 <= y0) return 0;
|
|
1014
|
+
const dx = b.x - a.x;
|
|
1015
|
+
const dy = b.y - a.y;
|
|
1016
|
+
let t0 = 0;
|
|
1017
|
+
let t1 = 1;
|
|
1018
|
+
for (const [from, d, lo, hi] of [[
|
|
1019
|
+
a.x,
|
|
1020
|
+
dx,
|
|
1021
|
+
x0,
|
|
1022
|
+
x1
|
|
1023
|
+
], [
|
|
1024
|
+
a.y,
|
|
1025
|
+
dy,
|
|
1026
|
+
y0,
|
|
1027
|
+
y1
|
|
1028
|
+
]]) {
|
|
1029
|
+
if (d === 0) {
|
|
1030
|
+
if (from <= lo || from >= hi) return 0;
|
|
1031
|
+
continue;
|
|
1032
|
+
}
|
|
1033
|
+
const ta = (lo - from) / d;
|
|
1034
|
+
const tb = (hi - from) / d;
|
|
1035
|
+
t0 = Math.max(t0, Math.min(ta, tb));
|
|
1036
|
+
t1 = Math.min(t1, Math.max(ta, tb));
|
|
1037
|
+
if (t0 > t1) return 0;
|
|
1038
|
+
}
|
|
1039
|
+
return (t1 - t0) * Math.sqrt(dx * dx + dy * dy);
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* This function tells if the segment `ab` goes through a placed box, by the rule of `Tolerance.through`.
|
|
1043
|
+
* A part of the segment longer than `tolerance` is inside the shape made `tolerance` smaller.
|
|
1044
|
+
*
|
|
1045
|
+
* - A circle box reads its circle. Each other kind reads its bounding box, so on a polygon or a free shape the answer is an upper bound.
|
|
1046
|
+
* - The margin of the box does not count. A box without a position gives `false`.
|
|
1047
|
+
*/
|
|
1048
|
+
function segmentThroughShape(a, b, box, tolerance = DEFAULT_TOLERANCE.through) {
|
|
1049
|
+
const disc = placedCircle(box);
|
|
1050
|
+
if (disc !== void 0) return partInCircle(a, b, disc.cx, disc.cy, disc.r - tolerance) > tolerance;
|
|
1051
|
+
const r = placedRect(box);
|
|
1052
|
+
if (r === void 0) return false;
|
|
1053
|
+
return partInBox(a, b, r.x + tolerance, r.y + tolerance, r.x + r.w - tolerance, r.y + r.h - tolerance) > tolerance;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* This function counts the routes that go through a placed box that is not one of their two ends, by `segmentThroughShape`.
|
|
1057
|
+
* A route counts once, also when it goes through more than one box.
|
|
1058
|
+
*/
|
|
1059
|
+
function countLinksThroughShapes(boxes, links, tolerance = DEFAULT_TOLERANCE.through) {
|
|
1060
|
+
const placed = boxes.flatMap((box) => {
|
|
1061
|
+
const r = placedRect(box);
|
|
1062
|
+
return r === void 0 ? [] : [{
|
|
1063
|
+
box,
|
|
1064
|
+
r
|
|
1065
|
+
}];
|
|
1066
|
+
});
|
|
1067
|
+
placed.sort((p, q) => p.r.x - q.r.x);
|
|
1068
|
+
const widest = placed.reduce((m, p) => Math.max(m, p.r.w), 0);
|
|
1069
|
+
const firstAt = (x) => {
|
|
1070
|
+
let lo = 0;
|
|
1071
|
+
let hi = placed.length;
|
|
1072
|
+
while (lo < hi) {
|
|
1073
|
+
const mid = lo + hi >>> 1;
|
|
1074
|
+
if (placed[mid].r.x < x) lo = mid + 1;
|
|
1075
|
+
else hi = mid;
|
|
1076
|
+
}
|
|
1077
|
+
return lo;
|
|
1078
|
+
};
|
|
1079
|
+
let count = 0;
|
|
1080
|
+
for (const link of links) {
|
|
1081
|
+
let hit = false;
|
|
1082
|
+
for (let i = 1; i < link.points.length && !hit; i++) {
|
|
1083
|
+
const a = link.points[i - 1];
|
|
1084
|
+
const b = link.points[i];
|
|
1085
|
+
const left = Math.min(a.x, b.x);
|
|
1086
|
+
const right = Math.max(a.x, b.x);
|
|
1087
|
+
const top = Math.min(a.y, b.y);
|
|
1088
|
+
const bottom = Math.max(a.y, b.y);
|
|
1089
|
+
for (let k = firstAt(left - widest); k < placed.length && placed[k].r.x < right && !hit; k++) {
|
|
1090
|
+
const { box, r } = placed[k];
|
|
1091
|
+
if (r.x + r.w <= left || r.y >= bottom || r.y + r.h <= top) continue;
|
|
1092
|
+
if (box.id !== link.source && box.id !== link.target && segmentThroughShape(a, b, box, tolerance)) hit = true;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (hit) count++;
|
|
1096
|
+
}
|
|
1097
|
+
return count;
|
|
1098
|
+
}
|
|
978
1099
|
/**
|
|
979
1100
|
* This function counts the placed boxes that go out of the container.
|
|
980
1101
|
* Each box with its margin must stay inside the container made smaller by `inset`. Only the fixed sides of the size count. A shaped container counts as its bounding box.
|
|
@@ -1416,6 +1537,15 @@ const JOINT_MEASURES = /* @__PURE__ */ Object.freeze([
|
|
|
1416
1537
|
role: "diagnostic",
|
|
1417
1538
|
shapes: BOUNDS_ONLY
|
|
1418
1539
|
},
|
|
1540
|
+
{
|
|
1541
|
+
id: "joint.route.length",
|
|
1542
|
+
unit: "layout units for each route",
|
|
1543
|
+
direction: "lower",
|
|
1544
|
+
min: 0,
|
|
1545
|
+
max: Infinity,
|
|
1546
|
+
role: "diagnostic",
|
|
1547
|
+
shapes: BOUNDS_ONLY
|
|
1548
|
+
},
|
|
1419
1549
|
{
|
|
1420
1550
|
id: "joint.ms",
|
|
1421
1551
|
unit: "milliseconds",
|
|
@@ -3921,13 +4051,30 @@ function checkSchema(strategy) {
|
|
|
3921
4051
|
return out;
|
|
3922
4052
|
}
|
|
3923
4053
|
// src/strategy-catalog.ts
|
|
3924
|
-
/** The schema of a strategy catalog. A new field is a new version of the schema. */
|
|
3925
|
-
const STRATEGY_CATALOG_SCHEMA = "strategy-catalog/
|
|
4054
|
+
/** The newest schema of a strategy catalog. A new field is a new version of the schema. */
|
|
4055
|
+
const STRATEGY_CATALOG_SCHEMA = "strategy-catalog/2";
|
|
4056
|
+
/** The schemas that `parseStrategyCatalog` reads, oldest first. Schema 2 adds the field `output` of an entry. */
|
|
4057
|
+
const STRATEGY_CATALOG_SCHEMAS = ["strategy-catalog/1", STRATEGY_CATALOG_SCHEMA];
|
|
3926
4058
|
/**
|
|
3927
4059
|
* The dimension of `supports` that tells who owns the positions of the nodes. The value `host` means that the strategy keeps the positions that the host gives.
|
|
3928
4060
|
* The value `engine` means that the strategy can set them. A strategy that moves nodes has only `engine`. A `SupportProbe` tests the claim with a run.
|
|
3929
4061
|
*/
|
|
3930
4062
|
const NODE_POSITIONS_DIMENSION = "nodePositions";
|
|
4063
|
+
/** The output properties that tell if the numbers of a result are whole: the positions and the sizes. The parser examines the class of these properties. */
|
|
4064
|
+
const OUTPUT_GRID_PROPERTIES = ["position-grid", "size-grid"];
|
|
4065
|
+
/** The largest distance from a whole number for a near-whole value. A value at a larger distance is fractional. */
|
|
4066
|
+
const OUTPUT_NEAR_WHOLE = 1e-9;
|
|
4067
|
+
/** The fewest packed inputs for the class `whole` or `near-whole`. A fraction needs no such count, because one counterexample is a proof. */
|
|
4068
|
+
const OUTPUT_CLASS_MIN_INPUTS = 30;
|
|
4069
|
+
/**
|
|
4070
|
+
* This function gives the class of a grid property from its counts. One fractional input gives `fractional` at any count.
|
|
4071
|
+
* With no fraction, fewer than `OUTPUT_CLASS_MIN_INPUTS` inputs give `untested`. Each other read gives `near-whole` or `whole`.
|
|
4072
|
+
*/
|
|
4073
|
+
function outputGridClass(counts) {
|
|
4074
|
+
if (counts.fractionalInputs > 0) return "fractional";
|
|
4075
|
+
if (counts.inputs < 30) return "untested";
|
|
4076
|
+
return counts.nearWholeInputs > 0 ? "near-whole" : "whole";
|
|
4077
|
+
}
|
|
3931
4078
|
const STRATEGY_KINDS = [
|
|
3932
4079
|
"single",
|
|
3933
4080
|
"composite",
|
|
@@ -3959,6 +4106,7 @@ const ENTRY_FIELDS = [
|
|
|
3959
4106
|
"determinismNote",
|
|
3960
4107
|
"optIn",
|
|
3961
4108
|
"baseline",
|
|
4109
|
+
"output",
|
|
3962
4110
|
"options"
|
|
3963
4111
|
];
|
|
3964
4112
|
const COMMON_FIELDS = [
|
|
@@ -4003,6 +4151,19 @@ const LIST_FIELDS = [
|
|
|
4003
4151
|
"min",
|
|
4004
4152
|
"max"
|
|
4005
4153
|
];
|
|
4154
|
+
const ROW_FIELDS = [
|
|
4155
|
+
"property",
|
|
4156
|
+
"class",
|
|
4157
|
+
"evidence"
|
|
4158
|
+
];
|
|
4159
|
+
const EVIDENCE_FIELDS = [
|
|
4160
|
+
"inputs",
|
|
4161
|
+
"fractionalInputs",
|
|
4162
|
+
"nearWholeInputs",
|
|
4163
|
+
"source",
|
|
4164
|
+
"optionSet",
|
|
4165
|
+
"catalogVersion"
|
|
4166
|
+
];
|
|
4006
4167
|
/** The fields of a declaration, in the order of the file. */
|
|
4007
4168
|
const OPTION_ORDER = [
|
|
4008
4169
|
"type",
|
|
@@ -4256,8 +4417,61 @@ function checkLimits(at, limits, faults) {
|
|
|
4256
4417
|
if (isFiniteNumber(raw["min"]) && isFiniteNumber(raw["max"]) && raw["min"] > raw["max"]) faults.push(`${place}: "min" is more than "max".`);
|
|
4257
4418
|
}
|
|
4258
4419
|
}
|
|
4420
|
+
/** This function adds the faults of the evidence of one output row. */
|
|
4421
|
+
function checkEvidence(at, property, rowClass, raw, faults) {
|
|
4422
|
+
if (!isFields(raw)) {
|
|
4423
|
+
faults.push(`${at}: "evidence" is not an object.`);
|
|
4424
|
+
return;
|
|
4425
|
+
}
|
|
4426
|
+
refuseUnknown(`${at}: the evidence`, raw, EVIDENCE_FIELDS, faults);
|
|
4427
|
+
for (const f of [
|
|
4428
|
+
"source",
|
|
4429
|
+
"optionSet",
|
|
4430
|
+
"catalogVersion"
|
|
4431
|
+
]) if (!isText(raw[f])) faults.push(`${at}: the evidence field "${f}" is not a text.`);
|
|
4432
|
+
const count = (v) => Number.isInteger(v) && v >= 0;
|
|
4433
|
+
if (!count(raw["inputs"])) faults.push(`${at}: the evidence field "inputs" is not a count.`);
|
|
4434
|
+
const grid = OUTPUT_GRID_PROPERTIES.includes(property);
|
|
4435
|
+
for (const f of ["fractionalInputs", "nearWholeInputs"]) if (grid ? !count(raw[f]) : raw[f] !== void 0 && !count(raw[f])) faults.push(`${at}: the evidence field "${f}" is not a count.`);
|
|
4436
|
+
const [inputs, fractionalInputs, nearWholeInputs] = [
|
|
4437
|
+
raw["inputs"],
|
|
4438
|
+
raw["fractionalInputs"],
|
|
4439
|
+
raw["nearWholeInputs"]
|
|
4440
|
+
];
|
|
4441
|
+
if (!grid || !count(inputs) || !count(fractionalInputs) || !count(nearWholeInputs)) return;
|
|
4442
|
+
if (fractionalInputs + nearWholeInputs > inputs) faults.push(`${at}: the fractional and near-whole counts are more than the inputs.`);
|
|
4443
|
+
const expected = outputGridClass({
|
|
4444
|
+
inputs,
|
|
4445
|
+
fractionalInputs,
|
|
4446
|
+
nearWholeInputs
|
|
4447
|
+
});
|
|
4448
|
+
if (rowClass !== expected) faults.push(`${at}: the evidence gives the class "${expected}".`);
|
|
4449
|
+
}
|
|
4450
|
+
/** This function adds the faults of the field `output` of one entry. */
|
|
4451
|
+
function checkOutput(at, raw, schema, faults) {
|
|
4452
|
+
if (schema === STRATEGY_CATALOG_SCHEMAS[0]) faults.push(`${at}: the field "output" needs the schema ${STRATEGY_CATALOG_SCHEMA}.`);
|
|
4453
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
4454
|
+
faults.push(`${at}: "output" is not a list with rows.`);
|
|
4455
|
+
return;
|
|
4456
|
+
}
|
|
4457
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4458
|
+
raw.forEach((row, i) => {
|
|
4459
|
+
const place = `${at}: the output row ${i}`;
|
|
4460
|
+
if (!isFields(row)) {
|
|
4461
|
+
faults.push(`${place} is not an object.`);
|
|
4462
|
+
return;
|
|
4463
|
+
}
|
|
4464
|
+
refuseUnknown(place, row, ROW_FIELDS, faults);
|
|
4465
|
+
for (const f of ["property", "class"]) if (!isText(row[f])) faults.push(`${place}: "${f}" is not a text.`);
|
|
4466
|
+
checkEvidence(place, row["property"], row["class"], row["evidence"], faults);
|
|
4467
|
+
const optionSet = isFields(row["evidence"]) ? row["evidence"]["optionSet"] : void 0;
|
|
4468
|
+
const name = JSON.stringify([row["property"], optionSet]);
|
|
4469
|
+
if (seen.has(name)) faults.push(`${place}: the property and the option set are not unique.`);
|
|
4470
|
+
seen.add(name);
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4259
4473
|
/** This function restores one entry of a file. */
|
|
4260
|
-
function readEntry(at, raw, faults) {
|
|
4474
|
+
function readEntry(at, raw, schema, faults) {
|
|
4261
4475
|
if (!isFields(raw)) {
|
|
4262
4476
|
faults.push(`${at} is not an object.`);
|
|
4263
4477
|
return;
|
|
@@ -4278,6 +4492,7 @@ function readEntry(at, raw, faults) {
|
|
|
4278
4492
|
if (raw["baseline"] === true && raw["optIn"] !== true) faults.push(`${at}: a baseline has "optIn" true.`);
|
|
4279
4493
|
if (!isFields(raw["supports"]) || !Object.values(raw["supports"]).every(isTextList)) faults.push(`${at}: "supports" is not a record of text lists.`);
|
|
4280
4494
|
checkLimits(at, raw["limits"], faults);
|
|
4495
|
+
if (raw["output"] !== void 0) checkOutput(at, raw["output"], schema, faults);
|
|
4281
4496
|
if (isText(raw["id"]) && raw["key"] !== catalogKey(raw["id"], raw["step"])) faults.push(`${at}: the key does not follow from "step" and "id".`);
|
|
4282
4497
|
if (!isFields(raw["options"])) {
|
|
4283
4498
|
faults.push(`${at}: "options" is not an object.`);
|
|
@@ -4310,6 +4525,7 @@ function readEntry(at, raw, faults) {
|
|
|
4310
4525
|
...determinismNote === void 0 ? {} : { determinismNote },
|
|
4311
4526
|
optIn: raw["optIn"],
|
|
4312
4527
|
...raw["baseline"] === true ? { baseline: true } : {},
|
|
4528
|
+
...raw["output"] === void 0 ? {} : { output: raw["output"] },
|
|
4313
4529
|
options
|
|
4314
4530
|
};
|
|
4315
4531
|
}
|
|
@@ -4365,7 +4581,7 @@ function checkReferences(entries, faults) {
|
|
|
4365
4581
|
}
|
|
4366
4582
|
}
|
|
4367
4583
|
/**
|
|
4368
|
-
* This function reads a catalog from parsed JSON
|
|
4584
|
+
* This function reads a catalog from parsed JSON, in each schema of `STRATEGY_CATALOG_SCHEMAS`. It refuses each unknown field and each other schema.
|
|
4369
4585
|
* It gives the catalog with its `Infinity` values restored, or the list of all faults.
|
|
4370
4586
|
*/
|
|
4371
4587
|
function parseStrategyCatalog(value) {
|
|
@@ -4375,7 +4591,8 @@ function parseStrategyCatalog(value) {
|
|
|
4375
4591
|
faults: ["The catalog is not an object."]
|
|
4376
4592
|
};
|
|
4377
4593
|
refuseUnknown("The catalog", value, TOP_FIELDS, faults);
|
|
4378
|
-
|
|
4594
|
+
const schema = value["schema"];
|
|
4595
|
+
if (!STRATEGY_CATALOG_SCHEMAS.includes(schema)) faults.push(`The schema is not one of ${STRATEGY_CATALOG_SCHEMAS.join(", ")}.`);
|
|
4379
4596
|
if (!isText(value["engine"])) faults.push(`"engine" is not a text.`);
|
|
4380
4597
|
if (!isText(value["version"])) faults.push(`"version" is not a text.`);
|
|
4381
4598
|
if (!Array.isArray(value["strategies"])) return {
|
|
@@ -4384,7 +4601,7 @@ function parseStrategyCatalog(value) {
|
|
|
4384
4601
|
};
|
|
4385
4602
|
const entries = [];
|
|
4386
4603
|
value["strategies"].forEach((raw, i) => {
|
|
4387
|
-
const entry = readEntry(`The strategy ${isFields(raw) && isText(raw["key"]) ? raw["key"] : i}`, raw, faults);
|
|
4604
|
+
const entry = readEntry(`The strategy ${isFields(raw) && isText(raw["key"]) ? raw["key"] : i}`, raw, schema, faults);
|
|
4388
4605
|
if (entry !== void 0) entries.push(entry);
|
|
4389
4606
|
});
|
|
4390
4607
|
for (let i = 1; i < entries.length; i++) {
|
|
@@ -4400,7 +4617,7 @@ function parseStrategyCatalog(value) {
|
|
|
4400
4617
|
return {
|
|
4401
4618
|
ok: true,
|
|
4402
4619
|
catalog: {
|
|
4403
|
-
schema
|
|
4620
|
+
schema,
|
|
4404
4621
|
engine: value["engine"],
|
|
4405
4622
|
version: value["version"],
|
|
4406
4623
|
strategies: entries
|
|
@@ -4446,6 +4663,22 @@ function writeOption(option) {
|
|
|
4446
4663
|
}
|
|
4447
4664
|
return out;
|
|
4448
4665
|
}
|
|
4666
|
+
/** This function gives the file form of one output row, with the fields in the order of the file. */
|
|
4667
|
+
function writeRow(row) {
|
|
4668
|
+
const e = row.evidence;
|
|
4669
|
+
return {
|
|
4670
|
+
property: row.property,
|
|
4671
|
+
class: row.class,
|
|
4672
|
+
evidence: {
|
|
4673
|
+
inputs: e.inputs,
|
|
4674
|
+
...e.fractionalInputs === void 0 ? {} : { fractionalInputs: e.fractionalInputs },
|
|
4675
|
+
...e.nearWholeInputs === void 0 ? {} : { nearWholeInputs: e.nearWholeInputs },
|
|
4676
|
+
source: e.source,
|
|
4677
|
+
optionSet: e.optionSet,
|
|
4678
|
+
catalogVersion: e.catalogVersion
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4681
|
+
}
|
|
4449
4682
|
/** This function gives the file form of an entry, with its fields in the order of the file. */
|
|
4450
4683
|
function writeEntry(e) {
|
|
4451
4684
|
const options = Object.fromEntries(Object.entries(e.options).map(([key, o]) => [key, writeOption(o)]));
|
|
@@ -4462,6 +4695,7 @@ function writeEntry(e) {
|
|
|
4462
4695
|
...e.determinismNote === void 0 ? {} : { determinismNote: e.determinismNote },
|
|
4463
4696
|
optIn: e.optIn,
|
|
4464
4697
|
...e.baseline === true ? { baseline: true } : {},
|
|
4698
|
+
...e.output === void 0 ? {} : { output: e.output.map(writeRow) },
|
|
4465
4699
|
options
|
|
4466
4700
|
};
|
|
4467
4701
|
}
|
|
@@ -4475,12 +4709,13 @@ function unsafeValues(v, at) {
|
|
|
4475
4709
|
}
|
|
4476
4710
|
/**
|
|
4477
4711
|
* This function gives the text of the catalog file, sorted by key. The same source and version give the same bytes.
|
|
4712
|
+
* The file has the oldest schema that holds it, so a catalog with no `output` stays valid for a reader of the schema 1.
|
|
4478
4713
|
* The caller gives the version from `package.json`. The function throws an error if the file breaks a rule of the format.
|
|
4479
4714
|
*/
|
|
4480
4715
|
function writeStrategyCatalog(source, version) {
|
|
4481
4716
|
const strategies = [...source.strategies].sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0).map(writeEntry);
|
|
4482
4717
|
const doc = {
|
|
4483
|
-
schema: STRATEGY_CATALOG_SCHEMA,
|
|
4718
|
+
schema: source.strategies.some((e) => e.output !== void 0) ? STRATEGY_CATALOG_SCHEMA : STRATEGY_CATALOG_SCHEMAS[0],
|
|
4484
4719
|
engine: source.engine,
|
|
4485
4720
|
version,
|
|
4486
4721
|
strategies
|
|
@@ -5658,6 +5893,94 @@ const EDGE_KEY_STEP = /* @__PURE__ */ Object.freeze({
|
|
|
5658
5893
|
familyPart: (d) => `key-${d["edgeKey"]}`,
|
|
5659
5894
|
apply: (input, seed, d) => edgeKeyStep(input, { edgeKey: edgeKeyOf(d) }, seed)
|
|
5660
5895
|
});
|
|
5896
|
+
/** The set of `CIRCLE_SCATTERED` when the caller gives no set. */
|
|
5897
|
+
const CIRCLE_SET = "circle-v1";
|
|
5898
|
+
/**
|
|
5899
|
+
* The shared family `circle-scattered`, version 1: circle items of random whole radii in a fixed container, with no obstacles and no edges.
|
|
5900
|
+
*
|
|
5901
|
+
* - The dimension `containerShape` takes `rect` or `circle`. One seed gives the same radii in the 2 containers, so a pair joins on the seed.
|
|
5902
|
+
* - The circles fill approximately half of the container, and the container is at least as large as the largest circle.
|
|
5903
|
+
* - The stream `items` gives each radius, from 8 to 40. The stream `container` gives the width of a rectangle over its side, from 0.80 to 1.25.
|
|
5904
|
+
* - The family has no margin and no gap. Each value comes from whole numbers and `Math.sqrt`, which each engine rounds correctly, so the family is `exact`.
|
|
5905
|
+
*/
|
|
5906
|
+
const CIRCLE_SCATTERED = /* @__PURE__ */ Object.freeze({
|
|
5907
|
+
name: "circle-scattered",
|
|
5908
|
+
version: 1,
|
|
5909
|
+
owner: "layout-contract",
|
|
5910
|
+
meaning: "Circle items of random radii in a fixed rectangle or circle container, which they fill approximately half.",
|
|
5911
|
+
dimensions: /* @__PURE__ */ Object.freeze([/* @__PURE__ */ sharedDimension("count", { default: 40 }), /* @__PURE__ */ sharedDimension("containerShape", { supported: ["rect", "circle"] })]),
|
|
5912
|
+
seeding: "stepRandom(seed, items) gives the radius of each item. stepRandom(seed, container) gives the width over the side of a rectangle, in hundredths.",
|
|
5913
|
+
crossEngine: "exact",
|
|
5914
|
+
generate(seed, dims, context) {
|
|
5915
|
+
const count = dims["count"];
|
|
5916
|
+
if (typeof count !== "number" || !Number.isInteger(count) || count < 0) throw new RangeError(`circle-scattered: the count is a whole number of 0 or more, not ${String(count)}.`);
|
|
5917
|
+
const containerShape = dims["containerShape"];
|
|
5918
|
+
if (containerShape !== "rect" && containerShape !== "circle") throw new RangeError(`circle-scattered: the container shape is rect or circle, not ${String(containerShape)}.`);
|
|
5919
|
+
const set = context.set ?? CIRCLE_SET;
|
|
5920
|
+
let r = stepRandom(seed, "items");
|
|
5921
|
+
const radii = Array.from({ length: count }, () => randomInt(r, 8, 40));
|
|
5922
|
+
const largest = radii.reduce((m, v) => Math.max(m, v), 1);
|
|
5923
|
+
const squares = radii.reduce((sum, v) => sum + v * v, 0);
|
|
5924
|
+
let container;
|
|
5925
|
+
if (containerShape === "circle") {
|
|
5926
|
+
const big = Math.max(largest, Math.ceil(Math.sqrt(2 * squares)));
|
|
5927
|
+
container = {
|
|
5928
|
+
w: 2 * big,
|
|
5929
|
+
h: 2 * big,
|
|
5930
|
+
fixed: "size",
|
|
5931
|
+
shape: {
|
|
5932
|
+
kind: "circle",
|
|
5933
|
+
cx: big,
|
|
5934
|
+
cy: big,
|
|
5935
|
+
r: big
|
|
5936
|
+
}
|
|
5937
|
+
};
|
|
5938
|
+
} else {
|
|
5939
|
+
const area = Math.ceil(63 * squares / 10);
|
|
5940
|
+
r = stepRandom(seed, "container");
|
|
5941
|
+
const w = Math.max(2 * largest, Math.ceil(Math.sqrt(area) * randomInt(r, 80, 125) / 100));
|
|
5942
|
+
container = {
|
|
5943
|
+
w,
|
|
5944
|
+
h: Math.max(2 * largest, Math.ceil(area / w)),
|
|
5945
|
+
fixed: "size"
|
|
5946
|
+
};
|
|
5947
|
+
}
|
|
5948
|
+
const body = {
|
|
5949
|
+
schema: "layout-input/1",
|
|
5950
|
+
id: `${set}/circle-scattered/${containerShape}/s${seed}`,
|
|
5951
|
+
set,
|
|
5952
|
+
family: "circle-scattered",
|
|
5953
|
+
seed,
|
|
5954
|
+
source: "made-up",
|
|
5955
|
+
generator: {
|
|
5956
|
+
name: "circle-scattered",
|
|
5957
|
+
version: 1,
|
|
5958
|
+
params: {
|
|
5959
|
+
count,
|
|
5960
|
+
containerShape
|
|
5961
|
+
},
|
|
5962
|
+
seed
|
|
5963
|
+
},
|
|
5964
|
+
container,
|
|
5965
|
+
boxes: radii.map((v, i) => ({
|
|
5966
|
+
id: `c${i}`,
|
|
5967
|
+
w: 2 * v,
|
|
5968
|
+
h: 2 * v,
|
|
5969
|
+
shape: {
|
|
5970
|
+
kind: "circle",
|
|
5971
|
+
cx: v,
|
|
5972
|
+
cy: v,
|
|
5973
|
+
r: v
|
|
5974
|
+
}
|
|
5975
|
+
})),
|
|
5976
|
+
edges: []
|
|
5977
|
+
};
|
|
5978
|
+
return {
|
|
5979
|
+
...body,
|
|
5980
|
+
hash: documentHash(body)
|
|
5981
|
+
};
|
|
5982
|
+
}
|
|
5983
|
+
});
|
|
5661
5984
|
/** The set of `RECT_SCATTERED` when the caller gives no set. */
|
|
5662
5985
|
const XCHECK_SET = "xcheck-v1";
|
|
5663
5986
|
/**
|
|
@@ -5737,6 +6060,6 @@ const RECT_SCATTERED = /* @__PURE__ */ Object.freeze({
|
|
|
5737
6060
|
};
|
|
5738
6061
|
}
|
|
5739
6062
|
});
|
|
5740
|
-
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CORPUS_DIMENSIONS, DEFAULT_FAMILY_BY, DEFAULT_RNG, DEFAULT_SHAPES, DEFAULT_TOLERANCE, EDGES_STEP, EDGE_DENSITY, EDGE_KEY_STEP, EDGE_KEY_STEP_VERSION, EDGE_STEP_VERSION, EPS, FAMILY_ANY_KIND, HARD_RULE_VERSION, INVALIDATED_FIELD, JOINT_MEASURES, JOINT_MOVED_MIN, NODE_POSITIONS_DIMENSION, PACK_HARD_RULES, RECORD_EPS, RECORD_SCALE, RECT_SCATTERED, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, STRATEGY_CATALOG_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, catalogChoices, catalogDefaults, catalogKey, catalogOptions, checkCatalog, checkConfig, checkDeclared, checkInput, checkLayoutRecord, checkOptions, checkSchema, checkShapes, checkSpace, checkSplit, circleOverlaps, circlesOutside, clampOptions, compareMeasure, composeFamily, configId, corpusHashOf, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, createFamilyRegistry, declarationIssues, declaredClaimOf, declaredCounts, decodeOptionValue, dimensionAt, dimensionSupports, dimensionUnit, documentHash, edgeKeyStep, edgeStep, encodeOptionValue, enumerateSpace, exercised, familyKind, familyOf, fnv1a32, grow, hardRuleOf, inputShapeLevel, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, listOptions, marginSides, minEffectOf, mulberry32, nearestGaps, optionDefaults, optionIssue, outputGroups, outputHash, overlapOf, ownerDimension, packHard, packLinks, paramActive, paramLevels, paramProblem, paramValue, parseLayoutRecord, parseStrategyCatalog, perChange, pickMoves, placedCircle, placedRect, pointSegmentDistance, portPoint, portfolio, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resolveDimensions, ruleLevel, segmentsCross, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, shapesOverlap, sharedDimension, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, sweepGrid, sweepOf, sweepValues, toLayoutRecord, toPackInput, toRect, toSizedRect, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnSide, verdict, writeStrategyCatalog };
|
|
6063
|
+
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CIRCLE_SCATTERED, CORPUS_DIMENSIONS, DEFAULT_FAMILY_BY, DEFAULT_RNG, DEFAULT_SHAPES, DEFAULT_TOLERANCE, EDGES_STEP, EDGE_DENSITY, EDGE_KEY_STEP, EDGE_KEY_STEP_VERSION, EDGE_STEP_VERSION, EPS, EPS_STEPS, FAMILY_ANY_KIND, HARD_RULE_VERSION, INVALIDATED_FIELD, JOINT_MEASURES, JOINT_MOVED_MIN, NODE_POSITIONS_DIMENSION, OUTPUT_CLASS_MIN_INPUTS, OUTPUT_GRID_PROPERTIES, OUTPUT_NEAR_WHOLE, PACK_HARD_RULES, RECORD_EPS, RECORD_SCALE, RECT_SCATTERED, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, STRATEGY_CATALOG_SCHEMA, STRATEGY_CATALOG_SCHEMAS, STRATEGY_SPACE_SCHEMA, VERDICT_DRAWS, VERDICT_EXACT_CAP, VERDICT_EXACT_MAX, VERDICT_RUNS, VERDICT_SEED, applyPack, balanceMeasureSpecs, balanceMeasures, balanceOf, boundsOf, boxArea, canonicalConfig, canonicalInput, canonicalJson, catalogChoices, catalogDefaults, catalogKey, catalogOptions, checkCatalog, checkConfig, checkDeclared, checkInput, checkLayoutRecord, checkOptions, checkSchema, checkShapes, checkSpace, checkSplit, circleOverlaps, circlesOutside, clampOptions, compareMeasure, composeFamily, configId, corpusHashOf, countLinksThroughShapes, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, createFamilyRegistry, crossingPoint, declarationIssues, declaredClaimOf, declaredCounts, decodeOptionValue, dimensionAt, dimensionSupports, dimensionUnit, documentHash, edgeKeyStep, edgeStep, encodeOptionValue, enumerateSpace, exercised, familyKind, familyOf, fnv1a32, grow, hardRuleOf, inputShapeLevel, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, listOptions, marginSides, minEffectOf, mulberry32, nearestGaps, optionDefaults, optionIssue, outputGridClass, outputGroups, outputHash, overlapOf, ownerDimension, packHard, packLinks, paramActive, paramLevels, paramProblem, paramValue, parseLayoutRecord, parseStrategyCatalog, perChange, pickMoves, placedCircle, placedRect, pointSegmentDistance, portPoint, portfolio, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resolveDimensions, ruleLevel, segmentThroughShape, segmentsCross, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, shapesOverlap, sharedDimension, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, sweepGrid, sweepOf, sweepValues, toLayoutRecord, toPackInput, toRect, toSizedRect, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnSide, verdict, writeStrategyCatalog };
|
|
5741
6064
|
|
|
5742
6065
|
//# sourceMappingURL=index.js.map
|