@mark1russell7/packing 0.2.12 → 0.2.14

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
@@ -769,7 +769,7 @@ interface AspectFitStrategyOptions {
769
769
  export declare const aspectFitStrategy: Strategy<AspectFitStrategyOptions>;
770
770
  /**
771
771
  * The composite strategies of the registry: each one packs an input with other strategies. They are not in `strategies`.
772
- * Since 0.2.7, the list has `portfolio` of roadmap item k20. Roadmap item k62 adds `aspect-fit`.
772
+ * Since 0.2.7, the list has `portfolio` of roadmap item k20. Roadmap item k62 adds `aspect-fit`, and roadmap item k66 adds `select`.
773
773
  */
774
774
  export declare const composites: readonly Strategy[];
775
775
  /** This function gives the strategy with an id, also a composite strategy. It throws a `RangeError` for an id that the registry does not have. */
@@ -1075,6 +1075,86 @@ interface PortfolioStrategyOptions {
1075
1075
  * - The strategy throws a `RangeError` for a `k` other than 2 or 3, and for `k` with `members`.
1076
1076
  */
1077
1077
  export declare const portfolioStrategy: Strategy<PortfolioStrategyOptions>;
1078
+ /** The cheap features of an input for `select`. One pass over the items and the obstacles gives them. */
1079
+ interface SelectFeatures {
1080
+ /** The count of the items */
1081
+ count: number;
1082
+ /** The value `true` when the container has the size `fixed`. A free width, a free height or a free size gives `false`. */
1083
+ fixed: boolean;
1084
+ /** The value `true` when the container is a rectangle with no obstacle of another shape: the `containerShape` `rect` of `cellOf` */
1085
+ rect: boolean;
1086
+ /** The size spread: `spreadOf`, the standard deviation of the natural log of `sqrt(w * h)` of each item */
1087
+ spread: number;
1088
+ }
1089
+ /** A feature of `SelectFeatures` with a number value. A node of this feature compares the value with `below`. */
1090
+ type SelectNumberFeature = "count" | "spread";
1091
+ /** A feature of `SelectFeatures` with a flag value. */
1092
+ type SelectFlagFeature = "fixed" | "rect";
1093
+ /**
1094
+ * A node of the decision table of `select`.
1095
+ *
1096
+ * - A leaf has `leaf`, its number for the trace, and `pick`, the index of its member in the option `members`.
1097
+ * - A number node goes to `yes` when the feature value is below `below`, else to `no`.
1098
+ * - A flag node goes to `yes` when the feature value is `true`, else to `no`.
1099
+ */
1100
+ type SelectNode = {
1101
+ readonly leaf: number;
1102
+ readonly pick: number;
1103
+ } | {
1104
+ readonly feature: SelectNumberFeature;
1105
+ readonly below: number;
1106
+ readonly yes: SelectNode;
1107
+ readonly no: SelectNode;
1108
+ } | {
1109
+ readonly feature: SelectFlagFeature;
1110
+ readonly yes: SelectNode;
1111
+ readonly no: SelectNode;
1112
+ };
1113
+ /** The largest count of the tests on a path of a table of `select` */
1114
+ export declare const SELECT_MAX_DEPTH = 3;
1115
+ /**
1116
+ * The default table of `select`, for the default members `rows` (0) and `maxrects-bl` (1). Roadmap item k66 fitted it on
1117
+ * the records of `pack-screen-v1` (CI job 40675490363) and `pack-free-v1` (CI job 40685309195). A win is a fill ratio of 1.05 or
1118
+ * more with no more hard breaks. The leaf picks the member with the most wins.
1119
+ *
1120
+ * - Each threshold is in a plateau of the training accuracy. The table takes a value in the plateau that other code uses.
1121
+ * - The spread thresholds are `SPREAD_THRESHOLDS`: 0.02 and 0.27. The spread plateaus are 0 to 0.11 and 0.24 to 0.35.
1122
+ * - The count threshold 317 is the end of the band `100` of `countCell`. Any value from 101 to 1000 gives the same split.
1123
+ */
1124
+ export declare const SELECT_TABLE: SelectNode;
1125
+ /** The default members of `select`: `rows`, then `maxrects` with the rule `bl` */
1126
+ export declare const SELECT_MEMBERS: readonly PortfolioEntry[];
1127
+ /** The id of the trace stage of `select`. Its measure `move.select` is 1 when the pick is not member 0. */
1128
+ export declare const SELECT_STAGE = "select";
1129
+ /** This function gives the cheap features of an input. The spread is `spreadOf`. */
1130
+ export declare function selectFeatures(input: PackInput): SelectFeatures;
1131
+ /** This function gives the leaf of the features in a table. */
1132
+ export declare function selectLeaf(features: SelectFeatures, table?: SelectNode): {
1133
+ leaf: number;
1134
+ pick: number;
1135
+ };
1136
+ /**
1137
+ * This function checks a table against a count of members. A path has at most `SELECT_MAX_DEPTH` tests, thus the table has 8 leaves or fewer.
1138
+ * It throws a `RangeError` for a longer path, a pick that is not a member index and a threshold that is not a number.
1139
+ */
1140
+ export declare function checkSelectTable(table: SelectNode, members: number): void;
1141
+ /** The options of the strategy `select` */
1142
+ interface SelectStrategyOptions {
1143
+ /** The members. The default is `SELECT_MEMBERS`. A member is a strategy id, or a `PortfolioEntry` with options. */
1144
+ members?: readonly (string | PortfolioEntry)[];
1145
+ /** The decision table. The default is `SELECT_TABLE`. Each pick is an index of `members`. */
1146
+ table?: SelectNode;
1147
+ }
1148
+ /**
1149
+ * The strategy `select`: it gives the features of the input to the table, and it packs with the one member of the leaf.
1150
+ *
1151
+ * - The seed of the context goes to the member. The output of the member does not change.
1152
+ * - The output gets the trace stage `select` (`SELECT_STAGE`) after the stages of the member.
1153
+ * - The stage has `move.select`, `select.member` (the index of the pick), `select.pick.<member id>` (1), `select.leaf` and each feature.
1154
+ * - Its supports are the union of the supports of `rows` and `maxrects`. A member that does not support the cell throws its error.
1155
+ * - The strategy throws a `RangeError` for an unknown strategy of a member and for a table that `checkSelectTable` refuses.
1156
+ */
1157
+ export declare const selectStrategy: Strategy<SelectStrategyOptions>;
1078
1158
  /**
1079
1159
  * This function counts the breaks of the 4 hard rules of the packer for an output.
1080
1160
  *
@@ -1222,5 +1302,5 @@ interface Corpus {
1222
1302
  * `RangeError` for an unknown generator, a different version or 2 inputs with the same id.
1223
1303
  */
1224
1304
  export declare function corpus(name: string, specs: readonly CorpusSpec[]): Corpus;
1225
- export { type AspectFitOptions, type AspectFitStrategyOptions, type Cell, type ChangeMeasures, type ContainerTest, type Corpus, type CorpusCell, type CorpusEntry, type CorpusGenerator, type CorpusManifest, type CorpusSpec, type CountScale, DEFAULT_TOLERANCE, type Dimension, type DimensionValue, type Direction, EPS, type EdgeCase, type EdgeCaseParams, type FreeSpace, type FreeSpan, type FreeWidthOptions, type FreeWidthResult, type FreeWidthTry, type GeneratedInput, type GeneratorParams, type GeneratorStamp, type Item, type LayoutContainer, type LayoutEdge, type LayoutInput, type LayoutMeasures, type LayoutStrategyOptions, type Margin, type MaxRectsOptions, type MaxRectsRule, type MaxRectsStrategyOptions, type MeasureFamily, type MeasureId, type MeasureOptions, type MeasureSpec, type MemberTrace, type MetricsOptions, type Obstacle, type ObstacleLayout, type PackContext, type PackHard, type PackInput, type PackLayoutOptions, type PackOptions, type PackOutput, type PackPortfolioOptions, type PackingMetrics, type Placement, type Port, type Portfolio, type PortfolioCell, type PortfolioCellSets, type PortfolioEntry, type PortfolioPick, type PortfolioSetSource, type PortfolioSets, type PortfolioSize, type PortfolioStrategyOptions, type PortfolioTrace, type PortfolioTrainScore, type PushOptions, type PushStrategyOptions, RECORD_EPS, type RectGridParams, type RectGridV2Params, type RectScatteredParams, type Region, type SelectLevel, type ShelfFit, type ShelfOptions, type Side, type Sides, type SizeDistribution, type SizeSearch, type SkylineOptions, type SortOrder, type SpaceRect, type SpreadBand, type StageTrace, type Strategy, type Supports, type Tolerance, type UiParams, checkInput, turnPoint, turnPort, turnRegion };
1305
+ export { type AspectFitOptions, type AspectFitStrategyOptions, type Cell, type ChangeMeasures, type ContainerTest, type Corpus, type CorpusCell, type CorpusEntry, type CorpusGenerator, type CorpusManifest, type CorpusSpec, type CountScale, DEFAULT_TOLERANCE, type Dimension, type DimensionValue, type Direction, EPS, type EdgeCase, type EdgeCaseParams, type FreeSpace, type FreeSpan, type FreeWidthOptions, type FreeWidthResult, type FreeWidthTry, type GeneratedInput, type GeneratorParams, type GeneratorStamp, type Item, type LayoutContainer, type LayoutEdge, type LayoutInput, type LayoutMeasures, type LayoutStrategyOptions, type Margin, type MaxRectsOptions, type MaxRectsRule, type MaxRectsStrategyOptions, type MeasureFamily, type MeasureId, type MeasureOptions, type MeasureSpec, type MemberTrace, type MetricsOptions, type Obstacle, type ObstacleLayout, type PackContext, type PackHard, type PackInput, type PackLayoutOptions, type PackOptions, type PackOutput, type PackPortfolioOptions, type PackingMetrics, type Placement, type Port, type Portfolio, type PortfolioCell, type PortfolioCellSets, type PortfolioEntry, type PortfolioPick, type PortfolioSetSource, type PortfolioSets, type PortfolioSize, type PortfolioStrategyOptions, type PortfolioTrace, type PortfolioTrainScore, type PushOptions, type PushStrategyOptions, RECORD_EPS, type RectGridParams, type RectGridV2Params, type RectScatteredParams, type Region, type SelectFeatures, type SelectFlagFeature, type SelectLevel, type SelectNode, type SelectNumberFeature, type SelectStrategyOptions, type ShelfFit, type ShelfOptions, type Side, type Sides, type SizeDistribution, type SizeSearch, type SkylineOptions, type SortOrder, type SpaceRect, type SpreadBand, type StageTrace, type Strategy, type Supports, type Tolerance, type UiParams, checkInput, turnPoint, turnPort, turnRegion };
1226
1306
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["Item","Sides","ContractMeasureSpec","Direction","SelectLevel","SelectLevel","Portfolio","LayoutContainer","LayoutEdge","LayoutInput","ContainerTest","PackHard"],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/contract.ts","../src/space.ts","../src/maxrects.ts","../src/shelf.ts","../src/pack.ts","../src/skyline.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/aspect-fit.ts","../src/select-key.ts","../src/portfolio.ts","../src/layout-input.ts","../src/portfolio-cell.ts","../src/portfolio-sets.ts","../src/portfolio-strategy.ts","../src/check.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;;;EAK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KAAK;;EAE3B,SAAS,cAAc,SAAS,QAAQ,IAAI,eAAe;;;KAgJjD;EAAwB;;;qBAGvB,eAAe,gBAAgB;;KA8QhC;EACV,eAAe;EACf,gBAAgB;EAChB,WAAW;EACX,OAAO;EACP;;;;;;qBAOW,UAAU,gBAAgB;;cA2BjC;;KAGM,mBAAmB;EAC7B,eAAe;;;;;;qBAOJ,YAAY,gBAAgB;;KA0B7B;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;;;;;wBAMlB,UAAU,cAAc,mBAAmB;;UCxsB1C;;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":["Item","Sides","ContractMeasureSpec","Direction","SelectLevel","SelectLevel","Portfolio","LayoutContainer","LayoutEdge","LayoutInput","ContainerTest","PackHard"],"sources":["../src/vector.ts","../src/rect.ts","../src/order.ts","../src/contract.ts","../src/space.ts","../src/maxrects.ts","../src/shelf.ts","../src/pack.ts","../src/skyline.ts","../src/free.ts","../src/push.ts","../src/metrics.ts","../src/measures.ts","../src/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/aspect-fit.ts","../src/select-key.ts","../src/portfolio.ts","../src/layout-input.ts","../src/portfolio-cell.ts","../src/portfolio-sets.ts","../src/portfolio-strategy.ts","../src/select.ts","../src/check.ts","../src/generators.ts","../src/corpus.ts"],"mappings":";;qBACa;;EAIX,YAAY,YAAO;;MAMf;MACA,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ACA;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
@@ -878,23 +878,44 @@ function inside(a, b) {
878
878
  */
879
879
  function cut(free, b, minW, minH) {
880
880
  const kept = [];
881
- const parts = [];
882
- const sides = [];
881
+ const near = [
882
+ [],
883
+ [],
884
+ [],
885
+ []
886
+ ];
887
+ const stay = [
888
+ [],
889
+ [],
890
+ [],
891
+ []
892
+ ];
893
+ let made = 0;
883
894
  let hits = 0;
884
895
  const add = (side, x0, y0, x1, y1) => {
885
- if (x1 - x0 >= minW && y1 - y0 >= minH) {
886
- parts.push({
887
- x0,
888
- y0,
889
- x1,
890
- y1
891
- });
892
- sides.push(side);
896
+ if (x1 - x0 < minW || y1 - y0 < minH) return;
897
+ const own = stay[side];
898
+ for (let k = 0; k < own.length;) {
899
+ const qx0 = own[k];
900
+ const qy0 = own[k + 1];
901
+ const qx1 = own[k + 2];
902
+ const qy1 = own[k + 3];
903
+ if (x0 >= qx0 && y0 >= qy0 && x1 <= qx1 && y1 <= qy1) return;
904
+ if (qx0 >= x0 && qy0 >= y0 && qx1 <= x1 && qy1 <= y1) {
905
+ const last = own.length - 5;
906
+ if (k !== last) for (let n = 0; n < 5; n++) own[k + n] = own[last + n];
907
+ own.length = last;
908
+ } else k += 5;
893
909
  }
910
+ own.push(x0, y0, x1, y1, made++);
894
911
  };
895
912
  for (const f of free) {
896
913
  if (b.x0 >= f.x1 || b.x1 <= f.x0 || b.y0 >= f.y1 || b.y1 <= f.y0) {
897
914
  kept.push(f);
915
+ if (f.x1 === b.x0) near[0].push(f);
916
+ if (f.x0 === b.x1) near[1].push(f);
917
+ if (f.y1 === b.y0) near[2].push(f);
918
+ if (f.y0 === b.y1) near[3].push(f);
898
919
  continue;
899
920
  }
900
921
  hits++;
@@ -903,67 +924,34 @@ function cut(free, b, minW, minH) {
903
924
  if (b.y0 > f.y0) add(2, f.x0, f.y0, f.x1, b.y0);
904
925
  if (b.y1 < f.y1) add(3, f.x0, b.y1, f.x1, f.y1);
905
926
  }
906
- if (parts.length === 0) return {
927
+ if (made === 0) return {
907
928
  free: kept,
908
929
  hits
909
930
  };
910
- const near = [
911
- [],
912
- [],
913
- [],
914
- []
915
- ];
916
- for (const k of kept) {
917
- if (k.x1 === b.x0) near[0].push(k);
918
- if (k.x0 === b.x1) near[1].push(k);
919
- if (k.y1 === b.y0) near[2].push(k);
920
- if (k.y0 === b.y1) near[3].push(k);
921
- }
922
- const order = parts.map((_, i) => i).sort((i, j) => byExtent(parts[i], parts[j]) || i - j);
923
- const gone = new Uint8Array(parts.length);
924
- const stay = [
925
- [],
926
- [],
927
- [],
928
- []
929
- ];
930
- for (const i of order) {
931
- const p = parts[i];
932
- const own = stay[sides[i]];
933
- let drop = false;
934
- for (const q of own) if (inside(p, q)) {
935
- drop = true;
936
- break;
937
- }
938
- if (drop) gone[i] = 1;
939
- else own.push(p);
940
- }
941
- for (let i = 0; i < parts.length; i++) {
942
- if (gone[i] === 1) continue;
943
- const p = parts[i];
944
- let drop = false;
945
- for (const k of near[sides[i]]) if (inside(p, k)) {
946
- drop = true;
947
- break;
931
+ const out = new Array(made).fill(void 0);
932
+ for (let side = 0; side < 4; side++) {
933
+ const own = stay[side];
934
+ for (let k = 0; k < own.length; k += 5) {
935
+ const p = {
936
+ x0: own[k],
937
+ y0: own[k + 1],
938
+ x1: own[k + 2],
939
+ y1: own[k + 3]
940
+ };
941
+ let drop = false;
942
+ for (const q of near[side]) if (inside(p, q)) {
943
+ drop = true;
944
+ break;
945
+ }
946
+ if (!drop) out[own[k + 4]] = p;
948
947
  }
949
- if (!drop) kept.push(p);
950
948
  }
949
+ for (const p of out) if (p !== void 0) kept.push(p);
951
950
  return {
952
951
  free: kept,
953
952
  hits
954
953
  };
955
954
  }
956
- /**
957
- * This function orders two boxes. The smaller `x0` comes first, then the smaller `y0`, then the larger `x1`, then the
958
- * larger `y1`. Thus a box comes before each other box in it.
959
- */
960
- function byExtent(a, b) {
961
- if (a.x0 !== b.x0) return a.x0 < b.x0 ? -1 : 1;
962
- if (a.y0 !== b.y0) return a.y0 < b.y0 ? -1 : 1;
963
- if (a.x1 !== b.x1) return a.x1 > b.x1 ? -1 : 1;
964
- if (a.y1 !== b.y1) return a.y1 > b.y1 ? -1 : 1;
965
- return 0;
966
- }
967
955
  /** This function adds a range to the edges at a coordinate. */
968
956
  function addEdge(edges, at, a, b) {
969
957
  const list = edges.get(at);
@@ -6294,7 +6282,7 @@ const SINGLES = [
6294
6282
  maxrects
6295
6283
  ];
6296
6284
  /** This function gives the union of the supports of the strategies of the members of the table. */
6297
- function unionSupports() {
6285
+ function unionSupports$1() {
6298
6286
  const used = new Set(Object.values(PORTFOLIO_SETS.entries).map((e) => e.strategy));
6299
6287
  const out = {};
6300
6288
  for (const s of SINGLES.filter((x) => used.has(x.id))) for (const [dim, values] of Object.entries(s.supports)) {
@@ -6318,7 +6306,7 @@ const portfolioStrategy = {
6318
6306
  id: "portfolio",
6319
6307
  family: "portfolio",
6320
6308
  catalog: [],
6321
- supports: unionSupports(),
6309
+ supports: unionSupports$1(),
6322
6310
  defaults: {},
6323
6311
  deterministic: true,
6324
6312
  pack(input, options, context) {
@@ -6339,6 +6327,172 @@ const portfolioStrategy = {
6339
6327
  }).run(input);
6340
6328
  }
6341
6329
  };
6330
+ // src/select.ts
6331
+ /** The largest count of the tests on a path of a table of `select` */
6332
+ const SELECT_MAX_DEPTH = 3;
6333
+ /**
6334
+ * The default table of `select`, for the default members `rows` (0) and `maxrects-bl` (1). Roadmap item k66 fitted it on
6335
+ * the records of `pack-screen-v1` (CI job 40675490363) and `pack-free-v1` (CI job 40685309195). A win is a fill ratio of 1.05 or
6336
+ * more with no more hard breaks. The leaf picks the member with the most wins.
6337
+ *
6338
+ * - Each threshold is in a plateau of the training accuracy. The table takes a value in the plateau that other code uses.
6339
+ * - The spread thresholds are `SPREAD_THRESHOLDS`: 0.02 and 0.27. The spread plateaus are 0 to 0.11 and 0.24 to 0.35.
6340
+ * - The count threshold 317 is the end of the band `100` of `countCell`. Any value from 101 to 1000 gives the same split.
6341
+ */
6342
+ const SELECT_TABLE = Object.freeze({
6343
+ feature: "fixed",
6344
+ yes: {
6345
+ feature: "count",
6346
+ below: 317,
6347
+ yes: {
6348
+ feature: "spread",
6349
+ below: .02,
6350
+ yes: {
6351
+ leaf: 0,
6352
+ pick: 0
6353
+ },
6354
+ no: {
6355
+ leaf: 1,
6356
+ pick: 1
6357
+ }
6358
+ },
6359
+ no: {
6360
+ feature: "spread",
6361
+ below: .27,
6362
+ yes: {
6363
+ leaf: 2,
6364
+ pick: 0
6365
+ },
6366
+ no: {
6367
+ leaf: 3,
6368
+ pick: 1
6369
+ }
6370
+ }
6371
+ },
6372
+ no: {
6373
+ feature: "spread",
6374
+ below: .27,
6375
+ yes: {
6376
+ leaf: 4,
6377
+ pick: 0
6378
+ },
6379
+ no: {
6380
+ feature: "rect",
6381
+ yes: {
6382
+ leaf: 5,
6383
+ pick: 0
6384
+ },
6385
+ no: {
6386
+ leaf: 6,
6387
+ pick: 1
6388
+ }
6389
+ }
6390
+ }
6391
+ });
6392
+ /** The default members of `select`: `rows`, then `maxrects` with the rule `bl` */
6393
+ const SELECT_MEMBERS = Object.freeze([{
6394
+ id: "rows",
6395
+ strategy: "rows"
6396
+ }, {
6397
+ id: "maxrects-bl",
6398
+ strategy: "maxrects",
6399
+ options: { rule: "bl" }
6400
+ }]);
6401
+ /** The id of the trace stage of `select`. Its measure `move.select` is 1 when the pick is not member 0. */
6402
+ const SELECT_STAGE = "select";
6403
+ /** This function gives the cheap features of an input. The spread is `spreadOf`. */
6404
+ function selectFeatures(input) {
6405
+ const c = input.container;
6406
+ const rect = (c.shape === void 0 || c.shape.kind === "rect") && !(input.obstacles ?? []).some((o) => o.region.kind !== "rect");
6407
+ return {
6408
+ count: input.items.length,
6409
+ fixed: c.fixed === "size",
6410
+ rect,
6411
+ spread: spreadOf(input)
6412
+ };
6413
+ }
6414
+ /** This function gives the leaf of the features in a table. */
6415
+ function selectLeaf(features, table = SELECT_TABLE) {
6416
+ let node = table;
6417
+ while (!("leaf" in node)) node = ("below" in node ? features[node.feature] < node.below : features[node.feature]) ? node.yes : node.no;
6418
+ return {
6419
+ leaf: node.leaf,
6420
+ pick: node.pick
6421
+ };
6422
+ }
6423
+ /**
6424
+ * This function checks a table against a count of members. A path has at most `SELECT_MAX_DEPTH` tests, thus the table has 8 leaves or fewer.
6425
+ * It throws a `RangeError` for a longer path, a pick that is not a member index and a threshold that is not a number.
6426
+ */
6427
+ function checkSelectTable(table, members) {
6428
+ const walk = (node, depth) => {
6429
+ if ("leaf" in node) {
6430
+ if (!Number.isInteger(node.pick) || node.pick < 0 || node.pick >= members) throw new RangeError(`The leaf ${node.leaf} of the table of select picks ${node.pick}, but the members are 0 to ${members - 1}.`);
6431
+ return;
6432
+ }
6433
+ if (depth >= 3) throw new RangeError(`The table of select has a path with more than 3 tests.`);
6434
+ if ((node.feature === "count" || node.feature === "spread") && !Number.isFinite(node.below)) throw new RangeError(`The test of ${node.feature} of the table of select needs a number below.`);
6435
+ walk(node.yes, depth + 1);
6436
+ walk(node.no, depth + 1);
6437
+ };
6438
+ walk(table, 0);
6439
+ }
6440
+ /** This function gives the union of the supports of the default members. */
6441
+ function unionSupports() {
6442
+ const out = {};
6443
+ for (const s of [rows, maxrects]) for (const [dim, values] of Object.entries(s.supports)) {
6444
+ const list = out[dim] ??= [];
6445
+ for (const v of values) if (!list.includes(v)) list.push(v);
6446
+ }
6447
+ return out;
6448
+ }
6449
+ /**
6450
+ * The strategy `select`: it gives the features of the input to the table, and it packs with the one member of the leaf.
6451
+ *
6452
+ * - The seed of the context goes to the member. The output of the member does not change.
6453
+ * - The output gets the trace stage `select` (`SELECT_STAGE`) after the stages of the member.
6454
+ * - The stage has `move.select`, `select.member` (the index of the pick), `select.pick.<member id>` (1), `select.leaf` and each feature.
6455
+ * - Its supports are the union of the supports of `rows` and `maxrects`. A member that does not support the cell throws its error.
6456
+ * - The strategy throws a `RangeError` for an unknown strategy of a member and for a table that `checkSelectTable` refuses.
6457
+ */
6458
+ const selectStrategy = {
6459
+ id: "select",
6460
+ family: "select",
6461
+ catalog: [],
6462
+ supports: unionSupports(),
6463
+ defaults: {},
6464
+ deterministic: true,
6465
+ pack(input, options, context) {
6466
+ const members = (options.members ?? SELECT_MEMBERS).map((m) => typeof m === "string" ? {
6467
+ id: m,
6468
+ strategy: m
6469
+ } : m);
6470
+ const table = options.table ?? SELECT_TABLE;
6471
+ for (const m of members) strategy(m.strategy);
6472
+ if (options.table !== void 0 || options.members !== void 0) checkSelectTable(table, members.length);
6473
+ const features = selectFeatures(input);
6474
+ const { leaf, pick } = selectLeaf(features, table);
6475
+ const member = members[pick];
6476
+ const out = packWith(member.strategy, input, member.options, context.seed);
6477
+ const measures = {
6478
+ "move.select": pick === 0 ? 0 : 1,
6479
+ "select.member": pick,
6480
+ [`select.pick.${member.id}`]: 1,
6481
+ "select.leaf": leaf,
6482
+ "select.count": features.count,
6483
+ "select.fixed": features.fixed ? 1 : 0,
6484
+ "select.rect": features.rect ? 1 : 0,
6485
+ "select.spread": round3(features.spread)
6486
+ };
6487
+ return {
6488
+ ...out,
6489
+ trace: [...out.trace ?? [], {
6490
+ id: SELECT_STAGE,
6491
+ measures
6492
+ }]
6493
+ };
6494
+ }
6495
+ };
6342
6496
  // src/registry.ts
6343
6497
  /** Each single strategy of the package. The benchmark starts each one on each input of the corpus. */
6344
6498
  const strategies = Object.freeze([
@@ -6381,9 +6535,13 @@ const aspectFitStrategy = {
6381
6535
  };
6382
6536
  /**
6383
6537
  * The composite strategies of the registry: each one packs an input with other strategies. They are not in `strategies`.
6384
- * Since 0.2.7, the list has `portfolio` of roadmap item k20. Roadmap item k62 adds `aspect-fit`.
6538
+ * Since 0.2.7, the list has `portfolio` of roadmap item k20. Roadmap item k62 adds `aspect-fit`, and roadmap item k66 adds `select`.
6385
6539
  */
6386
- const composites = Object.freeze([portfolioStrategy, aspectFitStrategy]);
6540
+ const composites = Object.freeze([
6541
+ portfolioStrategy,
6542
+ aspectFitStrategy,
6543
+ selectStrategy
6544
+ ]);
6387
6545
  /** This function gives the strategy with an id, also a composite strategy. It throws a `RangeError` for an id that the registry does not have. */
6388
6546
  function strategy(id) {
6389
6547
  const found = strategies.find((s) => s.id === id) ?? composites.find((s) => s.id === id);
@@ -7370,6 +7528,6 @@ function corpus(name, specs) {
7370
7528
  inputs
7371
7529
  };
7372
7530
  }
7373
- export { ASPECT_FIT_FACTORS, ASPECT_FIT_LEVELS, ASPECT_FIT_STAGE, DEFAULT_TOLERANCE, EPS, MAXRECTS_BANDS, MAXRECTS_RULES, MEASURE_SPECS, PORTFOLIO_FRAME_MS, PORTFOLIO_LEVELS, PORTFOLIO_SETS, PORTFOLIO_STAGE, RECORD_EPS, Rect, SHELF_FITS, SORT_ORDERS, SPREAD_THRESHOLDS, THIN_INPUTS, UnsupportedCell, Vector, aspectError, aspectFit, aspectFitStrategy, assertSupported, canonicalJson, cards, cellKey, cellOf, checkHard, checkInput, compareRects, composites, corpus, countCell, createContext, dashboard, edgeCases, fnv1a32, freeSpace, fromRects, gallery, generator, generators, hardBreaks, hashInput, isDeterministic, logSweep, lowestWindow, marginOf, maxrects, measure, measureChange, medianRatio, mulberry32, outputHash, pack, packFree, packMaxRects, packPortfolio, packRows, packShelf, packSkyline, packWith, packingMetrics, pairedRatio, portfolioCell, portfolioDefaultMembers, portfolioMembers, portfolioSetOf, portfolioStrategy, push, pushCascade, quantile, rectGrid, rectGridV2, rectScattered, round3, roundMeasures, rows, shelf, skyline, spreadBand, spreadOf, strategies, strategy, supportsCell, tailShare, toPackInput, toRects, turnItem, turnPoint, turnPort, turnRegion, unsupportedOf, wordCloud };
7531
+ export { ASPECT_FIT_FACTORS, ASPECT_FIT_LEVELS, ASPECT_FIT_STAGE, DEFAULT_TOLERANCE, EPS, MAXRECTS_BANDS, MAXRECTS_RULES, MEASURE_SPECS, PORTFOLIO_FRAME_MS, PORTFOLIO_LEVELS, PORTFOLIO_SETS, PORTFOLIO_STAGE, RECORD_EPS, Rect, SELECT_MAX_DEPTH, SELECT_MEMBERS, SELECT_STAGE, SELECT_TABLE, SHELF_FITS, SORT_ORDERS, SPREAD_THRESHOLDS, THIN_INPUTS, UnsupportedCell, Vector, aspectError, aspectFit, aspectFitStrategy, assertSupported, canonicalJson, cards, cellKey, cellOf, checkHard, checkInput, checkSelectTable, compareRects, composites, corpus, countCell, createContext, dashboard, edgeCases, fnv1a32, freeSpace, fromRects, gallery, generator, generators, hardBreaks, hashInput, isDeterministic, logSweep, lowestWindow, marginOf, maxrects, measure, measureChange, medianRatio, mulberry32, outputHash, pack, packFree, packMaxRects, packPortfolio, packRows, packShelf, packSkyline, packWith, packingMetrics, pairedRatio, portfolioCell, portfolioDefaultMembers, portfolioMembers, portfolioSetOf, portfolioStrategy, push, pushCascade, quantile, rectGrid, rectGridV2, rectScattered, round3, roundMeasures, rows, selectFeatures, selectLeaf, selectStrategy, shelf, skyline, spreadBand, spreadOf, strategies, strategy, supportsCell, tailShare, toPackInput, toRects, turnItem, turnPoint, turnPort, turnRegion, unsupportedOf, wordCloud };
7374
7532
 
7375
7533
  //# sourceMappingURL=index.js.map