@mark1russell7/layout-contract 0.2.18 → 0.2.19
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 +2 -0
- package/build/index.d.ts +58 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +266 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/balance.ts +233 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ The package has no runtime dependencies.
|
|
|
15
15
|
| The record `layout-record/1` | `LayoutRecord`, `Stage`, `Supports`, `RunFacts`, `RunEnv`, `toLayoutRecord` |
|
|
16
16
|
| The strategies | `StrategyInfo` |
|
|
17
17
|
| The measures | `MeasureSpec`, `Direction`, `JointMeasureId`, `JOINT_MEASURES`, `JOINT_MOVED_MIN`, `Verdict`, `compareMeasure`, `minEffectOf` |
|
|
18
|
+
| The balance and stability measures | `balanceOf`, `Balance`, `nearestGaps`, `procrustesOf`, `ProcrustesOptions`, `perChange`, `balanceMeasures`, `balanceMeasureSpecs`, `BALANCE_MEASURE_SUFFIXES`, `BalanceMeasureSuffix`, `BALANCE_SIDE_DEPTH`, `PlacedBox` |
|
|
18
19
|
| The edges step | `edgeStep`, `EdgeShape`, `EdgeStepParams`, `EDGE_DENSITY`, `EDGE_STEP_VERSION` |
|
|
19
20
|
| The random numbers | `mulberry32`, `fnv1a32`, `stepRandom`, `randomInt` |
|
|
20
21
|
| The hashes | `sha256Hex`, `canonicalJson`, `documentHash`, `outputHash`, `HashOptions` |
|
|
@@ -92,6 +93,7 @@ The comments of the source name each doc as `docs/<NAME>.md`. The docs are in th
|
|
|
92
93
|
|
|
93
94
|
| Doc | The subject |
|
|
94
95
|
|---|---|
|
|
96
|
+
| [`docs/BALANCE.md`](https://github.com/mark1russell7/layout-contract/blob/main/docs/BALANCE.md) | The balance and stability measures of a pack and of a joint layout |
|
|
95
97
|
| [`docs/CORPUS.md`](https://github.com/mark1russell7/layout-contract/blob/main/docs/CORPUS.md) | The shared corpus registry, its dimensions and families |
|
|
96
98
|
| [`docs/CORPUS-CHECKS.md`](https://github.com/mark1russell7/layout-contract/blob/main/docs/CORPUS-CHECKS.md) | The corpus checks and the split files |
|
|
97
99
|
| [`docs/JOINT-CORPUS.md`](https://github.com/mark1russell7/layout-contract/blob/main/docs/JOINT-CORPUS.md) | The joint corpus |
|
package/build/index.d.ts
CHANGED
|
@@ -780,6 +780,64 @@ export declare function minEffectOf(spec: Pick<MeasureSpec, "minEffect">, a?: nu
|
|
|
780
780
|
* Two equal values are a tie, also two infinite values. A value `NaN` is an error.
|
|
781
781
|
*/
|
|
782
782
|
export declare function compareMeasure(candidate: number, baseline: number, spec: Pick<MeasureSpec, "direction" | "minEffect">): Verdict;
|
|
783
|
+
/** A placed box: its id and its bounding box. */
|
|
784
|
+
export interface PlacedBox extends Rect {
|
|
785
|
+
readonly id: string;
|
|
786
|
+
}
|
|
787
|
+
/** The balance of one layout. `docs/BALANCE.md` gives the definitions. */
|
|
788
|
+
export interface Balance {
|
|
789
|
+
/** The standard deviation of the nearest-neighbour gaps divided by their mean. */
|
|
790
|
+
readonly gapCv: number;
|
|
791
|
+
/** The distance from the centroid of the free area to the center of the container, as a share of the half-diagonal. */
|
|
792
|
+
readonly centroidOffset: number;
|
|
793
|
+
/** The empty share of the strip at each side of the container. */
|
|
794
|
+
readonly side: Readonly<Record<Side, number>>;
|
|
795
|
+
/** The largest value of `side` minus the smallest value. */
|
|
796
|
+
readonly sideRange: number;
|
|
797
|
+
}
|
|
798
|
+
/** The depth of the strip of each side, as a share of the container. For `top` and `bottom`, it is a share of the height. For `left` and `right`, it is a share of the width. */
|
|
799
|
+
export declare const BALANCE_SIDE_DEPTH = .25;
|
|
800
|
+
/** A suffix of a balance or stability measure. A stage adds its prefix, for example `pack.balance.gapCv`. */
|
|
801
|
+
export type BalanceMeasureSuffix = "balance.gapCv" | "balance.centroidOffset" | "balance.side.top" | "balance.side.right" | "balance.side.bottom" | "balance.side.left" | "balance.sideRange" | "stability.procrustes" | "stability.seed";
|
|
802
|
+
/** The suffixes of the balance and stability measures, in the order of `docs/BALANCE.md`. */
|
|
803
|
+
export declare const BALANCE_MEASURE_SUFFIXES: readonly BalanceMeasureSuffix[];
|
|
804
|
+
/**
|
|
805
|
+
* This function gives the gap of each box to its nearest other box, in the order of `boxes`.
|
|
806
|
+
* Each box scans the boxes sorted by `x` in the two directions. A scan stops when the distance on `x` alone is above the best gap of the box.
|
|
807
|
+
* To the left, the distance on `x` is at least `a.x - b.x - maxW`, with `maxW` the largest width. With fewer than 2 boxes, a gap is `Infinity`.
|
|
808
|
+
*/
|
|
809
|
+
export declare function nearestGaps(boxes: readonly Rect[]): number[];
|
|
810
|
+
/**
|
|
811
|
+
* This function gives the balance of the placed boxes in the container: the evenness of the gaps and the place of the free space.
|
|
812
|
+
* The boxes do not overlap, as in the output of a packer. The area of a box outside the container does not count.
|
|
813
|
+
* `docs/BALANCE.md` gives the definitions and the reasons.
|
|
814
|
+
*/
|
|
815
|
+
export declare function balanceOf(boxes: readonly Rect[], container: Rect): Balance;
|
|
816
|
+
/** The options of `procrustesOf`. */
|
|
817
|
+
export interface ProcrustesOptions {
|
|
818
|
+
/** The unit of the result: the width `W` of the base, as in `joint.stability.mean`. A finite number above 0. */
|
|
819
|
+
readonly unit: number;
|
|
820
|
+
/** With `true` (the default), the alignment also rotates. With `false`, it only moves. */
|
|
821
|
+
readonly rotate?: boolean;
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* This function gives the root mean square move of the box centers from `base` to `next`, after the best alignment, in units of `unit`.
|
|
825
|
+
* The alignment is the orthogonal Procrustes fit: one move and, by default, one rotation. Only the ids in the two lists count.
|
|
826
|
+
* Fewer than 2 shared ids give 0, because the alignment then removes each move.
|
|
827
|
+
*/
|
|
828
|
+
export declare function procrustesOf(base: readonly PlacedBox[], next: readonly PlacedBox[], options: ProcrustesOptions): number;
|
|
829
|
+
/**
|
|
830
|
+
* This function gives the value of `stability.procrustes`: the move of `procrustesOf` divided by the change share.
|
|
831
|
+
* The change share is `changed / count`, and it is at least `1 / count`. Thus a change of one box divides by the smallest share.
|
|
832
|
+
*/
|
|
833
|
+
export declare function perChange(move: number, changed: number, count: number): number;
|
|
834
|
+
/** This function gives the balance values as measures, with the prefix of the stage, for example `pack.balance.gapCv`. */
|
|
835
|
+
export declare function balanceMeasures<S extends string>(stage: S, balance: Balance): Record<`${S}.${BalanceMeasureSuffix}`, number>;
|
|
836
|
+
/**
|
|
837
|
+
* This function gives the specs of the balance and stability measures, with the prefix of the stage.
|
|
838
|
+
* The balance measures read the area of each box, so they support only `rect`. The stability measures read only the centers.
|
|
839
|
+
*/
|
|
840
|
+
export declare function balanceMeasureSpecs<S extends string>(stage: S): readonly MeasureSpec<`${S}.${BalanceMeasureSuffix}`>[];
|
|
783
841
|
/**
|
|
784
842
|
* The common fields of a strategy of an engine. Each engine adds its own function, for example `pack` or `route`.
|
|
785
843
|
* `O` is the type of the options, and `S` is the type of `supports`.
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/tolerance.ts","../src/output.ts","../src/record.ts","../src/rules.ts","../src/turn.ts","../src/measures.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":";YACY;;qBAGC,gBAAgB;iBAEZ;WACN;WACA;;;iBAIM;WACN;WACA;WACA;WACA;;;iBAIM;WACN;WACA;WACA;WACA;;;;;;YAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA;WACA;;WAEA;WAAyB;WAAqB;WAAqB;;WACnE;WAA0B;WAAqB;WAAqB;WAAqB;;;YAG5F,kBAAkB;;wBAGd,YAAY,QAAQ,qBAAqB;;wBAOzC,KAAK,MAAM,MAA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;;;;wBAyBc,SAAS,OAAO,aAAa,QAAQ,YAAY,oBAA+C,UAAS,gBAAqB;;;;;;;wBAmC9H,WAAW,OAAO;;wBC1VlB,SAAS,MAAM,OAAO;;wBAKtB,UAAU,WAAW,WAAW;;;;;;wBAShC,SAAS,MAAM,MAAM,YAAY;;wBAajC,WAAW,QAAQ,SAAS;;wBAO5B,WAAW,QAAQ,QAAQ,YAAY;;wBAkBvC,QAAQ,KAAK,YAAY;;YC3D7B;;;;;;iBAOK,YAAY;WAClB,IAAI;WACJ;WACA,WAAW;;WAEX;;WAEA;;WAEA;;WAEA;;WAEA;;;;;WAKA;aAAgC;;;WAEhC;;WAEA,kBAAkB;;;;;WAKlB,QAAQ;;;YAIP;;;;;qBAoBC,yBAAyB,YAAY;;qBAarC;;YAGD;;;;;;wBAOI,YAAY,MAAM,KAAK,2BAA2B,YAAO;;;;;;;wBAezD,eAAe,mBAAmB,kBAAkB,MAAM,KAAK,0CAA0C;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/geometry.ts","../src/corpus.ts","../src/input.ts","../src/shapes.ts","../src/tolerance.ts","../src/output.ts","../src/record.ts","../src/rules.ts","../src/turn.ts","../src/measures.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":";YACY;;qBAGC,gBAAgB;iBAEZ;WACN;WACA;;;iBAIM;WACN;WACA;WACA;WACA;;;iBAIM;WACN;WACA;WACA;WACA;;;;;;YAOC;WACG;WAAuB;WAAoB;WAAoB;WAAoB;;WAEnF;WACA;WACA;;WAEA;WAAyB;WAAqB;WAAqB;;WACnE;WAA0B;WAAqB;WAAqB;WAAqB;;;YAG5F,kBAAkB;;wBAGd,YAAY,QAAQ,qBAAqB;;wBAOzC,KAAK,MAAM,MAAM,QAAQ,qBAAqB;;wBAM9C,SAAS,QAAQ,SAAS;;;;;wBA4B1B,WAA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kBAAkB;;;iBAIjD;;WAEN;;WAEA;WACA;;WAEA,QAAQ,OAAO;;;;;;;wBAWV,cAAc,MAAM,aAAa,cAAc,gBAAgB,cAAc,UAAS,iBAAsB,aAAa;;;;;qBA+D5H,YAAY;;;;;;qBAoBZ,gBAAgB,aAAa"}
|
package/build/index.js
CHANGED
|
@@ -1110,6 +1110,271 @@ function compareMeasure(candidate, baseline, spec) {
|
|
|
1110
1110
|
}
|
|
1111
1111
|
return (spec.direction === "lower" ? delta < 0 : delta > 0) ? "better" : "worse";
|
|
1112
1112
|
}
|
|
1113
|
+
// src/balance.ts
|
|
1114
|
+
/** The depth of the strip of each side, as a share of the container. For `top` and `bottom`, it is a share of the height. For `left` and `right`, it is a share of the width. */
|
|
1115
|
+
const BALANCE_SIDE_DEPTH = .25;
|
|
1116
|
+
/** The suffixes of the balance and stability measures, in the order of `docs/BALANCE.md`. */
|
|
1117
|
+
const BALANCE_MEASURE_SUFFIXES = Object.freeze([
|
|
1118
|
+
"balance.gapCv",
|
|
1119
|
+
"balance.centroidOffset",
|
|
1120
|
+
"balance.side.top",
|
|
1121
|
+
"balance.side.right",
|
|
1122
|
+
"balance.side.bottom",
|
|
1123
|
+
"balance.side.left",
|
|
1124
|
+
"balance.sideRange",
|
|
1125
|
+
"stability.procrustes",
|
|
1126
|
+
"stability.seed"
|
|
1127
|
+
]);
|
|
1128
|
+
/** This function gives the area of the overlap of two rectangles. */
|
|
1129
|
+
function overlapArea(a, b) {
|
|
1130
|
+
const w = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x);
|
|
1131
|
+
const h = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y);
|
|
1132
|
+
return w > 0 && h > 0 ? w * h : 0;
|
|
1133
|
+
}
|
|
1134
|
+
/** This function gives the distance between two rectangles. Two rectangles that touch or overlap give 0. */
|
|
1135
|
+
function rectDistance(a, b) {
|
|
1136
|
+
const dx = Math.max(0, b.x - (a.x + a.w), a.x - (b.x + b.w));
|
|
1137
|
+
const dy = Math.max(0, b.y - (a.y + a.h), a.y - (b.y + b.h));
|
|
1138
|
+
return Math.hypot(dx, dy);
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* This function gives the gap of each box to its nearest other box, in the order of `boxes`.
|
|
1142
|
+
* Each box scans the boxes sorted by `x` in the two directions. A scan stops when the distance on `x` alone is above the best gap of the box.
|
|
1143
|
+
* To the left, the distance on `x` is at least `a.x - b.x - maxW`, with `maxW` the largest width. With fewer than 2 boxes, a gap is `Infinity`.
|
|
1144
|
+
*/
|
|
1145
|
+
function nearestGaps(boxes) {
|
|
1146
|
+
const order = boxes.map((_, i) => i).sort((i, j) => boxes[i].x - boxes[j].x || i - j);
|
|
1147
|
+
const maxW = boxes.reduce((m, b) => Math.max(m, b.w), 0);
|
|
1148
|
+
const gaps = new Array(boxes.length).fill(Infinity);
|
|
1149
|
+
for (let k = 0; k < order.length; k++) {
|
|
1150
|
+
const a = boxes[order[k]];
|
|
1151
|
+
let best = Infinity;
|
|
1152
|
+
for (let m = k + 1; m < order.length; m++) {
|
|
1153
|
+
const b = boxes[order[m]];
|
|
1154
|
+
if (b.x - (a.x + a.w) > best) break;
|
|
1155
|
+
best = Math.min(best, rectDistance(a, b));
|
|
1156
|
+
}
|
|
1157
|
+
for (let m = k - 1; m >= 0; m--) {
|
|
1158
|
+
const b = boxes[order[m]];
|
|
1159
|
+
if (a.x - b.x - maxW > best) break;
|
|
1160
|
+
best = Math.min(best, rectDistance(a, b));
|
|
1161
|
+
}
|
|
1162
|
+
gaps[order[k]] = best;
|
|
1163
|
+
}
|
|
1164
|
+
return gaps;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* This function gives the balance of the placed boxes in the container: the evenness of the gaps and the place of the free space.
|
|
1168
|
+
* The boxes do not overlap, as in the output of a packer. The area of a box outside the container does not count.
|
|
1169
|
+
* `docs/BALANCE.md` gives the definitions and the reasons.
|
|
1170
|
+
*/
|
|
1171
|
+
function balanceOf(boxes, container) {
|
|
1172
|
+
const gaps = boxes.length < 2 ? [] : nearestGaps(boxes);
|
|
1173
|
+
const mean = gaps.length === 0 ? 0 : gaps.reduce((s, g) => s + g, 0) / gaps.length;
|
|
1174
|
+
const sd = gaps.length === 0 ? 0 : Math.sqrt(gaps.reduce((s, g) => s + (g - mean) ** 2, 0) / gaps.length);
|
|
1175
|
+
const gapCv = mean > 0 ? sd / mean : 0;
|
|
1176
|
+
const area = container.w * container.h;
|
|
1177
|
+
const cx = container.x + container.w / 2;
|
|
1178
|
+
const cy = container.y + container.h / 2;
|
|
1179
|
+
let used = 0;
|
|
1180
|
+
let mx = 0;
|
|
1181
|
+
let my = 0;
|
|
1182
|
+
for (const b of boxes) {
|
|
1183
|
+
const x0 = Math.max(b.x, container.x);
|
|
1184
|
+
const y0 = Math.max(b.y, container.y);
|
|
1185
|
+
const x1 = Math.min(b.x + b.w, container.x + container.w);
|
|
1186
|
+
const y1 = Math.min(b.y + b.h, container.y + container.h);
|
|
1187
|
+
if (x1 <= x0 || y1 <= y0) continue;
|
|
1188
|
+
const a = (x1 - x0) * (y1 - y0);
|
|
1189
|
+
used += a;
|
|
1190
|
+
mx += a * (x0 + x1) / 2;
|
|
1191
|
+
my += a * (y0 + y1) / 2;
|
|
1192
|
+
}
|
|
1193
|
+
const free = area - used;
|
|
1194
|
+
const half = Math.hypot(container.w, container.h) / 2;
|
|
1195
|
+
let centroidOffset = 0;
|
|
1196
|
+
if (free > 0 && half > 0) {
|
|
1197
|
+
const fx = (area * cx - mx) / free;
|
|
1198
|
+
const fy = (area * cy - my) / free;
|
|
1199
|
+
centroidOffset = Math.min(1, Math.hypot(fx - cx, fy - cy) / half);
|
|
1200
|
+
}
|
|
1201
|
+
const dh = container.h * BALANCE_SIDE_DEPTH;
|
|
1202
|
+
const dw = container.w * BALANCE_SIDE_DEPTH;
|
|
1203
|
+
const strips = {
|
|
1204
|
+
top: {
|
|
1205
|
+
x: container.x,
|
|
1206
|
+
y: container.y,
|
|
1207
|
+
w: container.w,
|
|
1208
|
+
h: dh
|
|
1209
|
+
},
|
|
1210
|
+
right: {
|
|
1211
|
+
x: container.x + container.w - dw,
|
|
1212
|
+
y: container.y,
|
|
1213
|
+
w: dw,
|
|
1214
|
+
h: container.h
|
|
1215
|
+
},
|
|
1216
|
+
bottom: {
|
|
1217
|
+
x: container.x,
|
|
1218
|
+
y: container.y + container.h - dh,
|
|
1219
|
+
w: container.w,
|
|
1220
|
+
h: dh
|
|
1221
|
+
},
|
|
1222
|
+
left: {
|
|
1223
|
+
x: container.x,
|
|
1224
|
+
y: container.y,
|
|
1225
|
+
w: dw,
|
|
1226
|
+
h: container.h
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
const side = {};
|
|
1230
|
+
for (const s of SIDES) {
|
|
1231
|
+
const strip = strips[s];
|
|
1232
|
+
const stripArea = strip.w * strip.h;
|
|
1233
|
+
const filled = boxes.reduce((sum, b) => sum + overlapArea(b, strip), 0);
|
|
1234
|
+
side[s] = stripArea > 0 ? Math.min(1, Math.max(0, 1 - filled / stripArea)) : 0;
|
|
1235
|
+
}
|
|
1236
|
+
const values = SIDES.map((s) => side[s]);
|
|
1237
|
+
return {
|
|
1238
|
+
gapCv,
|
|
1239
|
+
centroidOffset,
|
|
1240
|
+
side,
|
|
1241
|
+
sideRange: Math.max(...values) - Math.min(...values)
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* This function gives the root mean square move of the box centers from `base` to `next`, after the best alignment, in units of `unit`.
|
|
1246
|
+
* The alignment is the orthogonal Procrustes fit: one move and, by default, one rotation. Only the ids in the two lists count.
|
|
1247
|
+
* Fewer than 2 shared ids give 0, because the alignment then removes each move.
|
|
1248
|
+
*/
|
|
1249
|
+
function procrustesOf(base, next, options) {
|
|
1250
|
+
if (!(Number.isFinite(options.unit) && options.unit > 0)) throw new RangeError(`procrustesOf: the unit is a finite number above 0, not ${options.unit}.`);
|
|
1251
|
+
const after = new Map(next.map((b) => [b.id, b]));
|
|
1252
|
+
const a = [];
|
|
1253
|
+
const b = [];
|
|
1254
|
+
for (const p of base) {
|
|
1255
|
+
const q = after.get(p.id);
|
|
1256
|
+
if (q === void 0) continue;
|
|
1257
|
+
a.push([p.x + p.w / 2, p.y + p.h / 2]);
|
|
1258
|
+
b.push([q.x + q.w / 2, q.y + q.h / 2]);
|
|
1259
|
+
}
|
|
1260
|
+
const n = a.length;
|
|
1261
|
+
if (n < 2) return 0;
|
|
1262
|
+
const mean = (list) => [list.reduce((s, p) => s + p[0], 0) / n, list.reduce((s, p) => s + p[1], 0) / n];
|
|
1263
|
+
const [ax, ay] = mean(a);
|
|
1264
|
+
const [bx, by] = mean(b);
|
|
1265
|
+
let dot = 0;
|
|
1266
|
+
let cross = 0;
|
|
1267
|
+
for (let i = 0; i < n; i++) {
|
|
1268
|
+
const [px, py] = [a[i][0] - ax, a[i][1] - ay];
|
|
1269
|
+
const [qx, qy] = [b[i][0] - bx, b[i][1] - by];
|
|
1270
|
+
dot += px * qx + py * qy;
|
|
1271
|
+
cross += px * qy - py * qx;
|
|
1272
|
+
}
|
|
1273
|
+
const theta = options.rotate === false || dot === 0 && cross === 0 ? 0 : Math.atan2(cross, dot);
|
|
1274
|
+
const cos = Math.cos(theta);
|
|
1275
|
+
const sin = Math.sin(theta);
|
|
1276
|
+
let sum = 0;
|
|
1277
|
+
for (let i = 0; i < n; i++) {
|
|
1278
|
+
const [px, py] = [a[i][0] - ax, a[i][1] - ay];
|
|
1279
|
+
const [qx, qy] = [b[i][0] - bx, b[i][1] - by];
|
|
1280
|
+
sum += (cos * px - sin * py - qx) ** 2 + (sin * px + cos * py - qy) ** 2;
|
|
1281
|
+
}
|
|
1282
|
+
return Math.sqrt(sum / n) / options.unit;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* This function gives the value of `stability.procrustes`: the move of `procrustesOf` divided by the change share.
|
|
1286
|
+
* The change share is `changed / count`, and it is at least `1 / count`. Thus a change of one box divides by the smallest share.
|
|
1287
|
+
*/
|
|
1288
|
+
function perChange(move, changed, count) {
|
|
1289
|
+
if (!(Number.isInteger(count) && count >= 1)) throw new RangeError(`perChange: the count is an integer of 1 or more, not ${count}.`);
|
|
1290
|
+
return move / (Math.max(1, Math.min(count, changed)) / count);
|
|
1291
|
+
}
|
|
1292
|
+
/** This function gives the balance values as measures, with the prefix of the stage, for example `pack.balance.gapCv`. */
|
|
1293
|
+
function balanceMeasures(stage, balance) {
|
|
1294
|
+
const m = {
|
|
1295
|
+
[`${stage}.balance.gapCv`]: balance.gapCv,
|
|
1296
|
+
[`${stage}.balance.centroidOffset`]: balance.centroidOffset,
|
|
1297
|
+
[`${stage}.balance.sideRange`]: balance.sideRange
|
|
1298
|
+
};
|
|
1299
|
+
for (const s of SIDES) m[`${stage}.balance.side.${s}`] = balance.side[s];
|
|
1300
|
+
return m;
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* This function gives the specs of the balance and stability measures, with the prefix of the stage.
|
|
1304
|
+
* The balance measures read the area of each box, so they support only `rect`. The stability measures read only the centers.
|
|
1305
|
+
*/
|
|
1306
|
+
function balanceMeasureSpecs(stage) {
|
|
1307
|
+
const id = (suffix) => `${stage}.${suffix}`;
|
|
1308
|
+
const rect = ["rect"];
|
|
1309
|
+
const centers = SHAPE_KIND_IDS;
|
|
1310
|
+
return Object.freeze([
|
|
1311
|
+
{
|
|
1312
|
+
id: id("balance.gapCv"),
|
|
1313
|
+
unit: "ratio",
|
|
1314
|
+
direction: "lower",
|
|
1315
|
+
min: 0,
|
|
1316
|
+
max: Infinity,
|
|
1317
|
+
minEffect: .01,
|
|
1318
|
+
family: "balance",
|
|
1319
|
+
shapes: rect
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
id: id("balance.centroidOffset"),
|
|
1323
|
+
unit: "0 to 1",
|
|
1324
|
+
direction: "lower",
|
|
1325
|
+
min: 0,
|
|
1326
|
+
max: 1,
|
|
1327
|
+
minEffect: .01,
|
|
1328
|
+
family: "balance",
|
|
1329
|
+
shapes: rect
|
|
1330
|
+
},
|
|
1331
|
+
...SIDES.map((s) => ({
|
|
1332
|
+
id: id(`balance.side.${s}`),
|
|
1333
|
+
unit: "0 to 1",
|
|
1334
|
+
direction: "lower",
|
|
1335
|
+
min: 0,
|
|
1336
|
+
max: 1,
|
|
1337
|
+
family: "balance",
|
|
1338
|
+
role: "diagnostic",
|
|
1339
|
+
shapes: rect
|
|
1340
|
+
})),
|
|
1341
|
+
{
|
|
1342
|
+
id: id("balance.sideRange"),
|
|
1343
|
+
unit: "0 to 1",
|
|
1344
|
+
direction: "lower",
|
|
1345
|
+
min: 0,
|
|
1346
|
+
max: 1,
|
|
1347
|
+
minEffect: .02,
|
|
1348
|
+
family: "balance",
|
|
1349
|
+
shapes: rect
|
|
1350
|
+
},
|
|
1351
|
+
{
|
|
1352
|
+
id: id("stability.procrustes"),
|
|
1353
|
+
unit: "W for each change share",
|
|
1354
|
+
direction: "lower",
|
|
1355
|
+
min: 0,
|
|
1356
|
+
max: Infinity,
|
|
1357
|
+
floor: 0,
|
|
1358
|
+
tol: .005,
|
|
1359
|
+
minEffect: .005,
|
|
1360
|
+
family: "stability",
|
|
1361
|
+
role: "change-guard",
|
|
1362
|
+
shapes: centers
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
id: id("stability.seed"),
|
|
1366
|
+
unit: "W",
|
|
1367
|
+
direction: "lower",
|
|
1368
|
+
min: 0,
|
|
1369
|
+
max: Infinity,
|
|
1370
|
+
floor: 0,
|
|
1371
|
+
tol: .005,
|
|
1372
|
+
minEffect: .005,
|
|
1373
|
+
family: "stability",
|
|
1374
|
+
shapes: centers
|
|
1375
|
+
}
|
|
1376
|
+
]);
|
|
1377
|
+
}
|
|
1113
1378
|
// src/utf8.ts
|
|
1114
1379
|
/** This function gives the UTF-8 bytes of a string. The package has no runtime dependencies, thus it does not use `TextEncoder`. */
|
|
1115
1380
|
function utf8(text) {
|
|
@@ -3991,6 +4256,6 @@ const RECT_SCATTERED = Object.freeze({
|
|
|
3991
4256
|
};
|
|
3992
4257
|
}
|
|
3993
4258
|
});
|
|
3994
|
-
export { 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, 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, outputGroups, outputHash, overlapOf, ownerDimension, packHard, paramActive, paramLevels, paramProblem, paramValue, pickMoves, placedRect, portPoint, portfolio, 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 };
|
|
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 };
|
|
3995
4260
|
|
|
3996
4261
|
//# sourceMappingURL=index.js.map
|