@mark1russell7/layout-contract 0.10.0 → 0.10.2
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 +124 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +286 -43
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/cell.ts +5 -2
- package/src/curves.ts +19 -16
- package/src/geometry3.ts +260 -0
- package/src/index.ts +1 -0
- package/src/measure-registry.ts +6 -4
- package/src/strategy-catalog.ts +4 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/layout-contract",
|
|
4
|
-
"version": "0.10.
|
|
4
|
+
"version": "0.10.2",
|
|
5
5
|
"description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"layout",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@mark1russell7/cue": "^2.1.1",
|
|
53
53
|
"@types/node": "^26.6.4",
|
|
54
|
-
"@vitest/coverage-v8": "5.
|
|
54
|
+
"@vitest/coverage-v8": "^5.0.3",
|
|
55
55
|
"esbuild": "^0.28.2",
|
|
56
56
|
"fast-check": "^4.10.2",
|
|
57
57
|
"layout-contract-0221": "npm:@mark1russell7/layout-contract@0.2.21",
|
package/src/cell.ts
CHANGED
|
@@ -28,8 +28,11 @@ export type CellMeasureSuffix = "cell.areaError" | "cell.compactness";
|
|
|
28
28
|
/** The suffixes of the cell measures, in the order of `cellMeasureSpecs`. */
|
|
29
29
|
export const CELL_MEASURE_SUFFIXES: readonly CellMeasureSuffix[] = /* @__PURE__ */ Object.freeze(["cell.areaError", "cell.compactness"] as const);
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The compactness of a square: 4 over PI. The value is the literal of `4 / Math.PI`, because a bundler keeps a top-level division, also when
|
|
33
|
+
* no code uses it.
|
|
34
|
+
*/
|
|
35
|
+
export const SQUARE_COMPACTNESS: number = 1.2732395447351628;
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* This function gives the cell measures of the placed items in a container of the area `containerArea`.
|
package/src/curves.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type CurveSymmetry =
|
|
|
27
27
|
| "flip-t";
|
|
28
28
|
|
|
29
29
|
/** The 8 symmetries of a square, in a fixed order. */
|
|
30
|
-
export const CURVE_SYMMETRIES: readonly CurveSymmetry[] = Object.freeze(["same", "swap", "back", "half", "rise", "fall", "flip-s", "flip-t"]);
|
|
30
|
+
export const CURVE_SYMMETRIES: readonly CurveSymmetry[] = /* @__PURE__ */ Object.freeze(["same", "swap", "back", "half", "rise", "fall", "flip-s", "flip-t"]);
|
|
31
31
|
|
|
32
32
|
/** A quadrant of a square: `[0, 0]` is the low left quadrant, and `[1, 0]` is the quadrant with the high `s` and the low `t`. */
|
|
33
33
|
export type CurveQuadrant = readonly [0 | 1, 0 | 1];
|
|
@@ -44,35 +44,38 @@ export interface CurveSpec {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
/** The order of the parts of the Hilbert and Moore curves: low left, high left, high right and low right. */
|
|
47
|
-
const LOOP_ORDER: CurveSpec["order"] = Object.freeze([
|
|
48
|
-
Object.freeze([0, 0] as const),
|
|
49
|
-
Object.freeze([0, 1] as const),
|
|
50
|
-
Object.freeze([1, 1] as const),
|
|
51
|
-
Object.freeze([1, 0] as const),
|
|
47
|
+
const LOOP_ORDER: CurveSpec["order"] = /* @__PURE__ */ Object.freeze([
|
|
48
|
+
/* @__PURE__ */ Object.freeze([0, 0] as const),
|
|
49
|
+
/* @__PURE__ */ Object.freeze([0, 1] as const),
|
|
50
|
+
/* @__PURE__ */ Object.freeze([1, 1] as const),
|
|
51
|
+
/* @__PURE__ */ Object.freeze([1, 0] as const),
|
|
52
52
|
]);
|
|
53
53
|
|
|
54
54
|
/** The parts of the Hilbert curve. The curve goes in at the corner `(0, 0)` and out at the corner `(size, 0)`. */
|
|
55
|
-
export const HILBERT_PATTERN: CurvePattern = Object.freeze(["swap", "same", "same", "back"] as const);
|
|
55
|
+
export const HILBERT_PATTERN: CurvePattern = /* @__PURE__ */ Object.freeze(["swap", "same", "same", "back"] as const);
|
|
56
56
|
|
|
57
57
|
/** The top level of the Moore curve: four Hilbert curves in a loop. The loop goes in and out at the middle of the side `t = 0`. */
|
|
58
|
-
export const MOORE_PATTERN: CurvePattern = Object.freeze(["rise", "rise", "fall", "fall"] as const);
|
|
58
|
+
export const MOORE_PATTERN: CurvePattern = /* @__PURE__ */ Object.freeze(["rise", "rise", "fall", "fall"] as const);
|
|
59
59
|
|
|
60
60
|
/** The Hilbert curve. Two cells in a row along the curve share a side. */
|
|
61
|
-
export const HILBERT_CURVE: CurveSpec = Object.freeze({ name: "hilbert", order: LOOP_ORDER, root: HILBERT_PATTERN, child: HILBERT_PATTERN });
|
|
61
|
+
export const HILBERT_CURVE: CurveSpec = /* @__PURE__ */ Object.freeze({ name: "hilbert", order: LOOP_ORDER, root: HILBERT_PATTERN, child: HILBERT_PATTERN });
|
|
62
62
|
|
|
63
63
|
/** The Moore curve. Two cells in a row share a side, and the last cell shares a side with the first cell. */
|
|
64
|
-
export const MOORE_CURVE: CurveSpec = Object.freeze({ name: "moore", order: LOOP_ORDER, root: MOORE_PATTERN, child: HILBERT_PATTERN });
|
|
64
|
+
export const MOORE_CURVE: CurveSpec = /* @__PURE__ */ Object.freeze({ name: "moore", order: LOOP_ORDER, root: MOORE_PATTERN, child: HILBERT_PATTERN });
|
|
65
65
|
|
|
66
66
|
/** The Morton curve (the Z order). The index of a cell has the bits of `x` at the even places and the bits of `y` at the odd places. */
|
|
67
|
-
export const MORTON_CURVE: CurveSpec = Object.freeze({
|
|
67
|
+
export const MORTON_CURVE: CurveSpec = /* @__PURE__ */ Object.freeze({
|
|
68
68
|
name: "morton",
|
|
69
|
-
order: Object.freeze([Object.freeze([0, 0] as const), Object.freeze([1, 0] as const), Object.freeze([0, 1] as const), Object.freeze([1, 1] as const)] as const),
|
|
70
|
-
root: Object.freeze(["same", "same", "same", "same"] as const),
|
|
71
|
-
child: Object.freeze(["same", "same", "same", "same"] as const),
|
|
69
|
+
order: /* @__PURE__ */ Object.freeze([/* @__PURE__ */ Object.freeze([0, 0] as const), /* @__PURE__ */ Object.freeze([1, 0] as const), /* @__PURE__ */ Object.freeze([0, 1] as const), /* @__PURE__ */ Object.freeze([1, 1] as const)] as const),
|
|
70
|
+
root: /* @__PURE__ */ Object.freeze(["same", "same", "same", "same"] as const),
|
|
71
|
+
child: /* @__PURE__ */ Object.freeze(["same", "same", "same", "same"] as const),
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The largest side of a curve grid: 2 to the power 26. Thus each index is less than 2 to the power 52, and is exact. The value is a literal,
|
|
76
|
+
* because a bundler keeps a top-level `2 ** 26`, also when no code uses it.
|
|
77
|
+
*/
|
|
78
|
+
export const CURVE_MAX_SIDE: number = 67_108_864;
|
|
76
79
|
|
|
77
80
|
/**
|
|
78
81
|
* This function gives a point of the square `[0, size] x [0, size]` after a symmetry. The cell `(x, y)` of a grid of
|
package/src/geometry3.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 3D records: points, boxes with their sides along the axes, rotations and rigid transforms.
|
|
3
|
+
* The three axes make a right-handed system. The records give no meaning to an axis and no unit to a length.
|
|
4
|
+
* `docs/GEOMETRY-3D.md` gives the rules.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A point or a vector in 3D. */
|
|
8
|
+
export interface Point3 {
|
|
9
|
+
readonly x: number;
|
|
10
|
+
readonly y: number;
|
|
11
|
+
readonly z: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The point at the origin. It is also the vector of length 0. */
|
|
15
|
+
export const ORIGIN3: Point3 = { x: 0, y: 0, z: 0 };
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A box with its sides along the axes: the corner with the smallest coordinates, and its size.
|
|
19
|
+
* `w` is the size along x, `h` is the size along y, and `d` is the size along z.
|
|
20
|
+
*/
|
|
21
|
+
export interface Box3 {
|
|
22
|
+
readonly x: number;
|
|
23
|
+
readonly y: number;
|
|
24
|
+
readonly z: number;
|
|
25
|
+
readonly w: number;
|
|
26
|
+
readonly h: number;
|
|
27
|
+
readonly d: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A rotation about the origin, as a unit quaternion. `w` is the scalar part.
|
|
32
|
+
* The glTF format and three.js keep the four numbers in the same order.
|
|
33
|
+
*/
|
|
34
|
+
export interface Rotation3 {
|
|
35
|
+
readonly x: number;
|
|
36
|
+
readonly y: number;
|
|
37
|
+
readonly z: number;
|
|
38
|
+
readonly w: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The rotation that moves no point. */
|
|
42
|
+
export const NO_ROTATION3: Rotation3 = { x: 0, y: 0, z: 0, w: 1 };
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A rigid transform: the rotation of a point about the origin, then a move by `position`.
|
|
46
|
+
* It has no scale, because the size of a box is in the box.
|
|
47
|
+
*/
|
|
48
|
+
export interface Transform3 {
|
|
49
|
+
readonly position: Point3;
|
|
50
|
+
readonly rotation: Rotation3;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The transform that moves no point. */
|
|
54
|
+
export const NO_TRANSFORM3: Transform3 = { position: ORIGIN3, rotation: NO_ROTATION3 };
|
|
55
|
+
|
|
56
|
+
/** This function gives the sum of two vectors. */
|
|
57
|
+
export function addPoints3(a: Point3, b: Point3): Point3 {
|
|
58
|
+
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** This function gives the vector from `b` to `a`: `a` minus `b`. */
|
|
62
|
+
export function subtractPoints3(a: Point3, b: Point3): Point3 {
|
|
63
|
+
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** This function gives a vector with each coordinate times `factor`. */
|
|
67
|
+
export function scalePoint3(point: Point3, factor: number): Point3 {
|
|
68
|
+
return { x: point.x * factor, y: point.y * factor, z: point.z * factor };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** This function gives the dot product of two vectors. */
|
|
72
|
+
export function dot3(a: Point3, b: Point3): number {
|
|
73
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** This function gives the cross product of `a` and `b`. In a right-handed system, x cross y is z. */
|
|
77
|
+
export function cross3(a: Point3, b: Point3): Point3 {
|
|
78
|
+
return { x: a.y * b.z - a.z * b.y, y: a.z * b.x - a.x * b.z, z: a.x * b.y - a.y * b.x };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** This function gives the length of a vector. */
|
|
82
|
+
export function length3(vector: Point3): number {
|
|
83
|
+
return Math.hypot(vector.x, vector.y, vector.z);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** This function gives the distance between two points. */
|
|
87
|
+
export function distance3(a: Point3, b: Point3): number {
|
|
88
|
+
return Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* This function gives the rotation by `angle` radians about the line through the origin along `axis`.
|
|
93
|
+
* The rotation follows the right-hand rule: a positive angle about z turns the x axis to the y axis.
|
|
94
|
+
* An axis of length 0, or a number that is not finite, gives a `RangeError`.
|
|
95
|
+
*/
|
|
96
|
+
export function rotationAbout(axis: Point3, angle: number): Rotation3 {
|
|
97
|
+
const length = length3(axis);
|
|
98
|
+
if (!Number.isFinite(length) || length === 0 || !Number.isFinite(angle)) {
|
|
99
|
+
throw new RangeError("A rotation needs a finite angle and a finite axis with a length above 0.");
|
|
100
|
+
}
|
|
101
|
+
const factor = Math.sin(angle / 2) / length;
|
|
102
|
+
return { x: axis.x * factor, y: axis.y * factor, z: axis.z * factor, w: Math.cos(angle / 2) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* This function gives the rotation `inner`, then the rotation `outer`, as one rotation.
|
|
107
|
+
* It is the quaternion product of `outer` and `inner`.
|
|
108
|
+
*/
|
|
109
|
+
export function composeRotations3(outer: Rotation3, inner: Rotation3): Rotation3 {
|
|
110
|
+
return {
|
|
111
|
+
x: outer.w * inner.x + outer.x * inner.w + outer.y * inner.z - outer.z * inner.y,
|
|
112
|
+
y: outer.w * inner.y - outer.x * inner.z + outer.y * inner.w + outer.z * inner.x,
|
|
113
|
+
z: outer.w * inner.z + outer.x * inner.y - outer.y * inner.x + outer.z * inner.w,
|
|
114
|
+
w: outer.w * inner.w - outer.x * inner.x - outer.y * inner.y - outer.z * inner.z,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** This function gives the rotation that moves each point back. It is the conjugate of a unit quaternion. */
|
|
119
|
+
export function inverseRotation3(rotation: Rotation3): Rotation3 {
|
|
120
|
+
return { x: -rotation.x, y: -rotation.y, z: -rotation.z, w: rotation.w };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* This function gives the rotation with the length 1. Many products of rotations collect small float errors, and this function removes them.
|
|
125
|
+
* A quaternion of length 0, or a number that is not finite, gives a `RangeError`.
|
|
126
|
+
*/
|
|
127
|
+
export function normalizeRotation3(rotation: Rotation3): Rotation3 {
|
|
128
|
+
const length = Math.hypot(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
129
|
+
if (!Number.isFinite(length) || length === 0) throw new RangeError("A rotation needs a finite quaternion with a length above 0.");
|
|
130
|
+
return { x: rotation.x / length, y: rotation.y / length, z: rotation.z / length, w: rotation.w / length };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** This function gives the point after the rotation. The rotation is a unit quaternion. */
|
|
134
|
+
export function rotatePoint3(rotation: Rotation3, point: Point3): Point3 {
|
|
135
|
+
// The point plus two times the cross products: v + 2w (q × v) + 2 q × (q × v).
|
|
136
|
+
const first = cross3(rotation, point);
|
|
137
|
+
const second = cross3(rotation, first);
|
|
138
|
+
return {
|
|
139
|
+
x: point.x + 2 * (rotation.w * first.x + second.x),
|
|
140
|
+
y: point.y + 2 * (rotation.w * first.y + second.y),
|
|
141
|
+
z: point.z + 2 * (rotation.w * first.z + second.z),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** This function gives the point after the transform: the rotation, then the move. */
|
|
146
|
+
export function transformPoint3(transform: Transform3, point: Point3): Point3 {
|
|
147
|
+
return addPoints3(rotatePoint3(transform.rotation, point), transform.position);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* This function gives the transform `inner`, then the transform `outer`, as one transform.
|
|
152
|
+
* Thus `inner` is the place of a part in its parent, and `outer` is the place of the parent.
|
|
153
|
+
*/
|
|
154
|
+
export function composeTransforms3(outer: Transform3, inner: Transform3): Transform3 {
|
|
155
|
+
return {
|
|
156
|
+
position: transformPoint3(outer, inner.position),
|
|
157
|
+
rotation: composeRotations3(outer.rotation, inner.rotation),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** This function gives the transform that moves each point back. */
|
|
162
|
+
export function inverseTransform3(transform: Transform3): Transform3 {
|
|
163
|
+
const rotation = inverseRotation3(transform.rotation);
|
|
164
|
+
return { position: scalePoint3(rotatePoint3(rotation, transform.position), -1), rotation };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* This function gives the 4 by 4 matrix of a transform as 16 numbers, column by column.
|
|
169
|
+
* WebGL, the glTF format and three.js read a matrix in this order.
|
|
170
|
+
*/
|
|
171
|
+
export function transformMatrix4(transform: Transform3): readonly number[] {
|
|
172
|
+
const { x, y, z, w } = transform.rotation;
|
|
173
|
+
const { position } = transform;
|
|
174
|
+
return [
|
|
175
|
+
1 - 2 * (y * y + z * z),
|
|
176
|
+
2 * (x * y + w * z),
|
|
177
|
+
2 * (x * z - w * y),
|
|
178
|
+
0,
|
|
179
|
+
2 * (x * y - w * z),
|
|
180
|
+
1 - 2 * (x * x + z * z),
|
|
181
|
+
2 * (y * z + w * x),
|
|
182
|
+
0,
|
|
183
|
+
2 * (x * z + w * y),
|
|
184
|
+
2 * (y * z - w * x),
|
|
185
|
+
1 - 2 * (x * x + y * y),
|
|
186
|
+
0,
|
|
187
|
+
position.x,
|
|
188
|
+
position.y,
|
|
189
|
+
position.z,
|
|
190
|
+
1,
|
|
191
|
+
];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** This function gives the center of a box. */
|
|
195
|
+
export function box3Center(box: Box3): Point3 {
|
|
196
|
+
return { x: box.x + box.w / 2, y: box.y + box.h / 2, z: box.z + box.d / 2 };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** This function gives the volume of a box. */
|
|
200
|
+
export function box3Volume(box: Box3): number {
|
|
201
|
+
return box.w * box.h * box.d;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* This function gives the 8 corners of a box. The corner at the index `i` has the largest x when bit 0 of `i` is 1.
|
|
206
|
+
* Bit 1 gives the largest y, and bit 2 gives the largest z. Thus the corner 0 is the corner of the box record.
|
|
207
|
+
*/
|
|
208
|
+
export function box3Corners(box: Box3): readonly Point3[] {
|
|
209
|
+
const corners: Point3[] = [];
|
|
210
|
+
for (let index = 0; index < 8; index += 1) {
|
|
211
|
+
corners.push({
|
|
212
|
+
x: box.x + (index & 1) * box.w,
|
|
213
|
+
y: box.y + ((index >> 1) & 1) * box.h,
|
|
214
|
+
z: box.z + ((index >> 2) & 1) * box.d,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return corners;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** This function gives the smallest box that holds each point, or `undefined` for no points. */
|
|
221
|
+
export function boundsOf3(points: readonly Point3[]): Box3 | undefined {
|
|
222
|
+
const first = points[0];
|
|
223
|
+
if (first === undefined) return undefined;
|
|
224
|
+
let minX = first.x;
|
|
225
|
+
let minY = first.y;
|
|
226
|
+
let minZ = first.z;
|
|
227
|
+
let maxX = first.x;
|
|
228
|
+
let maxY = first.y;
|
|
229
|
+
let maxZ = first.z;
|
|
230
|
+
for (const point of points) {
|
|
231
|
+
minX = Math.min(minX, point.x);
|
|
232
|
+
minY = Math.min(minY, point.y);
|
|
233
|
+
minZ = Math.min(minZ, point.z);
|
|
234
|
+
maxX = Math.max(maxX, point.x);
|
|
235
|
+
maxY = Math.max(maxY, point.y);
|
|
236
|
+
maxZ = Math.max(maxZ, point.z);
|
|
237
|
+
}
|
|
238
|
+
return { x: minX, y: minY, z: minZ, w: maxX - minX, h: maxY - minY, d: maxZ - minZ };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* This function gives the smallest box along the axes that holds a box after a transform.
|
|
243
|
+
* A box that turns by an angle that is not a quarter turn gets a larger box.
|
|
244
|
+
*/
|
|
245
|
+
export function transformedBounds3(box: Box3, transform: Transform3): Box3 {
|
|
246
|
+
// A box has 8 corners, so the bounds are always present.
|
|
247
|
+
return boundsOf3(box3Corners(box).map((corner) => transformPoint3(transform, corner))) as Box3;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* This function gives the overlap of the insides of two boxes on each axis.
|
|
252
|
+
* A value of 0 or less on an axis is no overlap. Two boxes with a common face have an overlap of 0 on one axis.
|
|
253
|
+
*/
|
|
254
|
+
export function overlapOf3(a: Box3, b: Box3): Point3 {
|
|
255
|
+
return {
|
|
256
|
+
x: Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x),
|
|
257
|
+
y: Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y),
|
|
258
|
+
z: Math.min(a.z + a.d, b.z + b.d) - Math.max(a.z, b.z),
|
|
259
|
+
};
|
|
260
|
+
}
|
package/src/index.ts
CHANGED
package/src/measure-registry.ts
CHANGED
|
@@ -56,9 +56,11 @@ export function unitFault(spec: Pick<MeasureSpec, "unit" | "min" | "max">): stri
|
|
|
56
56
|
*/
|
|
57
57
|
export type CostOrder = string;
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
/**
|
|
60
|
+
* The pattern of a `CostOrder`: terms of `1`, `n`, `e` or `p`, each with an optional `^2`, `^3` or `log`, joined by ` + `. The pattern is a
|
|
61
|
+
* literal, because a bundler keeps a top-level `new RegExp` of a template, also when no code uses it.
|
|
62
|
+
*/
|
|
63
|
+
const COST_ORDER = /^(?:1|[nep](?:\^[23])?(?: log [nep])?)(?: \+ (?:1|[nep](?:\^[23])?(?: log [nep])?))*$/;
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* One entry of the measure registry: the spec of the measure, its source package, its noise, its normalization and its cost.
|
|
@@ -188,5 +190,5 @@ const JOINT_FACTS: Readonly<Record<JointMeasureId, Omit<EntryFacts, "source">>>
|
|
|
188
190
|
* The engines keep the specs of their own measures. `docs/measure-survey.json` lists them, and an engine adopts the registry with `measureEntry`.
|
|
189
191
|
*/
|
|
190
192
|
export const MEASURE_REGISTRY: readonly MeasureEntry<JointMeasureId>[] = /* @__PURE__ */ Object.freeze(
|
|
191
|
-
JOINT_MEASURES.map((spec) => measureEntry(spec, { source: JOINT_SOURCE, ...JOINT_FACTS[spec.id] })),
|
|
193
|
+
/* @__PURE__ */ JOINT_MEASURES.map((spec) => measureEntry(spec, { source: JOINT_SOURCE, ...JOINT_FACTS[spec.id] })),
|
|
192
194
|
);
|
package/src/strategy-catalog.ts
CHANGED
|
@@ -223,11 +223,11 @@ const SCALES: readonly OptionScale[] = ["linear", "log"];
|
|
|
223
223
|
const TOP_FIELDS: readonly string[] = ["schema", "engine", "version", "strategies"];
|
|
224
224
|
const ENTRY_FIELDS: readonly string[] = ["key", "id", "step", "family", "kind", "describe", "supports", "limits", "deterministic", "determinismNote", "optIn", "baseline", "output", "fingerprint", "options"];
|
|
225
225
|
const COMMON_FIELDS: readonly string[] = ["type", "describe", "default", "noDefault", "when"];
|
|
226
|
-
const NUMBER_FIELDS: readonly string[] = [
|
|
227
|
-
const ENUM_FIELDS: readonly string[] = [
|
|
228
|
-
const STRATEGY_FIELDS: readonly string[] = [
|
|
226
|
+
const NUMBER_FIELDS: readonly string[] = /* @__PURE__ */ COMMON_FIELDS.concat(["min", "max", "step", "scale", "special", "marks", "values"]);
|
|
227
|
+
const ENUM_FIELDS: readonly string[] = /* @__PURE__ */ COMMON_FIELDS.concat(["values", "custom"]);
|
|
228
|
+
const STRATEGY_FIELDS: readonly string[] = /* @__PURE__ */ COMMON_FIELDS.concat(["step", "kinds", "optionsKey", "inlineOptions", "optIn", "needs"]);
|
|
229
229
|
const MEMBER_FIELDS: readonly string[] = ["strategy", "options", "id"];
|
|
230
|
-
const LIST_FIELDS: readonly string[] = [
|
|
230
|
+
const LIST_FIELDS: readonly string[] = /* @__PURE__ */ COMMON_FIELDS.concat(["of", "min", "max"]);
|
|
231
231
|
const ROW_FIELDS: readonly string[] = ["property", "class", "evidence"];
|
|
232
232
|
const EVIDENCE_FIELDS: readonly string[] = ["inputs", "fractionalInputs", "nearWholeInputs", "source", "optionSet", "catalogVersion"];
|
|
233
233
|
/** The fields of a declaration, in the order of the file. */
|