@mark1russell7/packing 0.2.13 → 0.2.15

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 CHANGED
@@ -162,6 +162,7 @@ checkHard(input, output); // { "no-overlap": 0, "in-container": 0, "locked-kept"
162
162
  ```
163
163
 
164
164
  - The registry `strategies` has `rows`, `skyline`, `shelf`, `push` and `maxrects`. `strategy(id)` gives one, and `packWith(id, input, options, seed)` packs with it.
165
+ - `packDefault(input, seed)` packs with `DEFAULT_STRATEGY`, the composite strategy `select`. It passed the win test against `rows` on two fresh-seed corpora.
165
166
  - `fixed` is `size`, `width`, `height` or `none`. A fixed height turns the axes. The value `none` uses the size search `logSweep`, which wraps `packFree`.
166
167
  - Each strategy declares its cells in `supports`. `cellOf(input)` gives the cell of an input. A strategy throws `UnsupportedCell` for an input outside its cells.
167
168
  - Only `maxrects` accepts a turnable item, and it turns items only with `rotate: true`. The other strategies give `UnsupportedCell` for a turnable item.
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. */
@@ -779,6 +779,13 @@ export declare function strategy(id: string): Strategy;
779
779
  * context gets `mulberry32` with the seed. The default seed is 0.
780
780
  */
781
781
  export declare function packWith(id: string, input: PackInput, options?: unknown, seed?: number): PackOutput;
782
+ /**
783
+ * The id of the default strategy of an input: `select`. It passed two fresh-seed confirmations against `rows` (roadmap
784
+ * item k66). `pack` does not read it.
785
+ */
786
+ export declare const DEFAULT_STRATEGY = "select";
787
+ /** This function packs an input with `DEFAULT_STRATEGY` and its defaults. The default seed is 0. */
788
+ export declare function packDefault(input: PackInput, seed?: number): PackOutput;
782
789
  /** The options of `aspectFit` */
783
790
  interface AspectFitOptions {
784
791
  /** The target aspect: the width divided by the height. The default is `aspect` of the container, else 1. */
@@ -1075,6 +1082,86 @@ interface PortfolioStrategyOptions {
1075
1082
  * - The strategy throws a `RangeError` for a `k` other than 2 or 3, and for `k` with `members`.
1076
1083
  */
1077
1084
  export declare const portfolioStrategy: Strategy<PortfolioStrategyOptions>;
1085
+ /** The cheap features of an input for `select`. One pass over the items and the obstacles gives them. */
1086
+ interface SelectFeatures {
1087
+ /** The count of the items */
1088
+ count: number;
1089
+ /** The value `true` when the container has the size `fixed`. A free width, a free height or a free size gives `false`. */
1090
+ fixed: boolean;
1091
+ /** The value `true` when the container is a rectangle with no obstacle of another shape: the `containerShape` `rect` of `cellOf` */
1092
+ rect: boolean;
1093
+ /** The size spread: `spreadOf`, the standard deviation of the natural log of `sqrt(w * h)` of each item */
1094
+ spread: number;
1095
+ }
1096
+ /** A feature of `SelectFeatures` with a number value. A node of this feature compares the value with `below`. */
1097
+ type SelectNumberFeature = "count" | "spread";
1098
+ /** A feature of `SelectFeatures` with a flag value. */
1099
+ type SelectFlagFeature = "fixed" | "rect";
1100
+ /**
1101
+ * A node of the decision table of `select`.
1102
+ *
1103
+ * - A leaf has `leaf`, its number for the trace, and `pick`, the index of its member in the option `members`.
1104
+ * - A number node goes to `yes` when the feature value is below `below`, else to `no`.
1105
+ * - A flag node goes to `yes` when the feature value is `true`, else to `no`.
1106
+ */
1107
+ type SelectNode = {
1108
+ readonly leaf: number;
1109
+ readonly pick: number;
1110
+ } | {
1111
+ readonly feature: SelectNumberFeature;
1112
+ readonly below: number;
1113
+ readonly yes: SelectNode;
1114
+ readonly no: SelectNode;
1115
+ } | {
1116
+ readonly feature: SelectFlagFeature;
1117
+ readonly yes: SelectNode;
1118
+ readonly no: SelectNode;
1119
+ };
1120
+ /** The largest count of the tests on a path of a table of `select` */
1121
+ export declare const SELECT_MAX_DEPTH = 3;
1122
+ /**
1123
+ * The default table of `select`, for the default members `rows` (0) and `maxrects-bl` (1). Roadmap item k66 fitted it on
1124
+ * 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
1125
+ * more with no more hard breaks. The leaf picks the member with the most wins.
1126
+ *
1127
+ * - Each threshold is in a plateau of the training accuracy. The table takes a value in the plateau that other code uses.
1128
+ * - 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.
1129
+ * - The count threshold 317 is the end of the band `100` of `countCell`. Any value from 101 to 1000 gives the same split.
1130
+ */
1131
+ export declare const SELECT_TABLE: SelectNode;
1132
+ /** The default members of `select`: `rows`, then `maxrects` with the rule `bl` */
1133
+ export declare const SELECT_MEMBERS: readonly PortfolioEntry[];
1134
+ /** The id of the trace stage of `select`. Its measure `move.select` is 1 when the pick is not member 0. */
1135
+ export declare const SELECT_STAGE = "select";
1136
+ /** This function gives the cheap features of an input. The spread is `spreadOf`. */
1137
+ export declare function selectFeatures(input: PackInput): SelectFeatures;
1138
+ /** This function gives the leaf of the features in a table. */
1139
+ export declare function selectLeaf(features: SelectFeatures, table?: SelectNode): {
1140
+ leaf: number;
1141
+ pick: number;
1142
+ };
1143
+ /**
1144
+ * 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.
1145
+ * It throws a `RangeError` for a longer path, a pick that is not a member index and a threshold that is not a number.
1146
+ */
1147
+ export declare function checkSelectTable(table: SelectNode, members: number): void;
1148
+ /** The options of the strategy `select` */
1149
+ interface SelectStrategyOptions {
1150
+ /** The members. The default is `SELECT_MEMBERS`. A member is a strategy id, or a `PortfolioEntry` with options. */
1151
+ members?: readonly (string | PortfolioEntry)[];
1152
+ /** The decision table. The default is `SELECT_TABLE`. Each pick is an index of `members`. */
1153
+ table?: SelectNode;
1154
+ }
1155
+ /**
1156
+ * The strategy `select`: it gives the features of the input to the table, and it packs with the one member of the leaf.
1157
+ *
1158
+ * - The seed of the context goes to the member. The output of the member does not change.
1159
+ * - The output gets the trace stage `select` (`SELECT_STAGE`) after the stages of the member.
1160
+ * - The stage has `move.select`, `select.member` (the index of the pick), `select.pick.<member id>` (1), `select.leaf` and each feature.
1161
+ * - Its supports are the union of the supports of `rows` and `maxrects`. A member that does not support the cell throws its error.
1162
+ * - The strategy throws a `RangeError` for an unknown strategy of a member and for a table that `checkSelectTable` refuses.
1163
+ */
1164
+ export declare const selectStrategy: Strategy<SelectStrategyOptions>;
1078
1165
  /**
1079
1166
  * This function counts the breaks of the 4 hard rules of the packer for an output.
1080
1167
  *
@@ -1222,5 +1309,5 @@ interface Corpus {
1222
1309
  * `RangeError` for an unknown generator, a different version or 2 inputs with the same id.
1223
1310
  */
1224
1311
  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 };
1312
+ 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
1313
  //# 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;;;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;;SAKpC,YAAY,GAAG,OAAO,KAAK;;SAK3B,SAAS,GAAG,OAAO,KAAK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BA0BW,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,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;;E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  ];
6284
6284
  /** This function gives the union of the supports of the strategies of the members of the table. */
6285
- function unionSupports() {
6285
+ function unionSupports$1() {
6286
6286
  const used = new Set(Object.values(PORTFOLIO_SETS.entries).map((e) => e.strategy));
6287
6287
  const out = {};
6288
6288
  for (const s of SINGLES.filter((x) => used.has(x.id))) for (const [dim, values] of Object.entries(s.supports)) {
@@ -6306,7 +6306,7 @@ const portfolioStrategy = {
6306
6306
  id: "portfolio",
6307
6307
  family: "portfolio",
6308
6308
  catalog: [],
6309
- supports: unionSupports(),
6309
+ supports: unionSupports$1(),
6310
6310
  defaults: {},
6311
6311
  deterministic: true,
6312
6312
  pack(input, options, context) {
@@ -6327,6 +6327,172 @@ const portfolioStrategy = {
6327
6327
  }).run(input);
6328
6328
  }
6329
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
+ };
6330
6496
  // src/registry.ts
6331
6497
  /** Each single strategy of the package. The benchmark starts each one on each input of the corpus. */
6332
6498
  const strategies = Object.freeze([
@@ -6369,9 +6535,13 @@ const aspectFitStrategy = {
6369
6535
  };
6370
6536
  /**
6371
6537
  * The composite strategies of the registry: each one packs an input with other strategies. They are not in `strategies`.
6372
- * 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`.
6373
6539
  */
6374
- const composites = Object.freeze([portfolioStrategy, aspectFitStrategy]);
6540
+ const composites = Object.freeze([
6541
+ portfolioStrategy,
6542
+ aspectFitStrategy,
6543
+ selectStrategy
6544
+ ]);
6375
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. */
6376
6546
  function strategy(id) {
6377
6547
  const found = strategies.find((s) => s.id === id) ?? composites.find((s) => s.id === id);
@@ -6390,6 +6560,15 @@ function packWith(id, input, options, seed = 0) {
6390
6560
  };
6391
6561
  return s.pack(input, merged, createContext(seed));
6392
6562
  }
6563
+ /**
6564
+ * The id of the default strategy of an input: `select`. It passed two fresh-seed confirmations against `rows` (roadmap
6565
+ * item k66). `pack` does not read it.
6566
+ */
6567
+ const DEFAULT_STRATEGY = "select";
6568
+ /** This function packs an input with `DEFAULT_STRATEGY` and its defaults. The default seed is 0. */
6569
+ function packDefault(input, seed = 0) {
6570
+ return packWith(DEFAULT_STRATEGY, input, void 0, seed);
6571
+ }
6393
6572
  // src/generators.ts
6394
6573
  /** The largest count of boxes that a generator makes. */
6395
6574
  const MAX_COUNT = 1e5;
@@ -7358,6 +7537,6 @@ function corpus(name, specs) {
7358
7537
  inputs
7359
7538
  };
7360
7539
  }
7361
- 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 };
7540
+ export { ASPECT_FIT_FACTORS, ASPECT_FIT_LEVELS, ASPECT_FIT_STAGE, DEFAULT_STRATEGY, 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, packDefault, 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 };
7362
7541
 
7363
7542
  //# sourceMappingURL=index.js.map