@mark1russell7/layout-contract 0.9.4 → 0.9.6
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 +6 -3
- package/build/index.d.ts +83 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +185 -24
- package/build/index.js.map +1 -1
- package/build/{measures-B_n_KDMd.d.ts → measures-Aan-rHz1.d.ts} +31 -4
- package/build/measures-Aan-rHz1.d.ts.map +1 -0
- package/build/text.d.ts +1 -1
- package/package.json +3 -2
- package/src/frame.ts +2 -1
- package/src/geometry.ts +47 -7
- package/src/hash.ts +5 -1
- package/src/index.ts +1 -0
- package/src/input.ts +15 -0
- package/src/output.ts +11 -2
- package/src/record.ts +41 -2
- package/src/resize.ts +92 -0
- package/src/rules.ts +36 -14
- package/src/turn.ts +15 -2
- package/build/measures-B_n_KDMd.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { orient2dSign } from "@mark1russell7/predicates";
|
|
1
2
|
import { canonicalJson as canonicalJson$1, deriveSeed, fnv1a32 as fnv1a32$1, mulberry32 as mulberry32$1, sha256Hex as sha256Hex$1 } from "@mark1russell7/rigor-generators";
|
|
2
3
|
import { STRATEGY_SPACE_SCHEMA, canonicalConfig, checkConfig, checkOptions, checkSchema, checkSpace as checkSpace$1, clampOptions, configId, declarationIssues, enumerateSpace as enumerateSpace$1, joinConfigs, listOptions, optionDefaults, optionIssue, paramActive, paramLevels, paramProblem, paramValue, productSpace, spaceShapeKinds as spaceShapeKinds$1, spaceSize as spaceSize$1, splitConfig, sweepGrid, sweepOf, sweepValues } from "@mark1russell7/strategy-space";
|
|
3
4
|
import { bootstrap, bootstrapStrata, signFlipTest, signTest } from "@mark1russell7/rigor-statistics";
|
|
@@ -187,25 +188,33 @@ function overlapOf(a, b) {
|
|
|
187
188
|
function orient(a, b, c) {
|
|
188
189
|
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
|
|
189
190
|
}
|
|
190
|
-
/** This function
|
|
191
|
-
function
|
|
192
|
-
return
|
|
191
|
+
/** This function gives the exact sign of the cross product of `ab` and `ac`, from `orient2dSign` of `@mark1russell7/predicates`. */
|
|
192
|
+
function side(a, b, c) {
|
|
193
|
+
return orient2dSign(a.x, a.y, b.x, b.y, c.x, c.y);
|
|
194
|
+
}
|
|
195
|
+
/** This function tells if each coordinate of the points is finite. */
|
|
196
|
+
function allFinite(...points) {
|
|
197
|
+
return points.every((p) => Number.isFinite(p.x) && Number.isFinite(p.y));
|
|
193
198
|
}
|
|
194
199
|
/**
|
|
195
200
|
* This function tells if the segments `ab` and `cd` cross at one point inside both of them.
|
|
196
201
|
* Segments that only touch at an end, or that are collinear, do not cross. The test has no tolerance.
|
|
202
|
+
* The signs are exact, so an input that is almost collinear gets the correct answer. A coordinate that is not finite gives `false`.
|
|
197
203
|
*/
|
|
198
204
|
function segmentsCross(a, b, c, d) {
|
|
199
|
-
|
|
205
|
+
if (!allFinite(a, b, c, d)) return false;
|
|
206
|
+
return side(c, d, a) * side(c, d, b) === -1 && side(a, b, c) * side(a, b, d) === -1;
|
|
200
207
|
}
|
|
201
208
|
/**
|
|
202
209
|
* This function gives the point where the segments `ab` and `cd` cross, or `undefined`.
|
|
203
210
|
* It gives a point exactly when `segmentsCross` is true, so a touch at an end and collinear segments give `undefined`.
|
|
211
|
+
* The point comes from float cross products. For an input that is almost collinear, the point stays on `ab`.
|
|
204
212
|
*/
|
|
205
213
|
function crossingPoint(a, b, c, d) {
|
|
206
214
|
if (!segmentsCross(a, b, c, d)) return void 0;
|
|
207
215
|
const from = orient(c, d, a);
|
|
208
|
-
const
|
|
216
|
+
const r = from / (from - orient(c, d, b));
|
|
217
|
+
const t = Number.isNaN(r) ? .5 : Math.min(1, Math.max(0, r));
|
|
209
218
|
return {
|
|
210
219
|
x: a.x + t * (b.x - a.x),
|
|
211
220
|
y: a.y + t * (b.y - a.y)
|
|
@@ -219,6 +228,27 @@ function pointSegmentDistance(p, a, b) {
|
|
|
219
228
|
const t = l2 === 0 ? 0 : Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / l2));
|
|
220
229
|
return Math.hypot(p.x - (a.x + t * dx), p.y - (a.y + t * dy));
|
|
221
230
|
}
|
|
231
|
+
/** This function tells if the point (`x`, `y`) is inside a ring, by the even-odd rule. A ring can be concave. The answer for a point on the border can be each value. */
|
|
232
|
+
function pointInRing(x, y, ring) {
|
|
233
|
+
return pointInRings(x, y, [ring]);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* This function tells if the point (`x`, `y`) is inside a set of rings, by the even-odd rule over all their sides.
|
|
237
|
+
* Thus a point inside the outer ring and inside a hole is out. The answer for a point on a border can be each value.
|
|
238
|
+
*/
|
|
239
|
+
function pointInRings(x, y, rings) {
|
|
240
|
+
let inside = false;
|
|
241
|
+
for (const ring of rings) for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
242
|
+
const [xi, yi] = ring[i];
|
|
243
|
+
const [xj, yj] = ring[j];
|
|
244
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) inside = !inside;
|
|
245
|
+
}
|
|
246
|
+
return inside;
|
|
247
|
+
}
|
|
248
|
+
/** This function gives the distance between the centers of two rectangles. */
|
|
249
|
+
function boxCenterDistance(a, b) {
|
|
250
|
+
return Math.hypot(b.x + b.w / 2 - (a.x + a.w / 2), b.y + b.h / 2 - (a.y + a.h / 2));
|
|
251
|
+
}
|
|
222
252
|
/**
|
|
223
253
|
* This function gives the index at which a point goes among the items of a list on the screen.
|
|
224
254
|
* The reading order is the rows from top to bottom, and each row from left to right.
|
|
@@ -589,6 +619,83 @@ function canonicalInput(input) {
|
|
|
589
619
|
pairGaps
|
|
590
620
|
};
|
|
591
621
|
}
|
|
622
|
+
// src/resize.ts
|
|
623
|
+
/** The names of the bounds of a resize. */
|
|
624
|
+
const BOUNDS = [
|
|
625
|
+
"minW",
|
|
626
|
+
"maxW",
|
|
627
|
+
"minH",
|
|
628
|
+
"maxH"
|
|
629
|
+
];
|
|
630
|
+
/**
|
|
631
|
+
* This function gives the bounds of the size of a box. A bound that `resize` does not set is the size of the box.
|
|
632
|
+
* A box without `resize` gives the bounds of its own size, so it keeps its size.
|
|
633
|
+
*/
|
|
634
|
+
function sizeBoundsOf(box) {
|
|
635
|
+
const r = box.resize;
|
|
636
|
+
return {
|
|
637
|
+
minW: r?.minW ?? box.w,
|
|
638
|
+
maxW: r?.maxW ?? box.w,
|
|
639
|
+
minH: r?.minH ?? box.h,
|
|
640
|
+
maxH: r?.maxH ?? box.h,
|
|
641
|
+
aspect: r?.aspect ?? "free"
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* This function tells if a size is in the bounds of a box, with the tolerance `RECORD_EPS` of the records.
|
|
646
|
+
* With the aspect `keep`, the ratio of `w` to `h` also stays the ratio of the box, in the same tolerance.
|
|
647
|
+
* A size that is not positive and finite is not in the bounds.
|
|
648
|
+
*/
|
|
649
|
+
function sizeFits(box, w, h) {
|
|
650
|
+
if (!(w > 0 && h > 0 && Number.isFinite(w) && Number.isFinite(h))) return false;
|
|
651
|
+
const b = sizeBoundsOf(box);
|
|
652
|
+
if (w < b.minW - .001 || w > b.maxW + .001 || h < b.minH - .001 || h > b.maxH + .001) return false;
|
|
653
|
+
return b.aspect === "free" || Math.abs(w * box.h - h * box.w) <= .001 * (box.w + box.h);
|
|
654
|
+
}
|
|
655
|
+
/** This function gives a port of a box of the size `w` by `h` after a resize to `toW` by `toH`. A port with `along` keeps its value. */
|
|
656
|
+
function resizePort(port, w, h, toW, toH) {
|
|
657
|
+
return {
|
|
658
|
+
...port,
|
|
659
|
+
...port.x === void 0 ? {} : { x: port.x * toW / w },
|
|
660
|
+
...port.y === void 0 ? {} : { y: port.y * toH / h }
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* This function gives a box at the size `w` by `h`. The position, the margin and the other fields stay.
|
|
665
|
+
* A port with `x` or `y` moves with the scale of its axis. A port with `along` keeps its place on its side.
|
|
666
|
+
* The function does not test the bounds: `sizeFits` does. A box with a shape is a bad input for a resize (`resizeProblems`).
|
|
667
|
+
*/
|
|
668
|
+
function resizeBox(box, w, h) {
|
|
669
|
+
if (w === box.w && h === box.h) return box;
|
|
670
|
+
return {
|
|
671
|
+
...box,
|
|
672
|
+
w,
|
|
673
|
+
h,
|
|
674
|
+
...box.ports === void 0 ? {} : { ports: box.ports.map((p) => resizePort(p, box.w, box.h, w, h)) }
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* This function gives the problems of the `resize` of a box. A box without `resize` has no problem.
|
|
679
|
+
* Only a `rect` box without a shape can have a resize. Each bound is a positive finite number.
|
|
680
|
+
* The size of the box is in its bounds, and `aspect` is `keep` or `free`.
|
|
681
|
+
*/
|
|
682
|
+
function resizeProblems(box) {
|
|
683
|
+
const r = box.resize;
|
|
684
|
+
if (r === void 0) return [];
|
|
685
|
+
const at = `box ${box.id}`;
|
|
686
|
+
if (typeof r !== "object" || r === null) return [`${at}: the resize is not an object`];
|
|
687
|
+
const problems = [];
|
|
688
|
+
if (box.shape !== void 0 || shapeKindOf(box) !== "rect") problems.push(`${at}: only a rect box without a shape can have a resize`);
|
|
689
|
+
for (const k of BOUNDS) {
|
|
690
|
+
const v = r[k];
|
|
691
|
+
if (v !== void 0 && !(typeof v === "number" && v > 0 && Number.isFinite(v))) problems.push(`${at}: the resize bound ${k} ${String(v)} is not positive and finite`);
|
|
692
|
+
}
|
|
693
|
+
if (r.aspect !== void 0 && r.aspect !== "keep" && r.aspect !== "free") problems.push(`${at}: the resize aspect ${String(r.aspect)} is not keep or free`);
|
|
694
|
+
const b = sizeBoundsOf(box);
|
|
695
|
+
if (!(b.minW <= box.w && box.w <= b.maxW)) problems.push(`${at}: the width ${box.w} is not in the resize bounds ${b.minW} to ${b.maxW}`);
|
|
696
|
+
if (!(b.minH <= box.h && box.h <= b.maxH)) problems.push(`${at}: the height ${box.h} is not in the resize bounds ${b.minH} to ${b.maxH}`);
|
|
697
|
+
return problems;
|
|
698
|
+
}
|
|
592
699
|
// src/turn.ts
|
|
593
700
|
/** This function gives the side after a turn of 90 degrees clockwise. */
|
|
594
701
|
function turnSide(side) {
|
|
@@ -625,6 +732,17 @@ function turnMargin(margin) {
|
|
|
625
732
|
left: m.bottom
|
|
626
733
|
};
|
|
627
734
|
}
|
|
735
|
+
/** This function gives the bounds of a resize after the turn: the bounds of the width and of the height change places. */
|
|
736
|
+
function turnResize(resize) {
|
|
737
|
+
const { minW, maxW, minH, maxH, ...rest } = resize;
|
|
738
|
+
return {
|
|
739
|
+
...rest,
|
|
740
|
+
...minH === void 0 ? {} : { minW: minH },
|
|
741
|
+
...maxH === void 0 ? {} : { maxW: maxH },
|
|
742
|
+
...minW === void 0 ? {} : { minH: minW },
|
|
743
|
+
...maxW === void 0 ? {} : { maxH: maxW }
|
|
744
|
+
};
|
|
745
|
+
}
|
|
628
746
|
/** This function gives a region relative to the origin of a box of height `h` after the turn. */
|
|
629
747
|
function turnRegion(region, h) {
|
|
630
748
|
switch (region.kind) {
|
|
@@ -660,7 +778,7 @@ function turnRegion(region, h) {
|
|
|
660
778
|
}
|
|
661
779
|
}
|
|
662
780
|
}
|
|
663
|
-
/** This function gives a box after the turn: the size, the ports, the margin and the
|
|
781
|
+
/** This function gives a box after the turn: the size, the ports, the margin, the shape and the bounds of a resize turn. The position stays. */
|
|
664
782
|
function turnBox(box) {
|
|
665
783
|
return {
|
|
666
784
|
...box,
|
|
@@ -668,7 +786,8 @@ function turnBox(box) {
|
|
|
668
786
|
h: box.w,
|
|
669
787
|
...box.ports === void 0 ? {} : { ports: box.ports.map((p) => turnPort(p, box.h)) },
|
|
670
788
|
...box.margin === void 0 ? {} : { margin: turnMargin(box.margin) },
|
|
671
|
-
...box.shape === void 0 ? {} : { shape: turnRegion(box.shape, box.h) }
|
|
789
|
+
...box.shape === void 0 ? {} : { shape: turnRegion(box.shape, box.h) },
|
|
790
|
+
...box.resize === void 0 ? {} : { resize: turnResize(box.resize) }
|
|
672
791
|
};
|
|
673
792
|
}
|
|
674
793
|
// src/output.ts
|
|
@@ -676,6 +795,8 @@ function turnBox(box) {
|
|
|
676
795
|
* This function gives the input with the output of a packer applied. Each placed box gets its position.
|
|
677
796
|
* A turned box gets its turned size, ports, margin and shape. Each moved obstacle moves.
|
|
678
797
|
* The container gets the size of the output. The router reads this result. It does not read `turn`.
|
|
798
|
+
*
|
|
799
|
+
* A placement with `w` or `h` gives the box that size after the turn (`resizeBox`).
|
|
679
800
|
*/
|
|
680
801
|
function applyPack(input, output) {
|
|
681
802
|
const at = new Map(output.placements.map((p) => [p.id, p]));
|
|
@@ -683,8 +804,9 @@ function applyPack(input, output) {
|
|
|
683
804
|
const boxes = input.boxes.map((box) => {
|
|
684
805
|
const p = at.get(box.id);
|
|
685
806
|
if (p === void 0) return box;
|
|
807
|
+
const turned = p.turn === 90 ? turnBox(box) : box;
|
|
686
808
|
return {
|
|
687
|
-
...p.
|
|
809
|
+
...p.w === void 0 && p.h === void 0 ? turned : resizeBox(turned, p.w ?? turned.w, p.h ?? turned.h),
|
|
688
810
|
x: p.x,
|
|
689
811
|
y: p.y
|
|
690
812
|
};
|
|
@@ -777,6 +899,17 @@ function numberMap(out, v, name) {
|
|
|
777
899
|
}
|
|
778
900
|
/** This function tells if a value is an object whose values are strings. */
|
|
779
901
|
const isStringMap = (v) => isFields$1(v) && Object.values(v).every((s) => typeof s === "string");
|
|
902
|
+
/** This function gives the problems of the field `carried.code` of a record. */
|
|
903
|
+
function codeProblems(code) {
|
|
904
|
+
if (!isFields$1(code)) return ["carried.code is not an object"];
|
|
905
|
+
const out = [];
|
|
906
|
+
for (const key of ["from", "to"]) if (typeof code[key] !== "string" || code[key] === "") out.push(`carried.code.${key} is not a commit`);
|
|
907
|
+
if (out.length === 0 && code["from"] === code["to"]) out.push("carried.code.to is the commit of carried.code.from");
|
|
908
|
+
if (!Number.isInteger(code["audit"]) || code["audit"] < 1) out.push("carried.code.audit is not a count of 1 or more");
|
|
909
|
+
const upper = code["upper"];
|
|
910
|
+
if (typeof upper !== "number" || !(upper > 0 && upper <= 1)) out.push("carried.code.upper is not above 0 and at most 1");
|
|
911
|
+
return out;
|
|
912
|
+
}
|
|
780
913
|
/** This function gives the problems of the field `carried` of a record. */
|
|
781
914
|
function carriedProblems(carried) {
|
|
782
915
|
if (!isFields$1(carried)) return ["carried is not an object"];
|
|
@@ -787,12 +920,13 @@ function carriedProblems(carried) {
|
|
|
787
920
|
"fingerprints"
|
|
788
921
|
]) if (!isStringMap(carried[key])) out.push(`carried.${key} is not a map of strings`);
|
|
789
922
|
if (carried["run"] !== void 0 && typeof carried["run"] !== "string") out.push("carried.run is not a string");
|
|
923
|
+
if (carried["code"] !== void 0) out.push(...codeProblems(carried["code"]));
|
|
790
924
|
if (out.length > 0) return out;
|
|
791
925
|
const from = carried["from"];
|
|
792
926
|
const to = carried["to"];
|
|
793
927
|
const names = (m) => Object.keys(m).sort().join(",");
|
|
794
928
|
if (names(from) === "" || names(from) !== names(to)) out.push("carried.from and carried.to do not name the same engines");
|
|
795
|
-
else if (Object.keys(from).every((name) => from[name] === to[name])) out.push("carried.to has no other version than carried.from");
|
|
929
|
+
else if (carried["code"] === void 0 && Object.keys(from).every((name) => from[name] === to[name])) out.push("carried.to has no other version than carried.from");
|
|
796
930
|
if (Object.keys(carried["fingerprints"]).length === 0) out.push("carried.fingerprints is empty");
|
|
797
931
|
return out;
|
|
798
932
|
}
|
|
@@ -866,6 +1000,7 @@ function parseLayoutRecord(value) {
|
|
|
866
1000
|
}
|
|
867
1001
|
/**
|
|
868
1002
|
* This function gives a record that a run keeps after an engine release, with the field `carried` (L147).
|
|
1003
|
+
* With `facts.code`, the run keeps the record over a change of the measure code. Then the engine versions can be the same.
|
|
869
1004
|
* A record that a run carried before keeps the versions and the run of its measure, so `carried.from` always names the measure.
|
|
870
1005
|
* The function throws a `RangeError` for a skipped record: a skip makes no claim on an output, so the run measures the pair again.
|
|
871
1006
|
* It also throws a `RangeError` when `checkLayoutRecord` refuses the field `carried` of the result.
|
|
@@ -875,11 +1010,17 @@ function carryRecord(record, facts) {
|
|
|
875
1010
|
const from = record.carried?.from ?? facts.from;
|
|
876
1011
|
if (from === void 0) throw new RangeError(`The record of ${record.strategy} on ${record.input} has no carried.from, so the carry needs from.`);
|
|
877
1012
|
const run = record.carried?.run ?? facts.run;
|
|
1013
|
+
const before = record.carried?.code;
|
|
1014
|
+
const code = facts.code === void 0 ? before : {
|
|
1015
|
+
...facts.code,
|
|
1016
|
+
from: before?.from ?? facts.code.from
|
|
1017
|
+
};
|
|
878
1018
|
const carried = {
|
|
879
1019
|
from,
|
|
880
1020
|
to: facts.to,
|
|
881
1021
|
fingerprints: facts.fingerprints,
|
|
882
|
-
...run === void 0 ? {} : { run }
|
|
1022
|
+
...run === void 0 ? {} : { run },
|
|
1023
|
+
...code === void 0 ? {} : { code }
|
|
883
1024
|
};
|
|
884
1025
|
const problems = carriedProblems(carried);
|
|
885
1026
|
if (problems.length > 0) throw new RangeError(`The carry of ${record.strategy} on ${record.input} is bad: ${problems.join(", ")}.`);
|
|
@@ -1412,16 +1553,6 @@ function clipMid(ax, ay, bx, by, r) {
|
|
|
1412
1553
|
const t = (t0 + t1) / 2;
|
|
1413
1554
|
return [ax + t * dx, ay + t * dy];
|
|
1414
1555
|
}
|
|
1415
|
-
/** The even-odd rule over the outer ring and the holes. */
|
|
1416
|
-
function pointInRings(x, y, rings) {
|
|
1417
|
-
let inside = false;
|
|
1418
|
-
for (const ring of rings) for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
|
1419
|
-
const [xi, yi] = ring[i];
|
|
1420
|
-
const [xj, yj] = ring[j];
|
|
1421
|
-
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) inside = !inside;
|
|
1422
|
-
}
|
|
1423
|
-
return inside;
|
|
1424
|
-
}
|
|
1425
1556
|
/**
|
|
1426
1557
|
* This function counts the pairs of a placed box and an obstacle that overlap by more than `tolerance`.
|
|
1427
1558
|
* The box counts with its margin. A box with a shape counts as its bounding box.
|
|
@@ -1444,6 +1575,23 @@ function countObstacleHits(boxes, obstacles, tolerance = DEFAULT_TOLERANCE.overl
|
|
|
1444
1575
|
return count;
|
|
1445
1576
|
}
|
|
1446
1577
|
/**
|
|
1578
|
+
* This function gives the count of the placements whose size is not in the bounds of their box (`sizeFits`).
|
|
1579
|
+
* The bounds are in the axes of the placed box: a turned box has the turned bounds. A placement without `w` or `h` keeps that size of the box.
|
|
1580
|
+
* A placement of an id that is not in the input does not count.
|
|
1581
|
+
*/
|
|
1582
|
+
function countResizeBreaks(input, output) {
|
|
1583
|
+
const was = new Map(input.boxes.map((b) => [b.id, b]));
|
|
1584
|
+
let count = 0;
|
|
1585
|
+
for (const p of output.placements) {
|
|
1586
|
+
if (p.w === void 0 && p.h === void 0) continue;
|
|
1587
|
+
const box = was.get(p.id);
|
|
1588
|
+
if (box === void 0) continue;
|
|
1589
|
+
const placed = p.turn === 90 ? turnBox(box) : box;
|
|
1590
|
+
if (!sizeFits(placed, p.w ?? placed.w, p.h ?? placed.h)) count++;
|
|
1591
|
+
}
|
|
1592
|
+
return count;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1447
1595
|
* This function gives the count of each hard rule of the output of a packer.
|
|
1448
1596
|
* It applies the output with `applyPack`. Only the placed boxes and the locked boxes count for the overlaps and the container.
|
|
1449
1597
|
* `no-overlap` counts the pairs of boxes and the pairs of a box and an obstacle. A pair of `pairGaps` uses its gap in place of the margins. `HARD_RULE_VERSION` tells the version of these counts.
|
|
@@ -1451,6 +1599,7 @@ function countObstacleHits(boxes, obstacles, tolerance = DEFAULT_TOLERANCE.overl
|
|
|
1451
1599
|
* A locked box without a placement, or with a move of more than `RECORD_EPS`, breaks `locked-kept`.
|
|
1452
1600
|
* A locked box without a position in the input is a bad input, not a break. `checkInput` finds it.
|
|
1453
1601
|
* Another box without a placement that is not in `overflow` breaks `complete`.
|
|
1602
|
+
* `size-kept` is in the result only when a box has `resize` or a placement has `w` or `h` (`countResizeBreaks`).
|
|
1454
1603
|
*
|
|
1455
1604
|
* `options` goes to `countOutside` for `in-container`.
|
|
1456
1605
|
*/
|
|
@@ -1479,14 +1628,21 @@ function packHard(input, output, tolerance = DEFAULT_TOLERANCE.overlap, options
|
|
|
1479
1628
|
boxes: kept
|
|
1480
1629
|
}, tolerance, options),
|
|
1481
1630
|
"locked-kept": lockedMoved,
|
|
1482
|
-
complete: incomplete
|
|
1631
|
+
complete: incomplete,
|
|
1632
|
+
...resizes(input, output) ? { "size-kept": countResizeBreaks(input, output) } : {}
|
|
1483
1633
|
};
|
|
1484
1634
|
}
|
|
1635
|
+
/** This function tells if a box of the input has `resize` or a placement of the output has `w` or `h`. */
|
|
1636
|
+
function resizes(input, output) {
|
|
1637
|
+
return input.boxes.some((b) => b.resize !== void 0) || output.placements.some((p) => p.w !== void 0 || p.h !== void 0);
|
|
1638
|
+
}
|
|
1485
1639
|
/**
|
|
1486
1640
|
* This function gives the problems of an input file. An empty list tells that the file is good.
|
|
1487
1641
|
* A problem is a bad input, not a break of a hard rule. Thus an engine refuses the input.
|
|
1488
1642
|
* In `pairGaps`, an unknown box, a pair of one box, a repeated pair in either order, a bad `gap` and bad `lanes` are problems.
|
|
1489
1643
|
* A port with `along` and no `side`, with `x` or `y`, or with a value outside [0, 1] is a problem.
|
|
1644
|
+
*
|
|
1645
|
+
* A bad `resize` is a problem (`resizeProblems`).
|
|
1490
1646
|
*/
|
|
1491
1647
|
function checkInput(input) {
|
|
1492
1648
|
const problems = [];
|
|
@@ -1499,6 +1655,7 @@ function checkInput(input) {
|
|
|
1499
1655
|
const shape = shapeKindProblem(box);
|
|
1500
1656
|
if (shape !== void 0) problems.push(shape);
|
|
1501
1657
|
for (const port of box.ports ?? []) problems.push(...alongProblems(box.id, port));
|
|
1658
|
+
problems.push(...resizeProblems(box));
|
|
1502
1659
|
}
|
|
1503
1660
|
if (countPortsOffBorder(input.boxes) > 0) problems.push("a fixed port is not on the border of its box");
|
|
1504
1661
|
for (const edge of input.edges ?? []) if (!ids.has(edge.source) || !ids.has(edge.target)) problems.push(`edge ${edge.id}: a box of the edge is not in the input`);
|
|
@@ -2108,7 +2265,7 @@ function frameMove(a, b) {
|
|
|
2108
2265
|
for (const q of b.boxes) {
|
|
2109
2266
|
const p = before.get(q.id);
|
|
2110
2267
|
if (p === void 0) continue;
|
|
2111
|
-
sum +=
|
|
2268
|
+
sum += boxCenterDistance(p, q);
|
|
2112
2269
|
}
|
|
2113
2270
|
return sum;
|
|
2114
2271
|
}
|
|
@@ -2470,6 +2627,8 @@ function byId(a, b) {
|
|
|
2470
2627
|
* The placements, the moved obstacles and the overflow are in the order of their ids. A placement without `turn` gets `turn: 0`.
|
|
2471
2628
|
* Thus two packers with the same result in a different order have the same form.
|
|
2472
2629
|
* The function throws a `RangeError` when `placements`, `overflow` or `moved` has an id two times.
|
|
2630
|
+
*
|
|
2631
|
+
* A placement has `w` and `h` only when the packer set them, so the form of an output without a resize does not change.
|
|
2473
2632
|
*/
|
|
2474
2633
|
function packOutputForm(output) {
|
|
2475
2634
|
uniqueIds("placements", output.placements.map((p) => p.id));
|
|
@@ -2480,7 +2639,9 @@ function packOutputForm(output) {
|
|
|
2480
2639
|
id: p.id,
|
|
2481
2640
|
x: p.x,
|
|
2482
2641
|
y: p.y,
|
|
2483
|
-
turn: p.turn ?? 0
|
|
2642
|
+
turn: p.turn ?? 0,
|
|
2643
|
+
...p.w === void 0 ? {} : { w: p.w },
|
|
2644
|
+
...p.h === void 0 ? {} : { h: p.h }
|
|
2484
2645
|
})).sort(byId),
|
|
2485
2646
|
overflow: [...output.overflow].sort(),
|
|
2486
2647
|
size: {
|
|
@@ -5144,6 +5305,6 @@ const RECT_SCATTERED = /* @__PURE__ */ Object.freeze({
|
|
|
5144
5305
|
};
|
|
5145
5306
|
}
|
|
5146
5307
|
});
|
|
5147
|
-
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CIRCLE_SCATTERED, CORPUS_DIMENSIONS, CORPUS_MANIFEST_SCHEMA, 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, FRAME_SCHEMA, FRAME_STATES, 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, REFUSED_PROBE, 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, carryRecord, catalogChoices, catalogDefaults, catalogKey, catalogOptions, checkCatalog, checkConfig, checkDeclared, checkInput, checkLayoutRecord, checkOptions, checkSchema, checkShapes, checkSpace, checkSplit, circleOverlaps, circlesOutside, clampOptions, compareMeasure, composeFamily, configId, corpusHashOf, corpusManifestText, countLinksThroughShapes, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, createFamilyRegistry, crossingPoint, declarationIssues, declaredClaimOf, declaredCounts, decodeOptionValue, dimensionAt, dimensionSupports, dimensionUnit, documentHash, dropIndex, edgeKeyStep, edgeStep, encodeOptionValue, enumerateSpace, exercised, familyKind, familyOf, fingerprintOf, fixedPointMove, fnv1a32, frameAt, frameMove, frameOf, grow, hardRuleOf, inputShapeLevel, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, lineJson, listOptions, manifestText, marginSides, minEffectOf, mulberry32, nearestGaps, optionDefaults, optionIssue, outputGridClass, outputGroups, outputHash, outputOf, overlapOf, ownerDimension, packHard, packLinks, packOutputForm, paramActive, paramLevels, paramProblem, paramValue, parseLayoutRecord, parseStrategyCatalog, perChange, pickMoves, placedCircle, placedRect, pointSegmentDistance, portPoint, portfolio, probeHash, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resolveDimensions, ruleLevel, scaleRect, segmentThroughShape, segmentsCross, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, shapesOverlap, sharedDimension, snapRect, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, sweepGrid, sweepOf, sweepValues, toLayoutRecord, toPackInput, toRect, toSizedRect, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnSide, verdict, writeStrategyCatalog };
|
|
5308
|
+
export { BALANCE_MEASURE_SUFFIXES, BALANCE_SIDE_DEPTH, CIRCLE_SCATTERED, CORPUS_DIMENSIONS, CORPUS_MANIFEST_SCHEMA, 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, FRAME_SCHEMA, FRAME_STATES, 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, REFUSED_PROBE, 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, boxCenterDistance, canonicalConfig, canonicalInput, canonicalJson, carryRecord, catalogChoices, catalogDefaults, catalogKey, catalogOptions, checkCatalog, checkConfig, checkDeclared, checkInput, checkLayoutRecord, checkOptions, checkSchema, checkShapes, checkSpace, checkSplit, circleOverlaps, circlesOutside, clampOptions, compareMeasure, composeFamily, configId, corpusHashOf, corpusManifestText, countLinksThroughShapes, countObstacleHits, countOutside, countOverlaps, countPortsOffBorder, countResizeBreaks, createFamilyRegistry, crossingPoint, declarationIssues, declaredClaimOf, declaredCounts, decodeOptionValue, dimensionAt, dimensionSupports, dimensionUnit, documentHash, dropIndex, edgeKeyStep, edgeStep, encodeOptionValue, enumerateSpace, exercised, familyKind, familyOf, fingerprintOf, fixedPointMove, fnv1a32, frameAt, frameMove, frameOf, grow, hardRuleOf, inputShapeLevel, isShapeKind, itemShapeOf, joinConfigs, leaveOneSeedOut, levelsOf, lineJson, listOptions, manifestText, marginSides, minEffectOf, mulberry32, nearestGaps, optionDefaults, optionIssue, outputGridClass, outputGroups, outputHash, outputOf, overlapOf, ownerDimension, packHard, packLinks, packOutputForm, paramActive, paramLevels, paramProblem, paramValue, parseLayoutRecord, parseStrategyCatalog, perChange, pickMoves, placedCircle, placedRect, pointInRing, pointInRings, pointSegmentDistance, portPoint, portfolio, probeHash, procrustesOf, productSpace, randomInt, rectInRegion, regionArea, regionHitsRect, resizeBox, resizeProblems, resolveDimensions, ruleLevel, scaleRect, segmentThroughShape, segmentsCross, selectBest, sha256Hex, shapeKindOf, shapeKindProblem, shapeKindsOf, shapeLevel, shapeSupportProblems, shapesOf, shapesOverlap, sharedDimension, sizeBoundsOf, sizeFits, snapRect, spaceShapeKinds, spaceSize, splitConfig, splitFileName, splitFolds, stepRandom, sweepGrid, sweepOf, sweepValues, toLayoutRecord, toPackInput, toRect, toSizedRect, translate, turnBox, turnMargin, turnPoint, turnPort, turnRegion, turnResize, turnSide, verdict, writeStrategyCatalog };
|
|
5148
5309
|
|
|
5149
5310
|
//# sourceMappingURL=index.js.map
|