@mark1russell7/packing 0.2.5 → 0.2.6

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
@@ -60,6 +60,16 @@ pack(rects, outer, { strategy: "maxrects", rule: "cp" });
60
60
  - The move of each rule other than `bl` counts a box when the rule chooses a place that `bl` does not choose.
61
61
  - A shape that is not a rectangle gets bands. The option `bandHeight` sets their largest height. The default is the height divided by `MAXRECTS_BANDS`.
62
62
 
63
+ Since 0.2.6, `packPortfolio` packs an input with each member and keeps the best output. It is opt-in, and no default uses it.
64
+
65
+ ```ts
66
+ const { output, winner } = packPortfolio(["skyline", "shelf"]).pick(input);
67
+ ```
68
+
69
+ - The pick is `selectBest` of `@mark1russell7/layout-contract` on `PORTFOLIO_LEVELS`: the hard breaks, then `pack.overflow.excessArea`, then `pack.fill`.
70
+ - The trace of the output gets the stage `portfolio` with the measure `move.pick`.
71
+ - `outputHash` gives the hash of the placements of an output, as the bench records have it.
72
+
63
73
  Both functions also work alone, in an outer rectangle with a width that you set. They do not change the width.
64
74
 
65
75
  A `locked` rectangle keeps its position. `packSkyline` and `packShelf` put the other rectangles around it. `packRows` only keeps its position.
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ContainerTest, ContainerTest as ContainerTest$1, DEFAULT_TOLERANCE, Direction, Direction as Direction$1, EPS, Item, Item as Item$1, LayoutContainer, LayoutContainer as LayoutContainer$1, LayoutEdge, LayoutEdge as LayoutEdge$1, LayoutGenerator, LayoutInput, LayoutInput as LayoutInput$1, Margin, MeasureSpec as MeasureSpec$1, Obstacle, PackHard, PackHard as PackHard$1, PackInput, PackOutput, Placement, Port, RECORD_EPS, Region, Side, Sides, Sides as Sides$1, StageTrace, Tolerance, checkInput, turnPoint, turnPort, turnRegion } from "@mark1russell7/layout-contract";
1
+ import { ContainerTest, ContainerTest as ContainerTest$1, DEFAULT_TOLERANCE, Direction, Direction as Direction$1, EPS, Item, Item as Item$1, LayoutContainer, LayoutContainer as LayoutContainer$1, LayoutEdge, LayoutEdge as LayoutEdge$1, LayoutGenerator, LayoutInput, LayoutInput as LayoutInput$1, Margin, MeasureSpec as MeasureSpec$1, MemberTrace, Obstacle, PackHard, PackHard as PackHard$1, PackInput, PackOutput, Placement, Port, Portfolio, Portfolio as Portfolio$1, PortfolioPick, PortfolioTrace, RECORD_EPS, Region, SelectLevel, SelectLevel as SelectLevel$1, Side, Sides, Sides as Sides$1, StageTrace, Tolerance, checkInput, turnPoint, turnPort, turnRegion } from "@mark1russell7/layout-contract";
2
2
  /** A mutable two-dimensional vector. */
3
3
  export declare class Vector {
4
4
  #private;
@@ -759,6 +759,50 @@ export declare function strategy(id: string): Strategy;
759
759
  * context gets `mulberry32` with the seed. The default seed is 0.
760
760
  */
761
761
  export declare function packWith(id: string, input: PackInput, options?: unknown, seed?: number): PackOutput;
762
+ /** A member of `packPortfolio`: a strategy of the registry with some options. The id names the member in the trace. */
763
+ interface PortfolioEntry {
764
+ id: string;
765
+ /** The id of a strategy of the registry */
766
+ strategy: string;
767
+ /** The options of the member over the defaults of the strategy */
768
+ options?: unknown;
769
+ }
770
+ /** The options of `packPortfolio`. The time limit and the member limit are those of `portfolio` of the contract. */
771
+ interface PackPortfolioOptions {
772
+ /** The id of the portfolio. The default is `portfolio`. */
773
+ id?: string;
774
+ /** The seed of each member. The default is 0, as for `packWith`. */
775
+ seed?: number;
776
+ /** The time limit in milliseconds. Without it, each member runs. A cut member makes the pick not deterministic. */
777
+ budgetMs?: number;
778
+ /** The largest count of members that run */
779
+ maxMembers?: number;
780
+ /** The clock in milliseconds. The default is `performance.now`. */
781
+ now?: () => number;
782
+ }
783
+ /** The id of the trace stage of `packPortfolio`. Its measure `move.pick` is 1 when the pick is not member 0. */
784
+ export declare const PORTFOLIO_STAGE = "portfolio";
785
+ /**
786
+ * The levels of the pick of `packPortfolio` and of the portfolio report of the benchmark, in order. Level 0 is `hard`.
787
+ *
788
+ * - `hard`: the count of hard breaks of `checkHard` with `exactContainer`. Lower is better, with the minimum effect 0.
789
+ * - `pack.overflow.excessArea`: the overflow area above its bound. Lower is better.
790
+ * - `pack.fill`: the fill of the hull. Higher is better.
791
+ */
792
+ export declare const PORTFOLIO_LEVELS: readonly SelectLevel$1[];
793
+ /** This function gives the count of the hard breaks of an output: the sum of `checkHard` with `exactContainer`. */
794
+ export declare function hardBreaks(input: PackInput, output: PackOutput): number;
795
+ /**
796
+ * This function makes an opt-in portfolio of strategies of the registry with `portfolio` of the contract.
797
+ * Its `pick(input)` packs the input with each member and gives the output of the winner, its id and the trace.
798
+ *
799
+ * - A member is a strategy id, or a `PortfolioEntry` with options. The members run in the given order.
800
+ * - The key is the hard breaks, then `pack.overflow.excessArea`, then `pack.fill`. `PORTFOLIO_LEVELS` gives the specs.
801
+ * - The hash of the key is `outputHash`. `selectBest` of the contract picks the winner.
802
+ * - The output of the winner gets the trace stage `portfolio` with `move.pick` of `pickMoves`.
803
+ * - The function throws a `RangeError` for an unknown strategy, an empty list and two members with the same id.
804
+ */
805
+ export declare function packPortfolio(members: readonly (string | PortfolioEntry)[], options?: PackPortfolioOptions): Portfolio$1<PackInput, PackOutput>;
762
806
  /**
763
807
  * This function counts the breaks of the 4 hard rules of the packer for an output.
764
808
  *
@@ -833,6 +877,12 @@ export declare function round3(x: number): number;
833
877
  export declare function canonicalJson(value: unknown): string;
834
878
  /** This function gives the hash of an input file: the first 16 hex characters of the SHA-256 of its canonical form without `hash`. */
835
879
  export declare function hashInput(file: LayoutInput$1): string;
880
+ /**
881
+ * This function gives the `outputHash` of an output. It is the first 16 hex characters of the SHA-256 of the canonical form of
882
+ * its placements, sorted by id. The canonical form rounds each number with `round3`. Thus the order of the list does not count.
883
+ * The records of the benchmark and the key of `packPortfolio` use it. It is not `outputHash` of the contract, which uses a grid.
884
+ */
885
+ export declare function outputHash(output: Pick<PackOutput, "placements">): string;
836
886
  /** This function gives the scale of a count: the nearest of 1, 10, 100, 1000 and 10000 on a log scale. The count 0 gives `1`. */
837
887
  export declare function countCell(count: number): CountScale;
838
888
  /**
@@ -952,5 +1002,5 @@ interface Corpus {
952
1002
  * `RangeError` for an unknown generator, a different version or 2 inputs with the same id.
953
1003
  */
954
1004
  export declare function corpus(name: string, specs: readonly CorpusSpec[]): Corpus;
955
- export { 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 MetricsOptions, type Obstacle, type ObstacleLayout, type PackContext, type PackHard, type PackInput, type PackLayoutOptions, type PackOptions, type PackOutput, type PackingMetrics, type Placement, type Port, type PushOptions, type PushStrategyOptions, RECORD_EPS, type RectGridParams, type RectScatteredParams, type Region, type ShelfFit, type ShelfOptions, type Side, type Sides, type SizeDistribution, type SizeSearch, type SkylineOptions, type SortOrder, type SpaceRect, type StageTrace, type Strategy, type Supports, type Tolerance, type UiParams, checkInput, turnPoint, turnPort, turnRegion };
1005
+ export { 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 PortfolioEntry, type PortfolioPick, type PortfolioTrace, type PushOptions, type PushStrategyOptions, RECORD_EPS, type RectGridParams, 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 StageTrace, type Strategy, type Supports, type Tolerance, type UiParams, checkInput, turnPoint, turnPort, turnRegion };
956
1006
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["Item","Sides","ContractMeasureSpec","Direction","ContainerTest","PackHard","LayoutContainer","LayoutEdge","LayoutInput"],"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/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;;MAE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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;;UChqBxB;;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","Portfolio","ContainerTest","PackHard","LayoutContainer","LayoutEdge","LayoutInput"],"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/portfolio.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;;E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AAK,SAAS,QAAQ,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;;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;;UChqBxB;;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
@@ -1,4 +1,4 @@
1
- import { DEFAULT_TOLERANCE, EPS, RECORD_EPS, boundsOf, boundsOf as boundsOf$1, checkInput, marginSides, rectInRegion, regionHitsRect, translate, turnBox, turnPoint, turnPort, turnRegion } from "@mark1russell7/layout-contract";
1
+ import { DEFAULT_TOLERANCE, EPS, RECORD_EPS, boundsOf, boundsOf as boundsOf$1, checkInput, marginSides, pickMoves, portfolio, rectInRegion, regionHitsRect, translate, turnBox, turnPoint, turnPort, turnRegion } from "@mark1russell7/layout-contract";
2
2
  // src/vector.ts
3
3
  /** A mutable two-dimensional vector. */
4
4
  var Vector = class Vector {
@@ -2559,6 +2559,14 @@ function hashInput(file) {
2559
2559
  const { hash: _hash, ...rest } = file;
2560
2560
  return sha256Hex(canonicalJson(rest)).slice(0, 16);
2561
2561
  }
2562
+ /**
2563
+ * This function gives the `outputHash` of an output. It is the first 16 hex characters of the SHA-256 of the canonical form of
2564
+ * its placements, sorted by id. The canonical form rounds each number with `round3`. Thus the order of the list does not count.
2565
+ * The records of the benchmark and the key of `packPortfolio` use it. It is not `outputHash` of the contract, which uses a grid.
2566
+ */
2567
+ function outputHash(output) {
2568
+ return sha256Hex(canonicalJson(output.placements.toSorted((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0))).slice(0, 16);
2569
+ }
2562
2570
  /** This function gives the scale of a count: the nearest of 1, 10, 100, 1000 and 10000 on a log scale. The count 0 gives `1`. */
2563
2571
  function countCell(count) {
2564
2572
  if (count <= 3) return "1";
@@ -3692,6 +3700,104 @@ function checkHard(input, output, tolerance = DEFAULT_TOLERANCE, options = {}) {
3692
3700
  complete
3693
3701
  };
3694
3702
  }
3703
+ // src/portfolio.ts
3704
+ /** The id of the trace stage of `packPortfolio`. Its measure `move.pick` is 1 when the pick is not member 0. */
3705
+ const PORTFOLIO_STAGE = "portfolio";
3706
+ /**
3707
+ * The levels of the pick of `packPortfolio` and of the portfolio report of the benchmark, in order. Level 0 is `hard`.
3708
+ *
3709
+ * - `hard`: the count of hard breaks of `checkHard` with `exactContainer`. Lower is better, with the minimum effect 0.
3710
+ * - `pack.overflow.excessArea`: the overflow area above its bound. Lower is better.
3711
+ * - `pack.fill`: the fill of the hull. Higher is better.
3712
+ */
3713
+ const PORTFOLIO_LEVELS = Object.freeze([
3714
+ {
3715
+ id: "hard",
3716
+ spec: {
3717
+ direction: "lower",
3718
+ minEffect: 0
3719
+ }
3720
+ },
3721
+ {
3722
+ id: "pack.overflow.excessArea",
3723
+ spec: MEASURE_SPECS["pack.overflow.excessArea"]
3724
+ },
3725
+ {
3726
+ id: "pack.fill",
3727
+ spec: MEASURE_SPECS["pack.fill"]
3728
+ }
3729
+ ]);
3730
+ /** This function gives the count of the hard breaks of an output: the sum of `checkHard` with `exactContainer`. */
3731
+ function hardBreaks(input, output) {
3732
+ return Object.values(checkHard(input, output, void 0, { exactContainer: true })).reduce((sum, n) => sum + n, 0);
3733
+ }
3734
+ /**
3735
+ * This function makes an opt-in portfolio of strategies of the registry with `portfolio` of the contract.
3736
+ * Its `pick(input)` packs the input with each member and gives the output of the winner, its id and the trace.
3737
+ *
3738
+ * - A member is a strategy id, or a `PortfolioEntry` with options. The members run in the given order.
3739
+ * - The key is the hard breaks, then `pack.overflow.excessArea`, then `pack.fill`. `PORTFOLIO_LEVELS` gives the specs.
3740
+ * - The hash of the key is `outputHash`. `selectBest` of the contract picks the winner.
3741
+ * - The output of the winner gets the trace stage `portfolio` with `move.pick` of `pickMoves`.
3742
+ * - The function throws a `RangeError` for an unknown strategy, an empty list and two members with the same id.
3743
+ */
3744
+ function packPortfolio(members, options = {}) {
3745
+ const seed = options.seed ?? 0;
3746
+ const list = members.map((m) => {
3747
+ const e = typeof m === "string" ? {
3748
+ id: m,
3749
+ strategy: m
3750
+ } : m;
3751
+ strategy(e.strategy);
3752
+ return {
3753
+ id: e.id,
3754
+ run: (input) => packWith(e.strategy, input, e.options, seed)
3755
+ };
3756
+ });
3757
+ const cache = /* @__PURE__ */ new WeakMap();
3758
+ const measured = (input, output) => {
3759
+ let m = cache.get(output);
3760
+ if (m === void 0) {
3761
+ m = measure(input, output);
3762
+ cache.set(output, m);
3763
+ }
3764
+ return m;
3765
+ };
3766
+ const key = {
3767
+ hard: hardBreaks,
3768
+ levels: PORTFOLIO_LEVELS.slice(1).map((level) => ({
3769
+ id: level.id,
3770
+ spec: level.spec,
3771
+ value: (input, output) => measured(input, output)[level.id]
3772
+ })),
3773
+ hash: outputHash
3774
+ };
3775
+ const limits = {
3776
+ ...options.budgetMs !== void 0 ? { budgetMs: options.budgetMs } : {},
3777
+ ...options.maxMembers !== void 0 ? { maxMembers: options.maxMembers } : {},
3778
+ ...options.now !== void 0 ? { now: options.now } : {}
3779
+ };
3780
+ const inner = portfolio(options.id ?? "portfolio", list, key, limits);
3781
+ const pick = (input) => {
3782
+ const got = inner.pick(input);
3783
+ const stage = {
3784
+ id: PORTFOLIO_STAGE,
3785
+ measures: { "move.pick": pickMoves(got.trace).pick }
3786
+ };
3787
+ return {
3788
+ ...got,
3789
+ output: {
3790
+ ...got.output,
3791
+ trace: [...got.output.trace ?? [], stage]
3792
+ }
3793
+ };
3794
+ };
3795
+ return {
3796
+ id: inner.id,
3797
+ pick,
3798
+ run: (input) => pick(input).output
3799
+ };
3800
+ }
3695
3801
  // src/generators.ts
3696
3802
  /** The largest count of boxes that a generator makes. */
3697
3803
  const MAX_COUNT = 1e5;
@@ -4606,6 +4712,6 @@ function corpus(name, specs) {
4606
4712
  inputs
4607
4713
  };
4608
4714
  }
4609
- export { DEFAULT_TOLERANCE, EPS, MAXRECTS_BANDS, MAXRECTS_RULES, MEASURE_SPECS, RECORD_EPS, Rect, SHELF_FITS, SORT_ORDERS, UnsupportedCell, Vector, aspectError, assertSupported, canonicalJson, cards, cellOf, checkHard, checkInput, compareRects, corpus, countCell, createContext, dashboard, edgeCases, fnv1a32, freeSpace, fromRects, gallery, generator, generators, hashInput, isDeterministic, logSweep, lowestWindow, marginOf, maxrects, measure, measureChange, medianRatio, mulberry32, pack, packFree, packMaxRects, packRows, packShelf, packSkyline, packWith, packingMetrics, pairedRatio, push, pushCascade, quantile, rectGrid, rectScattered, round3, roundMeasures, rows, shelf, skyline, strategies, strategy, supportsCell, tailShare, toPackInput, toRects, turnItem, turnPoint, turnPort, turnRegion, unsupportedOf, wordCloud };
4715
+ export { DEFAULT_TOLERANCE, EPS, MAXRECTS_BANDS, MAXRECTS_RULES, MEASURE_SPECS, PORTFOLIO_LEVELS, PORTFOLIO_STAGE, RECORD_EPS, Rect, SHELF_FITS, SORT_ORDERS, UnsupportedCell, Vector, aspectError, assertSupported, canonicalJson, cards, cellOf, checkHard, checkInput, compareRects, 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, push, pushCascade, quantile, rectGrid, rectScattered, round3, roundMeasures, rows, shelf, skyline, strategies, strategy, supportsCell, tailShare, toPackInput, toRects, turnItem, turnPoint, turnPort, turnRegion, unsupportedOf, wordCloud };
4610
4716
 
4611
4717
  //# sourceMappingURL=index.js.map