@mark1russell7/layout-contract 0.10.0 → 0.10.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/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.0",
4
+ "version": "0.10.1",
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.1.0",
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
- /** The compactness of a square: 4 over PI. */
32
- export const SQUARE_COMPACTNESS: number = 4 / Math.PI;
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
- /** 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. */
75
- export const CURVE_MAX_SIDE: number = 2 ** 26;
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
@@ -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
- /** The pattern of a `CostOrder`: terms of `1`, `n`, `e` or `p`, each with an optional `^2`, `^3` or `log`, joined by ` + `. */
60
- const COST_TERM = "(?:1|[nep](?:\\^[23])?(?: log [nep])?)";
61
- const COST_ORDER = /* @__PURE__ */ new RegExp(`^${COST_TERM}(?: \\+ ${COST_TERM})*$`);
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
  );
@@ -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[] = [...COMMON_FIELDS, "min", "max", "step", "scale", "special", "marks", "values"];
227
- const ENUM_FIELDS: readonly string[] = [...COMMON_FIELDS, "values", "custom"];
228
- const STRATEGY_FIELDS: readonly string[] = [...COMMON_FIELDS, "step", "kinds", "optionsKey", "inlineOptions", "optIn", "needs"];
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[] = [...COMMON_FIELDS, "of", "min", "max"];
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. */