@mark1russell7/layout-contract 0.5.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 +4 -4
- package/build/index.d.ts +37 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +221 -3
- 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/tolerance.ts +3 -0
- package/build/measures-KWg_was6.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The package has one runtime dependency: `@mark1russell7/rigor-generators`, the h
|
|
|
8
8
|
|
|
9
9
|
| Part | Exports |
|
|
10
10
|
|---|---|
|
|
11
|
-
| Geometry | `Point`, `Rect`, `Region`, `Side`, `Sides`, `Margin`, `marginSides`, `grow`, `boundsOf`, `regionArea`, `translate`, `overlapOf`, `segmentsCross`, `pointSegmentDistance` |
|
|
11
|
+
| Geometry | `Point`, `Rect`, `Region`, `Side`, `Sides`, `Margin`, `marginSides`, `grow`, `boundsOf`, `regionArea`, `translate`, `overlapOf`, `segmentsCross`, `crossingPoint`, `pointSegmentDistance` |
|
|
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`, `PackLink`, `toPackInput`, `packLinks`, `Placement`, `PackOutput`, `StageTrace`, `applyPack` |
|
|
@@ -32,8 +32,8 @@ The package has one runtime dependency: `@mark1russell7/rigor-generators`, the h
|
|
|
32
32
|
| The option declarations | `OptionSchema`, `OptionDeclaration`, `AnyOption`, `NumberOption`, `BooleanOption`, `EnumOption`, `ValueOption`, `ListItem`, `NoDefault`, `DeclaredStrategy`, `listOptions`, `optionDefaults`, `checkOptions`, `clampOptions`, `sweepValues`, `sweepOf`, `sweepGrid`, `checkSchema` |
|
|
33
33
|
| The strategy catalog | `StrategyCatalog`, `StrategyCatalogSource`, `CatalogEntry`, `ParamRoute`, `StrategyMember`, `CatalogLimit`, `OutputRow`, `OutputEvidence`, `OutputGridClass`, `OutputGridCounts`, `StrategyCatalogSchema`, `STRATEGY_CATALOG_SCHEMA`, `STRATEGY_CATALOG_SCHEMAS`, `OUTPUT_GRID_PROPERTIES`, `OUTPUT_NEAR_WHOLE`, `OUTPUT_CLASS_MIN_INPUTS`, `NODE_POSITIONS_DIMENSION`, `outputGridClass`, `parseStrategyCatalog`, `writeStrategyCatalog`, `checkCatalog`, `catalogDefaults`, `catalogOptions`, `catalogChoices`, `catalogKey`, `decodeOptionValue`, `encodeOptionValue` |
|
|
34
34
|
| The turn | `turnBox`, `turnPort`, `turnMargin`, `turnRegion`, `turnSide`, `turnPoint` |
|
|
35
|
-
| The tolerances | `EPS`, `RECORD_EPS`, `RECORD_SCALE`, `Tolerance`, `DEFAULT_TOLERANCE` |
|
|
36
|
-
| The hard rules | `HARD_RULE_VERSION`, `shapesOverlap`, `circleOverlaps`, `circlesOutside`, `placedCircle`, `PlacedCircle`, `countOverlaps`, `countObstacleHits`, `regionHitsRect`, `rectInRegion`, `countOutside`, `ContainerTest`, `countPortsOffBorder`, `packHard`, `PackHard`, `PACK_HARD_RULES`, `placedRect`, `checkInput` |
|
|
35
|
+
| The tolerances | `EPS`, `EPS_STEPS`, `RECORD_EPS`, `RECORD_SCALE`, `Tolerance`, `DEFAULT_TOLERANCE` |
|
|
36
|
+
| The hard rules | `HARD_RULE_VERSION`, `shapesOverlap`, `circleOverlaps`, `circlesOutside`, `placedCircle`, `PlacedCircle`, `segmentThroughShape`, `countLinksThroughShapes`, `ShapeLink`, `countOverlaps`, `countObstacleHits`, `regionHitsRect`, `rectInRegion`, `countOutside`, `ContainerTest`, `countPortsOffBorder`, `packHard`, `PackHard`, `PACK_HARD_RULES`, `placedRect`, `checkInput` |
|
|
37
37
|
|
|
38
38
|
## The rules
|
|
39
39
|
|
|
@@ -74,7 +74,7 @@ The package has one runtime dependency: `@mark1russell7/rigor-generators`, the h
|
|
|
74
74
|
- **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.
|
|
75
75
|
- **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:
|
|
76
76
|
- `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.
|
|
77
|
-
- A record without `skipped` has a boolean `deterministic
|
|
77
|
+
- A record without `skipped` has a boolean `deterministic`, or `null` when it has `oneRun: true` and the pair had no second run. `checkLayoutRecord` refuses `null` on each other record.
|
|
78
78
|
- An old skipped record has `deterministic: true`. `checkLayoutRecord` accepts it, and `parseLayoutRecord` gives `null` in its place.
|
|
79
79
|
- `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`.
|
|
80
80
|
- `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.
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { $ as CorpusSplit, A as shapeKindsOf, At as
|
|
1
|
+
import { $ as CorpusSplit, A as shapeKindsOf, At as pointSegmentDistance, B as LayoutInput, C as checkShapes, Ct as Sides, D as ruleLevel, Dt as grow, E as itemShapeOf, Et as crossingPoint, F as LayoutBox, Ft as translate, G as PairGap, H as PackInput, I as LayoutCell, J as packLinks, K as Port, L as LayoutContainer, M as shapeSupportProblems, Mt as segmentsCross, N as shapesOf, Nt as toRect, O as shapeKindOf, Ot as marginSides, P as Item, Pt as toSizedRect, Q as CorpusEntry, R as LayoutEdge, S as boxArea, St as Side, T as isShapeKind, Tt as boundsOf, U as PackInputOptions, V as Obstacle, W as PackLink, X as toPackInput, Y as portPoint, Z as ClaimBreak, _ as ShapeKind, _t as Margin, a as MeasureSpec, at as SPLIT_SCHEMA, b as ShapeLimit, bt as Region, c as minEffectOf, ct as checkDeclared, d as SHAPE_KINDS, dt as declaredClaimOf, et as DeclaredClaim, f as SHAPE_KIND_IDS, ft as declaredCounts, g as ShapeInput, gt as splitFolds, h as ShapeGeometry, ht as splitFileName, i as JointMeasureId, it as FamilyCell, j as shapeLevel, jt as regionArea, k as shapeKindProblem, kt as overlapOf, l as DEFAULT_SHAPES, lt as checkSplit, m as ShapeCheck, mt as leaveOneSeedOut, n as JOINT_MEASURES, nt as FAMILY_ANY_KIND, o as Verdict, ot as SplitCorpus, p as ShapeBound, pt as familyOf, q as canonicalInput, r as JOINT_MOVED_MIN, rt as FamilyBy, s as compareMeasure, st as SplitFold, t as Direction, tt as Declares, u as RuleLevel, ut as corpusHashOf, v as ShapeKindSpec, vt as Point, w as inputShapeLevel, wt as SizedRect, x as ShapeSupport, xt as SIDES, y as ShapeLevel, yt as Rect, z as LayoutGenerator } from "./measures-COqcrCzv.js";
|
|
2
2
|
/** The epsilon for the float compares in an engine. */
|
|
3
3
|
export declare const EPS = 1e-6;
|
|
4
|
+
/** The count of `EPS` steps in one layout unit. It is the integer equal to `1 / EPS`. */
|
|
5
|
+
export declare const EPS_STEPS = 1e6;
|
|
4
6
|
/**
|
|
5
7
|
* 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`.
|
|
6
8
|
* Use a multiplication by this value, not a division by `RECORD_EPS`. The two differ at some half steps.
|
|
@@ -94,7 +96,9 @@ export interface LayoutRecord {
|
|
|
94
96
|
readonly hardRule?: number;
|
|
95
97
|
/**
|
|
96
98
|
* The value is `true` when two runs with the same seed give the same positions.
|
|
97
|
-
* A skipped record has `null`, because no run made a claim.
|
|
99
|
+
* A skipped record has `null`, because no run made a claim.
|
|
100
|
+
* A record with `oneRun: true` can also have `null`: the pair had no second run to compare.
|
|
101
|
+
* Each other record has a boolean.
|
|
98
102
|
*/
|
|
99
103
|
readonly deterministic: boolean | null;
|
|
100
104
|
/** The id of the prediction that was written before the run. */
|
|
@@ -106,6 +110,7 @@ export interface LayoutRecord {
|
|
|
106
110
|
/**
|
|
107
111
|
* The value is `true` when a measure of the pair chose 1 timed repeat and no warm-up.
|
|
108
112
|
* Then `ms` is one time, so a time gate does not read this record.
|
|
113
|
+
* A bench that runs such a pair only once writes `deterministic: null`, and its record makes no claim on determinism.
|
|
109
114
|
*/
|
|
110
115
|
readonly oneRun?: boolean;
|
|
111
116
|
/** The wall budget of the pair of a strategy and an input, in milliseconds. */
|
|
@@ -161,7 +166,7 @@ export declare function hardRuleOf(record: Pick<LayoutRecord, "hardRule">): numb
|
|
|
161
166
|
/**
|
|
162
167
|
* This function gives the problems of one `layout-record/1` value. An empty list means a good record.
|
|
163
168
|
* A record that has `skipped` has `deterministic: null`. An old skipped record with a boolean is also correct.
|
|
164
|
-
* A record without `skipped` has a boolean
|
|
169
|
+
* A record without `skipped` has a boolean, or `null` when it has `oneRun: true`. The check accepts fields that the format does not know.
|
|
165
170
|
*/
|
|
166
171
|
export declare function checkLayoutRecord(value: unknown): string[];
|
|
167
172
|
/**
|
|
@@ -230,6 +235,25 @@ export interface ContainerTest {
|
|
|
230
235
|
* - Each other box does not count. The function throws a `RangeError` for a container that is not a circle.
|
|
231
236
|
*/
|
|
232
237
|
export declare function circlesOutside(input: LayoutInput, tolerance?: number): number;
|
|
238
|
+
/**
|
|
239
|
+
* This function tells if the segment `ab` goes through a placed box, by the rule of `Tolerance.through`.
|
|
240
|
+
* A part of the segment longer than `tolerance` is inside the shape made `tolerance` smaller.
|
|
241
|
+
*
|
|
242
|
+
* - 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.
|
|
243
|
+
* - The margin of the box does not count. A box without a position gives `false`.
|
|
244
|
+
*/
|
|
245
|
+
export declare function segmentThroughShape(a: Point, b: Point, box: LayoutBox, tolerance?: number): boolean;
|
|
246
|
+
/** A route between two boxes: the ids of its ends and its points. `countLinksThroughShapes` reads it. */
|
|
247
|
+
export interface ShapeLink {
|
|
248
|
+
readonly source: string;
|
|
249
|
+
readonly target: string;
|
|
250
|
+
readonly points: readonly Point[];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* This function counts the routes that go through a placed box that is not one of their two ends, by `segmentThroughShape`.
|
|
254
|
+
* A route counts once, also when it goes through more than one box.
|
|
255
|
+
*/
|
|
256
|
+
export declare function countLinksThroughShapes(boxes: readonly LayoutBox[], links: readonly ShapeLink[], tolerance?: number): number;
|
|
233
257
|
/**
|
|
234
258
|
* This function counts the placed boxes that go out of the container.
|
|
235
259
|
* 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.
|
|
@@ -1643,11 +1667,20 @@ export declare const EDGES_STEP: CorpusStep;
|
|
|
1643
1667
|
* The step `edge-key` of `edgeKeyStep` (version 1), as a corpus step. It comes directly after `EDGES_STEP`. Its family part is `key-<edgeKey>`.
|
|
1644
1668
|
*/
|
|
1645
1669
|
export declare const EDGE_KEY_STEP: CorpusStep;
|
|
1670
|
+
/**
|
|
1671
|
+
* The shared family `circle-scattered`, version 1: circle items of random whole radii in a fixed container, with no obstacles and no edges.
|
|
1672
|
+
*
|
|
1673
|
+
* - The dimension `containerShape` takes `rect` or `circle`. One seed gives the same radii in the 2 containers, so a pair joins on the seed.
|
|
1674
|
+
* - The circles fill approximately half of the container, and the container is at least as large as the largest circle.
|
|
1675
|
+
* - 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.
|
|
1676
|
+
* - 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`.
|
|
1677
|
+
*/
|
|
1678
|
+
export declare const CIRCLE_SCATTERED: CorpusFamily<LayoutInput>;
|
|
1646
1679
|
/**
|
|
1647
1680
|
* The shared family `rect-scattered`, version 1: a fixed rectangle container, rectangle obstacles at random places and boxes without positions.
|
|
1648
1681
|
* It is the one copy of the generator of `docs/FORMAT.md` of `packing`. Its input is the input of `packing`, byte for byte.
|
|
1649
1682
|
* The steps `container`, `obstacles` and `boxes` each have a stream of `stepRandom`. Each value is a whole number, so the family is `exact`.
|
|
1650
1683
|
*/
|
|
1651
1684
|
export declare const RECT_SCATTERED: CorpusFamily<LayoutInput>;
|
|
1652
|
-
export { ClaimBreak, CorpusEntry, CorpusSplit, DEFAULT_SHAPES, DeclaredClaim, Declares, Direction, FAMILY_ANY_KIND, FamilyBy, FamilyCell, Item, JOINT_MEASURES, JOINT_MOVED_MIN, JointMeasureId, LayoutBox, LayoutCell, LayoutContainer, LayoutEdge, LayoutGenerator, LayoutInput, Margin, MeasureSpec, Obstacle, PackInput, PackInputOptions, PackLink, PairGap, Point, Port, Rect, Region, RuleLevel, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, ShapeBound, ShapeCheck, ShapeGeometry, ShapeInput, ShapeKind, ShapeKindSpec, ShapeLevel, ShapeLimit, ShapeSupport, Side, Sides, SizedRect, SplitCorpus, SplitFold, Verdict, boundsOf, boxArea, canonicalInput, checkDeclared, checkShapes, checkSplit, compareMeasure, corpusHashOf, declaredClaimOf, declaredCounts, familyOf, grow, inputShapeLevel, isShapeKind, itemShapeOf, leaveOneSeedOut, marginSides, minEffectOf, overlapOf, packLinks, pointSegmentDistance, portPoint, regionArea, ruleLevel, segmentsCross, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, splitFileName, splitFolds, toPackInput, toRect, toSizedRect, translate };
|
|
1685
|
+
export { ClaimBreak, CorpusEntry, CorpusSplit, DEFAULT_SHAPES, DeclaredClaim, Declares, Direction, FAMILY_ANY_KIND, FamilyBy, FamilyCell, Item, JOINT_MEASURES, JOINT_MOVED_MIN, JointMeasureId, LayoutBox, LayoutCell, LayoutContainer, LayoutEdge, LayoutGenerator, LayoutInput, Margin, MeasureSpec, Obstacle, PackInput, PackInputOptions, PackLink, PairGap, Point, Port, Rect, Region, RuleLevel, SHAPE_KINDS, SHAPE_KIND_IDS, SIDES, SPLIT_SCHEMA, ShapeBound, ShapeCheck, ShapeGeometry, ShapeInput, ShapeKind, ShapeKindSpec, ShapeLevel, ShapeLimit, ShapeSupport, Side, Sides, SizedRect, SplitCorpus, SplitFold, Verdict, boundsOf, boxArea, canonicalInput, checkDeclared, checkShapes, checkSplit, compareMeasure, corpusHashOf, crossingPoint, declaredClaimOf, declaredCounts, familyOf, grow, inputShapeLevel, isShapeKind, itemShapeOf, leaveOneSeedOut, marginSides, minEffectOf, overlapOf, packLinks, pointSegmentDistance, portPoint, regionArea, ruleLevel, segmentsCross, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, splitFileName, splitFolds, toPackInput, toRect, toSizedRect, translate };
|
|
1653
1686
|
//# sourceMappingURL=index.d.ts.map
|
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/strategy-options.ts","../src/strategy-catalog.ts","../src/verdict.ts","../src/families.ts"],"mappings":";;qBACa;;;;;qBAMA;;;;;qBAMA;;;;;iBAMI;;WAEN;;WAEA;;;;;;qBAOE,mBAAmB;;
|
|
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/strategy-options.ts","../src/strategy-catalog.ts","../src/verdict.ts","../src/families.ts"],"mappings":";;qBACa;;qBAGA;;;;;qBAMA;;;;;qBAMA;;;;;iBAMI;;WAEN;;WAEA;;;;;;qBAOE,mBAAmB;;iBC5Bf;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;;WAE7B;;;;;;;WAOA;;WAEA;;WAEA;;WAEA;;;;;;WAMA;;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,WAAW,QAAQ,KAAK;;;;;;wBASxB,kBAAkB;;;;;;wBAmClB,kBAAkB,iBAAiB;;wBC5LnC,WAAW,KAAK,YAAY;;;;;;;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Bf,kBAAkB,aAAa;;;;;;qBAqD/B,gBAAgB,aAAa"}
|
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",
|
|
@@ -5763,6 +5893,94 @@ const EDGE_KEY_STEP = /* @__PURE__ */ Object.freeze({
|
|
|
5763
5893
|
familyPart: (d) => `key-${d["edgeKey"]}`,
|
|
5764
5894
|
apply: (input, seed, d) => edgeKeyStep(input, { edgeKey: edgeKeyOf(d) }, seed)
|
|
5765
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
|
+
});
|
|
5766
5984
|
/** The set of `RECT_SCATTERED` when the caller gives no set. */
|
|
5767
5985
|
const XCHECK_SET = "xcheck-v1";
|
|
5768
5986
|
/**
|
|
@@ -5842,6 +6060,6 @@ const RECT_SCATTERED = /* @__PURE__ */ Object.freeze({
|
|
|
5842
6060
|
};
|
|
5843
6061
|
}
|
|
5844
6062
|
});
|
|
5845
|
-
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, 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, 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, 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, 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 };
|
|
5846
6064
|
|
|
5847
6065
|
//# sourceMappingURL=index.js.map
|