@mark1russell7/packing 0.2.7 → 0.2.8
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 +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/portfolio.ts +4 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/packing",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.8",
|
|
5
5
|
"description": "Rectangle packing: shelf, guillotine and skyline strategies, push cascades and measures of a layout.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"rectangle-packing",
|
package/src/portfolio.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { pickMoves, portfolio, type Member, type Portfolio, type PortfolioKey, t
|
|
|
5
5
|
import { checkHard } from "./check.ts";
|
|
6
6
|
import type { PackInput, PackOutput } from "./contract.ts";
|
|
7
7
|
import { outputHash } from "./layout-input.ts";
|
|
8
|
-
import { MEASURE_SPECS, measure, type LayoutMeasures } from "./measures.ts";
|
|
8
|
+
import { MEASURE_SPECS, measure, roundMeasures, type LayoutMeasures } from "./measures.ts";
|
|
9
9
|
import { packWith, strategy } from "./registry.ts";
|
|
10
10
|
|
|
11
11
|
/** A member of `packPortfolio`: a strategy of the registry with some options. The id names the member in the trace. */
|
|
@@ -59,6 +59,7 @@ export function hardBreaks(input: PackInput, output: PackOutput): number {
|
|
|
59
59
|
* - A member is a strategy id, or a `PortfolioEntry` with options. The members run in the given order.
|
|
60
60
|
* - `members` is a list, or a function of the input that gives the list. The strategy `portfolio` uses the function form.
|
|
61
61
|
* - The key is the hard breaks, then `pack.overflow.excessArea`, then `pack.fill`. `PORTFOLIO_LEVELS` gives the specs.
|
|
62
|
+
* - The key reads the measures after `roundMeasures`, as a record keeps them. A replay of the records gives the same pick.
|
|
62
63
|
* - The hash of the key is `outputHash`. `selectBest` of the contract picks the winner.
|
|
63
64
|
* - The output of the winner gets the trace stage `portfolio` with `move.pick` of `pickMoves`.
|
|
64
65
|
* - The function throws a `RangeError` for an unknown strategy, an empty list and two members with the same id.
|
|
@@ -81,7 +82,8 @@ export function packPortfolio(
|
|
|
81
82
|
const measured = (input: PackInput, output: PackOutput): LayoutMeasures => {
|
|
82
83
|
let m = cache.get(output);
|
|
83
84
|
if (m === undefined) {
|
|
84
|
-
|
|
85
|
+
// The key reads the measures as a record keeps them, so a replay of the records gives the same pick
|
|
86
|
+
m = roundMeasures(measure(input, output));
|
|
85
87
|
cache.set(output, m);
|
|
86
88
|
}
|
|
87
89
|
return m;
|