@mark1russell7/packing 0.1.5 → 0.1.7

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/build/index.d.ts CHANGED
@@ -343,6 +343,8 @@ interface Item {
343
343
  margin?: number | Margin;
344
344
  /** The ports. The packer keeps them, and turns them with the item. */
345
345
  ports?: Port[];
346
+ /** The free data of the item. The packer does not read it, and the turn and the converters keep it. */
347
+ data?: Readonly<Record<string, unknown>>;
346
348
  }
347
349
  /** The input of a packing: a `layout-input/1` file without `edges`, with `items` for `boxes`. */
348
350
  interface PackInput {
@@ -431,6 +433,20 @@ interface MeasureSpec {
431
433
  min: number;
432
434
  /** The highest value. The value `Infinity` tells that the measure has no upper limit. */
433
435
  max: number;
436
+ /**
437
+ * The floor is the best value of a guard measure. The floor rule of `docs/PROMOTION.md` of `highways` reads it. Each
438
+ * guard of the packer has the floor 0. A measure without a floor has no floor rule.
439
+ */
440
+ floor?: number;
441
+ /**
442
+ * The tolerance is the absolute tolerance at the floor. A candidate within the tolerance ties with a default at the floor.
443
+ *
444
+ * - `pack.order.inversions` and `pack.overflow` have the tolerance 0. Thus each new inversion and each new unplaced item is a loss.
445
+ * - `pack.aspectError` has 0.01, approximately 1% of the aspect. An exact tiling gives the default an error of 0.
446
+ * - `pack.stability.mean` has 0.005 container widths, and `pack.stability.q95` has 0.01. The default often moves no item.
447
+ * - `pack.stability.moved` has 0.02: 2% of the items that stay. On a small change, the default often moves no item.
448
+ */
449
+ tol?: number;
434
450
  }
435
451
  /** The measures of one layout, by id. `measure` gives them. The values are not rounded. */
436
452
  interface LayoutMeasures {
@@ -460,7 +476,10 @@ interface MeasureOptions {
460
476
  */
461
477
  rowTolerance?: number;
462
478
  }
463
- /** The facts of each measure, by id. `docs/MEASURES.md` gives the full definitions. */
479
+ /**
480
+ * The facts of each measure, by id. `docs/MEASURES.md` gives the full definitions. This record is the source of the floor
481
+ * and the tolerance of each guard of the packer.
482
+ */
464
483
  export declare const MEASURE_SPECS: Readonly<Record<MeasureId, MeasureSpec>>;
465
484
  /**
466
485
  * This function gives the measures of one layout, by the ids of `docs/MEASURES.md`. The values are not rounded. A
@@ -519,8 +538,11 @@ export declare function quantile(values: readonly number[], q: number): number;
519
538
  export declare function medianRatio(ratios: readonly number[]): number;
520
539
  /** This function gives the share of the paired ratios above a limit. An empty list throws a `RangeError`. */
521
540
  export declare function tailShare(ratios: readonly number[], limit: number): number;
522
- /** For each dimension of the taxonomy, the values that a strategy supports. `docs/research/TAXONOMY.md` gives the values. */
523
- interface Supports {
541
+ /**
542
+ * For each dimension of the taxonomy, the values that a strategy supports. `docs/research/TAXONOMY.md` gives the values.
543
+ * The type is an alias, not an interface. Thus it fits the record `Supports` of the contract.
544
+ */
545
+ type Supports = {
524
546
  containerSize: ("fixed" | "freeHeight" | "freeWidth" | "freeAspect" | "freeArea")[];
525
547
  containerShape: ("rect" | "convex" | "polygon" | "circle" | "ellipse" | "holes")[];
526
548
  /** The movement of the obstacles. An empty list supports only an input with no obstacle and no locked item. */
@@ -530,7 +552,7 @@ interface Supports {
530
552
  order: ("free" | "soft" | "hard")[];
531
553
  groups: ("none" | "flat" | "nested")[];
532
554
  mode: ("offline" | "online" | "incremental")[];
533
- }
555
+ };
534
556
  /** A dimension of `Supports`. */
535
557
  type Dimension = keyof Supports;
536
558
  /** A value of a dimension of `Supports`. */
@@ -692,11 +714,16 @@ interface HardBreaks {
692
714
  * This function counts the breaks of the 4 hard rules of the packer for an output.
693
715
  *
694
716
  * - `no-overlap`: each pair of items with their margins, and each pair of an item and an obstacle, that overlap by more than `tolerance.overlap`.
695
- * - `in-container`: each item with its margin that goes out of a fixed side by more than `tolerance.overlap`.
696
- * - `locked-kept`: each locked item that moved by more than `RECORD_EPS`, or that has no position.
697
- * - `complete`: each item with no position that is not in the overflow.
717
+ * - `in-container`: each item with its margin that goes out of a fixed side by more than `tolerance.overlap`. The inset of
718
+ * the container makes each fixed side smaller (decision 3 of `docs/PACKER.md`).
719
+ * - `locked-kept`: each locked item that moved by more than `RECORD_EPS`, or that has no placement.
720
+ * - `complete`: each item with no placement that is not in the overflow. A locked item breaks `locked-kept` in its place.
721
+ *
722
+ * A locked item with no placement stays at its input position for `no-overlap` and `in-container`. A locked item with no
723
+ * `x` or no `y` in the input is not locked for these rules.
698
724
  *
699
- * The rules read a shape of the container or of an obstacle as its bounding box. The result has no tolerance in it.
725
+ * The rules read a shape of the container, of an obstacle or of an item as its bounding box (decision 5). The bounding box
726
+ * of an item shape is relative to the position of the item. The result has no tolerance in it.
700
727
  */
701
728
  export declare function checkHard(input: PackInput, output: PackOutput, tolerance?: Pick<Tolerance, "overlap">): HardBreaks;
702
729
  /** An edge between two boxes. The router reads it, and the packer ignores it. */
@@ -706,6 +733,8 @@ interface Edge {
706
733
  target: string;
707
734
  sourcePort?: string;
708
735
  targetPort?: string;
736
+ /** The free data of the edge. The packer does not read it. */
737
+ data?: Readonly<Record<string, unknown>>;
709
738
  }
710
739
  /** The parameters of a generator: a name and a string or a number for each parameter. */
711
740
  type GeneratorParams = Record<string, string | number>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/pack.ts","../src/skyline.ts","../src/shelf.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/contract.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/check.ts","../src/layout-input.ts","../src/generators.ts","../src/corpus.ts"],"mappings":";qBACa;;EAIX,YAAY,YAAO;;MAMf;MACA,EAAE;;MAEF;MACA,EAAE;;EAGN,IAAI,WAAW;;EAMf,MAAM,GAAG;;EAMT,IAAI,OAAO,SAAS;;EAKpB;;EAKA,SAAS;;EAKT,MAAM,KAAK,QAAQ,KAAK,SAAS;;SAQ1B,GAAG,iBAAiB;;SAKpB,IAAI,SAAS,WAAW;;SASxB,IAAI,SAAS,WAAW;;aASpB,YAAY;;;qBCxEZ,KAAK;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AAgB;;KA2B3B;EACV,eAAe;EACf;;;qBA0BW,SAAS,gBAAgB;;qBAWzB,WAAW,gBAAgB;;qBAS3B,OAAO,gBAAgB;;qBAUvB,WAAW,gBAAgB;;KAY5B;;KAGA;EAAmB,MAAM;EAAU;;;;;;;;;;;qBAoBlC,WAAW,gBAAgB;;qBAwF3B,qBAAqB;;wBAGlB,UAAU,eAAe;;UCjqBxB;;EAEf;;EAEA;;EAEA,SAAS;EACT;;;UAIe;EACf;EACA;EACA,MAAM;;;UAIS;EACf;;EAEA;;EAEA;IAAS;IAAmB;IAAiB,QAAQ;IAAiB;;EACtE,QAAQ;;;UAIO;EACf,UAAU;EACV,QAAQ;;;;;;wBAOM,OAAO,cAAc,gBAAgB,eAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/pack.ts","../src/skyline.ts","../src/shelf.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/contract.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/check.ts","../src/layout-input.ts","../src/generators.ts","../src/corpus.ts"],"mappings":";qBACa;;EAIX,YAAY,YAAO;;MAMf;MACA,EAAE;;MAEF;MACA,EAAE;;EAGN,IAAI,WAAW;;EAMf,MAAM,GAAG;;EAMT,IAAI,OAAO,SAAS;;EAKpB;;EAKA,SAAS;;EAKT,MAAM,KAAK,QAAQ,KAAK,SAAS;;SAQ1B,GAAG,iBAAiB;;SAKpB,IAAI,SAAS,WAAW;;SASxB,IAAI,SAAS,WAAW;;aASpB,YAAY;;;qBCxEZ,KAAK;;;EAKhB,KAAK;;EAEL;;EAEA;;EAEA;;;;;EAKA;;MAGI,YAAY;;MAEZ,QAAQ;;EAGZ;;EAEA;;EAGA,WAAW;;EAOX,YAAY,QAAQ;;EAMpB;;SAGO,OAAO,GAAG,OAAO,KAAK,OAAO,KAAK;;SAKlC,SAAS,GAAG,OAAO,KAAK,OAAO,KAAK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AmB,MAAM;EAAU;;;;;;;;;;;qBAoBlC,WAAW,gBAAgB;;qBAwF3B,qBAAqB;;wBAGlB,UAAU,eAAe;;UCjqBxB;;EAEf;;EAEA;;EAEA,SAAS;EACT;;;UAIe;EACf;EACA;EACA,MAAM;;;UAIS;EACf;;EAEA;;EAEA;IAAS;IAAmB;IAAiB,QAAQ;IAAiB;;EACtE,QAAQ;;;UAIO;EACf,UAAU;EACV,QAAQ;;;;;;wBAOM,OAAO,cAAc,gBAAgB,eAAe"}
package/build/index.js CHANGED
@@ -911,28 +911,50 @@ function toPackInput(file) {
911
911
  return input;
912
912
  }
913
913
  // src/measures.ts
914
- const spec = (id, family, unit, direction, min, max) => ({
914
+ const spec = (id, family, unit, direction, min, max, guard) => ({
915
915
  id,
916
916
  family,
917
917
  unit,
918
918
  direction,
919
919
  min,
920
- max
920
+ max,
921
+ ...guard
921
922
  });
922
- /** The facts of each measure, by id. `docs/MEASURES.md` gives the full definitions. */
923
+ /**
924
+ * The facts of each measure, by id. `docs/MEASURES.md` gives the full definitions. This record is the source of the floor
925
+ * and the tolerance of each guard of the packer.
926
+ */
923
927
  const MEASURE_SPECS = Object.freeze({
924
928
  "pack.area": spec("pack.area", "density", "square units", "lower", 0, Infinity),
925
929
  "pack.fill": spec("pack.fill", "density", "share", "higher", 0, 1),
926
930
  "pack.whitespace": spec("pack.whitespace", "density", "share", "lower", 0, 1),
927
931
  "pack.aspect": spec("pack.aspect", "aspect", "ratio", "lower", 1, Infinity),
928
- "pack.aspectError": spec("pack.aspectError", "aspect", "natural log", "lower", 0, Infinity),
929
- "pack.order.inversions": spec("pack.order.inversions", "order", "share", "lower", 0, 1),
932
+ "pack.aspectError": spec("pack.aspectError", "aspect", "natural log", "lower", 0, Infinity, {
933
+ floor: 0,
934
+ tol: .01
935
+ }),
936
+ "pack.order.inversions": spec("pack.order.inversions", "order", "share", "lower", 0, 1, {
937
+ floor: 0,
938
+ tol: 0
939
+ }),
930
940
  "pack.order.breaks": spec("pack.order.breaks", "order", "count", "lower", 0, Infinity),
931
941
  "pack.raggedness": spec("pack.raggedness", "raggedness", "share", "lower", 0, 1),
932
- "pack.overflow": spec("pack.overflow", "overflow", "count", "lower", 0, Infinity),
933
- "pack.stability.moved": spec("pack.stability.moved", "stability", "share", "lower", 0, 1),
934
- "pack.stability.mean": spec("pack.stability.mean", "stability", "container widths", "lower", 0, Infinity),
935
- "pack.stability.q95": spec("pack.stability.q95", "stability", "container widths", "lower", 0, Infinity),
942
+ "pack.overflow": spec("pack.overflow", "overflow", "count", "lower", 0, Infinity, {
943
+ floor: 0,
944
+ tol: 0
945
+ }),
946
+ "pack.stability.moved": spec("pack.stability.moved", "stability", "share", "lower", 0, 1, {
947
+ floor: 0,
948
+ tol: .02
949
+ }),
950
+ "pack.stability.mean": spec("pack.stability.mean", "stability", "container widths", "lower", 0, Infinity, {
951
+ floor: 0,
952
+ tol: .005
953
+ }),
954
+ "pack.stability.q95": spec("pack.stability.q95", "stability", "container widths", "lower", 0, Infinity, {
955
+ floor: 0,
956
+ tol: .01
957
+ }),
936
958
  "pack.deterministic": spec("pack.deterministic", "determinism", "boolean", "higher", 0, 1),
937
959
  "pack.search.widths": spec("pack.search.widths", "speed", "count", "lower", 0, Infinity),
938
960
  "pack.search.ms": spec("pack.search.ms", "speed", "milliseconds", "lower", 0, Infinity)
@@ -2050,11 +2072,16 @@ function overlap(a, b, tolerance) {
2050
2072
  * This function counts the breaks of the 4 hard rules of the packer for an output.
2051
2073
  *
2052
2074
  * - `no-overlap`: each pair of items with their margins, and each pair of an item and an obstacle, that overlap by more than `tolerance.overlap`.
2053
- * - `in-container`: each item with its margin that goes out of a fixed side by more than `tolerance.overlap`.
2054
- * - `locked-kept`: each locked item that moved by more than `RECORD_EPS`, or that has no position.
2055
- * - `complete`: each item with no position that is not in the overflow.
2075
+ * - `in-container`: each item with its margin that goes out of a fixed side by more than `tolerance.overlap`. The inset of
2076
+ * the container makes each fixed side smaller (decision 3 of `docs/PACKER.md`).
2077
+ * - `locked-kept`: each locked item that moved by more than `RECORD_EPS`, or that has no placement.
2078
+ * - `complete`: each item with no placement that is not in the overflow. A locked item breaks `locked-kept` in its place.
2079
+ *
2080
+ * A locked item with no placement stays at its input position for `no-overlap` and `in-container`. A locked item with no
2081
+ * `x` or no `y` in the input is not locked for these rules.
2056
2082
  *
2057
- * The rules read a shape of the container or of an obstacle as its bounding box. The result has no tolerance in it.
2083
+ * The rules read a shape of the container, of an obstacle or of an item as its bounding box (decision 5). The bounding box
2084
+ * of an item shape is relative to the position of the item. The result has no tolerance in it.
2058
2085
  */
2059
2086
  function checkHard(input, output, tolerance = DEFAULT_TOLERANCE) {
2060
2087
  const tol = tolerance.overlap;
@@ -2069,22 +2096,36 @@ function checkHard(input, output, tolerance = DEFAULT_TOLERANCE) {
2069
2096
  };
2070
2097
  const boxes = [];
2071
2098
  for (const item of input.items) {
2072
- const p = placements.get(item.id);
2099
+ const lockedAt = item.locked === true && item.x !== void 0 && item.y !== void 0 ? {
2100
+ x: item.x,
2101
+ y: item.y
2102
+ } : void 0;
2103
+ let p = placements.get(item.id);
2073
2104
  if (p === void 0) {
2074
- if (item.locked === true && item.x !== void 0 && item.y !== void 0) breaks["locked-kept"] += 1;
2075
- if (!overflow.has(item.id)) breaks.complete += 1;
2076
- continue;
2077
- }
2078
- if (item.locked === true && item.x !== void 0 && item.y !== void 0) {
2079
- if (Math.abs(p.x - item.x) > .001 || Math.abs(p.y - item.y) > .001) breaks["locked-kept"] += 1;
2105
+ if (lockedAt === void 0) {
2106
+ if (!overflow.has(item.id)) breaks.complete += 1;
2107
+ continue;
2108
+ }
2109
+ breaks["locked-kept"] += 1;
2110
+ p = lockedAt;
2111
+ } else if (lockedAt !== void 0) {
2112
+ if (Math.abs(p.x - lockedAt.x) > .001 || Math.abs(p.y - lockedAt.y) > .001) breaks["locked-kept"] += 1;
2080
2113
  }
2081
2114
  const placed = p.turn === 90 ? turnItem(item) : item;
2082
2115
  const m = marginOf(placed);
2116
+ const area = placed.shape === void 0 ? {
2117
+ x: 0,
2118
+ y: 0,
2119
+ w: placed.w,
2120
+ h: placed.h
2121
+ } : boundsOf(placed.shape);
2122
+ const l = p.x + area.x;
2123
+ const t = p.y + area.y;
2083
2124
  boxes.push({
2084
- l: p.x - m.left,
2085
- t: p.y - m.top,
2086
- r: p.x + placed.w + m.right,
2087
- b: p.y + placed.h + m.bottom
2125
+ l: l - m.left,
2126
+ t: t - m.top,
2127
+ r: l + area.w + m.right,
2128
+ b: t + area.h + m.bottom
2088
2129
  });
2089
2130
  }
2090
2131
  const moved = new Map(output.moved.map((m) => [m.id, m]));
@@ -2108,11 +2149,12 @@ function checkHard(input, output, tolerance = DEFAULT_TOLERANCE) {
2108
2149
  const y = shape?.y ?? 0;
2109
2150
  const w = shape?.w ?? container.w ?? Infinity;
2110
2151
  const h = shape?.h ?? container.h ?? Infinity;
2152
+ const inset = container.inset ?? 0;
2111
2153
  const fixedW = container.fixed === "size" || container.fixed === "width";
2112
2154
  const fixedH = container.fixed === "size" || container.fixed === "height";
2113
2155
  for (const box of boxes) {
2114
- const outX = fixedW && (box.l < x - tol || box.r > x + w + tol);
2115
- const outY = fixedH && (box.t < y - tol || box.b > y + h + tol);
2156
+ const outX = fixedW && (box.l < x + inset - tol || box.r > x + w - inset + tol);
2157
+ const outY = fixedH && (box.t < y + inset - tol || box.b > y + h - inset + tol);
2116
2158
  if (outX || outY) breaks["in-container"] += 1;
2117
2159
  }
2118
2160
  return breaks;