@mark1russell7/packing 0.1.2 → 0.1.3
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 +32 -0
- package/build/index.d.ts +338 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +986 -2
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters.ts +261 -0
- package/src/check.ts +84 -0
- package/src/contract.ts +203 -0
- package/src/convert.ts +51 -0
- package/src/frame.ts +262 -0
- package/src/index.ts +41 -0
- package/src/pack.ts +2 -1
- package/src/registry.ts +23 -0
- package/src/strategy.ts +214 -0
package/README.md
CHANGED
|
@@ -78,6 +78,38 @@ const moved = pushCascade(dropped, cards, { gap: 8 });
|
|
|
78
78
|
const { utilization, raggedness, rows } = packingMetrics(Rect.packed(rects));
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
+
## The Packer interface
|
|
82
|
+
|
|
83
|
+
Each strategy has one interface: `pack(input, options, context)`. The input is a `PackInput`: a container, items, obstacles and a gap. The output is a `PackOutput`. The output does not change the input.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { checkHard, packWith, type PackInput } from "@mark1russell7/packing";
|
|
87
|
+
|
|
88
|
+
const input: PackInput = {
|
|
89
|
+
container: { w: 400, fixed: "width", inset: 8 },
|
|
90
|
+
gap: 4,
|
|
91
|
+
items: [
|
|
92
|
+
{ id: "a", w: 120, h: 40, margin: 2 },
|
|
93
|
+
{ id: "pin", w: 60, h: 60, x: 200, y: 8, locked: true },
|
|
94
|
+
{ id: "b", w: 80, h: 30 },
|
|
95
|
+
],
|
|
96
|
+
obstacles: [{ id: "logo", region: { kind: "rect", x: 300, y: 0, w: 100, h: 50 } }],
|
|
97
|
+
};
|
|
98
|
+
const output = packWith("shelf", input, { sortOrder: "input" });
|
|
99
|
+
output.placements; // the position of each item
|
|
100
|
+
output.size; // the size of the container
|
|
101
|
+
checkHard(input, output); // { "no-overlap": 0, "in-container": 0, "locked-kept": 0, complete: 0 }
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- The registry `strategies` has `rows`, `skyline`, `shelf` and `push`. `strategy(id)` gives one, and `packWith(id, input, options, seed)` packs with it.
|
|
105
|
+
- `fixed` is `size`, `width`, `height` or `none`. A fixed height turns the axes. The value `none` uses the size search `logSweep`, which wraps `packFree`.
|
|
106
|
+
- 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.
|
|
107
|
+
- The strategies of this version do not turn items, read groups or pack shapes. A turnable item, a group or a shape gives `UnsupportedCell`.
|
|
108
|
+
- `checkHard` counts the breaks of the hard rules: `no-overlap`, `in-container`, `locked-kept` and `complete`.
|
|
109
|
+
- `fromRects` and `toRects` connect the interface to the `Rect` objects.
|
|
110
|
+
|
|
111
|
+
`docs/PACKER.md` in the repository gives the interface in full.
|
|
112
|
+
|
|
81
113
|
## More
|
|
82
114
|
|
|
83
115
|
- [The repository](https://github.com/mark1russell7/packing): the source, the tests and the roadmap.
|
package/build/index.d.ts
CHANGED
|
@@ -258,5 +258,342 @@ interface MetricsOptions {
|
|
|
258
258
|
* ```
|
|
259
259
|
*/
|
|
260
260
|
export declare function packingMetrics(rects: readonly Rect[], options?: MetricsOptions): PackingMetrics;
|
|
261
|
-
|
|
261
|
+
/** A region. The forms and the rules are those of `docs/FORMAT.md`. The y axis points down. */
|
|
262
|
+
type Region = {
|
|
263
|
+
kind: "rect";
|
|
264
|
+
x: number;
|
|
265
|
+
y: number;
|
|
266
|
+
w: number;
|
|
267
|
+
h: number;
|
|
268
|
+
} | {
|
|
269
|
+
kind: "polygon";
|
|
270
|
+
points: [number, number][];
|
|
271
|
+
holes?: [number, number][][];
|
|
272
|
+
} | {
|
|
273
|
+
kind: "circle";
|
|
274
|
+
cx: number;
|
|
275
|
+
cy: number;
|
|
276
|
+
r: number;
|
|
277
|
+
} | {
|
|
278
|
+
kind: "ellipse";
|
|
279
|
+
cx: number;
|
|
280
|
+
cy: number;
|
|
281
|
+
rx: number;
|
|
282
|
+
ry: number;
|
|
283
|
+
};
|
|
284
|
+
/** The container of a packing. */
|
|
285
|
+
interface Container {
|
|
286
|
+
/** The width. Without it, the packer searches the width. */
|
|
287
|
+
w?: number;
|
|
288
|
+
/** The height. Without it, the packer searches the height. */
|
|
289
|
+
h?: number;
|
|
290
|
+
/** The sides that stay: `size` keeps `w` and `h`, `width` keeps `w`, `height` keeps `h`, and `none` searches both. */
|
|
291
|
+
fixed: "size" | "width" | "height" | "none";
|
|
292
|
+
/** The target aspect (the width divided by the height) for the value `none` of `fixed`. The default is 1. */
|
|
293
|
+
aspect?: number;
|
|
294
|
+
/** The weight of the aspect error in the objective. The value 0 gives the least area. The default is 1. */
|
|
295
|
+
aspectWeight?: number;
|
|
296
|
+
/** The shape. Without it, the container is the rectangle from 0, 0 to `w`, `h`. */
|
|
297
|
+
shape?: Region;
|
|
298
|
+
/** The space between the border and the items with their margins. The default is 0. */
|
|
299
|
+
inset?: number;
|
|
300
|
+
}
|
|
301
|
+
/** An obstacle: an area that no item enters. */
|
|
302
|
+
interface Obstacle {
|
|
303
|
+
id: string;
|
|
304
|
+
region: Region;
|
|
305
|
+
/** Without it, the obstacle stays. With it, the packer can move the obstacle for `cost` times the distance. */
|
|
306
|
+
move?: {
|
|
307
|
+
cost: number;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/** The margin of an item on each side. */
|
|
311
|
+
interface Margin {
|
|
312
|
+
top: number;
|
|
313
|
+
right: number;
|
|
314
|
+
bottom: number;
|
|
315
|
+
left: number;
|
|
316
|
+
}
|
|
317
|
+
/** A port on the border of an item. */
|
|
318
|
+
interface Port {
|
|
319
|
+
id: string;
|
|
320
|
+
side: "top" | "right" | "bottom" | "left";
|
|
321
|
+
/** The point on the border of the item, relative to its top-left corner. Without it, the router chooses the point. */
|
|
322
|
+
x?: number;
|
|
323
|
+
y?: number;
|
|
324
|
+
}
|
|
325
|
+
/** An item to pack. The file format names it a box. */
|
|
326
|
+
interface Item {
|
|
327
|
+
id: string;
|
|
328
|
+
w: number;
|
|
329
|
+
h: number;
|
|
330
|
+
/** The reading order. Without it, the index in the array is the rank. */
|
|
331
|
+
rank?: number;
|
|
332
|
+
group?: string;
|
|
333
|
+
parent?: string;
|
|
334
|
+
/** A shape relative to the origin of the item. Without it, the item is the rectangle `w` by `h`. */
|
|
335
|
+
shape?: Region;
|
|
336
|
+
/** A locked item keeps `x` and `y`. The packer reads it as an obstacle. */
|
|
337
|
+
locked?: boolean;
|
|
338
|
+
x?: number;
|
|
339
|
+
y?: number;
|
|
340
|
+
/** The value `true` lets the packer turn the item by 90 degrees. The default is `false`. */
|
|
341
|
+
turnable?: boolean;
|
|
342
|
+
/** A ring around the item that no other item and no route enters. The default is 0. */
|
|
343
|
+
margin?: number | Margin;
|
|
344
|
+
/** The ports. The packer keeps them, and turns them with the item. */
|
|
345
|
+
ports?: Port[];
|
|
346
|
+
}
|
|
347
|
+
/** The input of a packing: a `layout-input/1` file without `edges`, with `items` for `boxes`. */
|
|
348
|
+
interface PackInput {
|
|
349
|
+
container: Container;
|
|
350
|
+
items: Item[];
|
|
351
|
+
obstacles?: Obstacle[];
|
|
352
|
+
/** The free space between two items with their margins. Routes use this space. The default is 0. */
|
|
353
|
+
gap?: number;
|
|
354
|
+
}
|
|
355
|
+
/** The position of one item after the packing. */
|
|
356
|
+
interface Placement {
|
|
357
|
+
id: string;
|
|
358
|
+
x: number;
|
|
359
|
+
y: number;
|
|
360
|
+
/** The turn: 0 or 90, only for an item with `turnable` set to `true`. */
|
|
361
|
+
turn?: 0 | 90;
|
|
362
|
+
}
|
|
363
|
+
/** The facts of one stage of a packing. */
|
|
364
|
+
interface StageTrace {
|
|
365
|
+
/** The id of the stage, for example `skyline` or `log-sweep`. */
|
|
366
|
+
id: string;
|
|
367
|
+
/** The time of the stage in milliseconds. */
|
|
368
|
+
ms: number;
|
|
369
|
+
/** The measures of the stage, by the names of `docs/FORMAT.md`. */
|
|
370
|
+
measures: Record<string, number>;
|
|
371
|
+
}
|
|
372
|
+
/** The output of a packing. The output does not change the input. */
|
|
373
|
+
interface PackOutput {
|
|
374
|
+
placements: Placement[];
|
|
375
|
+
/** The ids of the items that the packer did not place. */
|
|
376
|
+
overflow: string[];
|
|
377
|
+
/** The size of the container after the packing. For a free size, the size that the search found. */
|
|
378
|
+
size: {
|
|
379
|
+
w: number;
|
|
380
|
+
h: number;
|
|
381
|
+
};
|
|
382
|
+
/** The new positions of the obstacles that moved. */
|
|
383
|
+
moved: {
|
|
384
|
+
id: string;
|
|
385
|
+
x: number;
|
|
386
|
+
y: number;
|
|
387
|
+
}[];
|
|
388
|
+
/** The facts of each stage, for the site and the records. */
|
|
389
|
+
trace: StageTrace[];
|
|
390
|
+
}
|
|
391
|
+
/** The tolerances of the hard rules. */
|
|
392
|
+
interface Tolerance {
|
|
393
|
+
/** The rule `no-overlap`: two boxes overlap only by more than this value. */
|
|
394
|
+
overlap: number;
|
|
395
|
+
/** The router rule that a route does not go through a box. */
|
|
396
|
+
through: number;
|
|
397
|
+
}
|
|
398
|
+
/** The tolerance for the comparison of two numbers in an engine. */
|
|
399
|
+
export declare const EPS = 1e-6;
|
|
400
|
+
/** The tolerance for the comparison of two numbers of a file. The files round to 3 decimals. */
|
|
401
|
+
export declare const RECORD_EPS = .001;
|
|
402
|
+
/** The default tolerances of the hard rules. Each record writes its tolerances in its top-level field `tolerance`. */
|
|
403
|
+
export declare const DEFAULT_TOLERANCE: Readonly<Tolerance>;
|
|
404
|
+
/** This function gives the margin of an item on each side. A number is the same margin on each side. */
|
|
405
|
+
export declare function marginOf(item: Pick<Item, "margin">): Margin;
|
|
406
|
+
/** This function gives the point `px`, `py` of an item of height `h` after a turn of 90 degrees clockwise. */
|
|
407
|
+
export declare function turnPoint(px: number, py: number, h: number): [number, number];
|
|
408
|
+
/** This function turns a port of an item of height `h` by 90 degrees clockwise. The side turns from top to right. */
|
|
409
|
+
export declare function turnPort(port: Port, h: number): Port;
|
|
410
|
+
/** This function turns a region relative to an item of height `h` by 90 degrees clockwise. */
|
|
411
|
+
export declare function turnRegion(region: Region, h: number): Region;
|
|
412
|
+
/**
|
|
413
|
+
* This function gives an item after a turn of 90 degrees clockwise, with the y axis down (decision 1 of
|
|
414
|
+
* `docs/PACKER.md`). The width and the height change places. The top-left corner, the id and the other fields stay.
|
|
415
|
+
* The ports, the shape and the margin turn with the item. The function does not change its argument.
|
|
416
|
+
*/
|
|
417
|
+
export declare function turnItem(item: Item): Item;
|
|
418
|
+
/** For each dimension of the taxonomy, the values that a strategy supports. `docs/research/TAXONOMY.md` gives the values. */
|
|
419
|
+
interface Supports {
|
|
420
|
+
containerSize: ("fixed" | "freeHeight" | "freeWidth" | "freeAspect" | "freeArea")[];
|
|
421
|
+
containerShape: ("rect" | "convex" | "polygon" | "circle" | "ellipse" | "holes")[];
|
|
422
|
+
/** The movement of the obstacles. An empty list supports only an input with no obstacle and no locked item. */
|
|
423
|
+
obstacleMove: ("fixed" | "costly" | "free")[];
|
|
424
|
+
itemShape: ("rect" | "circle" | "convex" | "polygon" | "mixed")[];
|
|
425
|
+
rotation: ("none" | "quarter" | "any")[];
|
|
426
|
+
order: ("free" | "soft" | "hard")[];
|
|
427
|
+
groups: ("none" | "flat" | "nested")[];
|
|
428
|
+
mode: ("offline" | "online" | "incremental")[];
|
|
429
|
+
}
|
|
430
|
+
/** A dimension of `Supports`. */
|
|
431
|
+
type Dimension = keyof Supports;
|
|
432
|
+
/** A value of a dimension of `Supports`. */
|
|
433
|
+
type DimensionValue<D extends Dimension = Dimension> = Supports[D][number];
|
|
434
|
+
/**
|
|
435
|
+
* The cell of an input: one value for each packer dimension that the input tells. The input does not tell the mode.
|
|
436
|
+
* Without obstacles and locked items, the cell has no `obstacleMove`.
|
|
437
|
+
*/
|
|
438
|
+
interface Cell {
|
|
439
|
+
containerSize: DimensionValue<"containerSize">;
|
|
440
|
+
containerShape: DimensionValue<"containerShape">;
|
|
441
|
+
obstacleMove?: DimensionValue<"obstacleMove">;
|
|
442
|
+
itemShape: DimensionValue<"itemShape">;
|
|
443
|
+
rotation: DimensionValue<"rotation">;
|
|
444
|
+
order: DimensionValue<"order">;
|
|
445
|
+
groups: DimensionValue<"groups">;
|
|
446
|
+
}
|
|
447
|
+
/** The context of one packing. */
|
|
448
|
+
interface PackContext {
|
|
449
|
+
/** The seed. A strategy gets each random number from `rng`, not from `Math.random`. */
|
|
450
|
+
seed: number;
|
|
451
|
+
/** The random numbers in `[0, 1)`, from `mulberry32` with `seed`. */
|
|
452
|
+
rng: () => number;
|
|
453
|
+
/** A limit for the strategies that search. The strategy gives its best result at the limit. */
|
|
454
|
+
budget?: {
|
|
455
|
+
ms?: number;
|
|
456
|
+
steps?: number;
|
|
457
|
+
};
|
|
458
|
+
/** The previous output, for the mode `incremental`. */
|
|
459
|
+
previous?: PackOutput;
|
|
460
|
+
}
|
|
461
|
+
/** A packing strategy behind the Packer interface. */
|
|
462
|
+
interface Strategy<O = unknown> {
|
|
463
|
+
/** A stable name, for example `shelf`. The records use it. */
|
|
464
|
+
id: string;
|
|
465
|
+
/** The family of the catalog, for example `shelf` or `skyline`. */
|
|
466
|
+
family: string;
|
|
467
|
+
/** The ids of the catalog rows that this strategy builds. */
|
|
468
|
+
catalog: string[];
|
|
469
|
+
/** The cells that the strategy supports. */
|
|
470
|
+
supports: Supports;
|
|
471
|
+
/** The default options. A record writes the options in full. */
|
|
472
|
+
defaults: O;
|
|
473
|
+
/** The value `true` tells that the result depends only on the input, the options and the seed. */
|
|
474
|
+
deterministic: boolean;
|
|
475
|
+
/** This method packs an input. It throws `UnsupportedCell` for an input outside the cells of `supports`. */
|
|
476
|
+
pack(input: PackInput, options: O, context: PackContext): PackOutput;
|
|
477
|
+
}
|
|
478
|
+
/** A size search: it gives a strategy of a fixed width the cells `freeAspect` and `freeArea`. */
|
|
479
|
+
interface SizeSearch {
|
|
480
|
+
id: string;
|
|
481
|
+
/** This method searches the size of the container for an input with `fixed` set to `none`. `options` go to `inner`. */
|
|
482
|
+
search(input: PackInput, inner: Strategy, context: PackContext, options?: unknown): PackOutput;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* The error of a strategy for an input outside its cells. The benchmark records this result. It is not a failure of the
|
|
486
|
+
* strategy.
|
|
487
|
+
*/
|
|
488
|
+
export declare class UnsupportedCell extends Error {
|
|
489
|
+
/** The dimension of the taxonomy. */
|
|
490
|
+
readonly dimension: Dimension;
|
|
491
|
+
/** The value of the input that the strategy does not support. */
|
|
492
|
+
readonly value: string;
|
|
493
|
+
constructor(dimension: Dimension, value: string);
|
|
494
|
+
}
|
|
495
|
+
/** This function gives a generator of random numbers in `[0, 1)`: `mulberry32` of `docs/FORMAT.md`. */
|
|
496
|
+
export declare function mulberry32(seed: number): () => number;
|
|
497
|
+
/** This function makes the context of one packing from a seed. */
|
|
498
|
+
export declare function createContext(seed?: number, more?: Omit<PackContext, "seed" | "rng">): PackContext;
|
|
499
|
+
/**
|
|
500
|
+
* This function gives the cell of an input: the values of the packer dimensions that the input tells.
|
|
501
|
+
*
|
|
502
|
+
* - `containerSize` comes from `fixed`. The value `none` gives `freeArea` when `aspectWeight` is 0, and `freeAspect` if not.
|
|
503
|
+
* - `containerShape` comes from the shape. A rectangle container with an obstacle of another region gives `holes`.
|
|
504
|
+
* - `obstacleMove` is the hardest value of the obstacles and the locked items: `costly`, then `free`, then `fixed`.
|
|
505
|
+
* - `order` is `soft` when an item has a rank, and `free` if not. The input does not tell a hard order.
|
|
506
|
+
* - `groups` is `nested` when an item has a parent, `flat` when an item has a group, and `none` if not.
|
|
507
|
+
*/
|
|
508
|
+
export declare function cellOf(input: PackInput): Cell;
|
|
509
|
+
/** This function gives the first dimension of a cell that `supports` does not hold, or `undefined` when it holds each one. */
|
|
510
|
+
export declare function unsupportedOf(supports: Supports, cell: Partial<Record<Dimension, string>>): {
|
|
511
|
+
dimension: Dimension;
|
|
512
|
+
value: string;
|
|
513
|
+
} | undefined;
|
|
514
|
+
/** This function tells if `supports` holds each value of a cell. A dimension that the cell does not have is held. */
|
|
515
|
+
export declare function supportsCell(supports: Supports, cell: Partial<Record<Dimension, string>>): boolean;
|
|
516
|
+
/** This function throws `UnsupportedCell` for the first value of the cell of an input that `supports` does not hold. */
|
|
517
|
+
export declare function assertSupported(supports: Supports, input: PackInput): void;
|
|
518
|
+
/** The options of the strategies `rows`, `skyline` and `shelf`. */
|
|
519
|
+
interface LayoutStrategyOptions {
|
|
520
|
+
/** The order of the items before the packing. The items are in the order of their rank first. */
|
|
521
|
+
sortOrder: SortOrder;
|
|
522
|
+
/** The number of widths that the first pass of the size search `log-sweep` tries. */
|
|
523
|
+
samples: number;
|
|
524
|
+
}
|
|
525
|
+
/** The options of the strategy `push`. */
|
|
526
|
+
interface PushStrategyOptions {
|
|
527
|
+
/** The order of the items that the cascade does not place. */
|
|
528
|
+
sortOrder: SortOrder;
|
|
529
|
+
/** The most shoves for each item. The cascade stops at this limit. */
|
|
530
|
+
maxShovesPerItem: number;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* The strategy `rows` uses `packRows`: a guillotine row packing with a recursive gap fill. It supports no obstacle and
|
|
534
|
+
* no locked item, because `packRows` does not go around them. Turnable items, groups and shapes throw `UnsupportedCell`.
|
|
535
|
+
*/
|
|
536
|
+
export declare const rows: Strategy<LayoutStrategyOptions>;
|
|
537
|
+
/**
|
|
538
|
+
* The strategy `skyline` uses `packSkyline`: each item goes to the lowest place where it fits. It packs around the
|
|
539
|
+
* locked items and the fixed obstacles. Turnable items, groups and shapes throw `UnsupportedCell`.
|
|
540
|
+
*/
|
|
541
|
+
export declare const skyline: Strategy<LayoutStrategyOptions>;
|
|
542
|
+
/**
|
|
543
|
+
* The strategy `shelf` uses `packShelf`: rows filled left to right, around the locked items and the fixed obstacles.
|
|
544
|
+
* With the sort order `input`, the rows keep the rank order. Turnable items, groups and shapes throw `UnsupportedCell`.
|
|
545
|
+
*/
|
|
546
|
+
export declare const shelf: Strategy<LayoutStrategyOptions>;
|
|
547
|
+
/**
|
|
548
|
+
* The size search `log-sweep` uses `packFree` of 0.1.2: widths on a log scale, then the widths near the best width. It
|
|
549
|
+
* wraps `rows`, `skyline` and `shelf`. The objective is the area of the frame times `1 + aspectWeight * aspectError`.
|
|
550
|
+
*/
|
|
551
|
+
export declare const logSweep: SizeSearch;
|
|
552
|
+
/**
|
|
553
|
+
* The strategy `push` uses `pushCascade`. Each item starts at its `x` and `y`, or at its place in `context.previous`.
|
|
554
|
+
* Each item in rank order pushes the items and the movable obstacles that it overlaps. Then `packSkyline` places the
|
|
555
|
+
* items with no start, and the items that still overlap. The output tells each obstacle that moved.
|
|
556
|
+
*/
|
|
557
|
+
export declare const push: Strategy<PushStrategyOptions>;
|
|
558
|
+
/**
|
|
559
|
+
* This function makes a `PackInput` from the `Rect` objects of 0.1. The id of each item is the index of its rectangle.
|
|
560
|
+
*
|
|
561
|
+
* - `fixedSize` gives `fixed` set to `size`, `fixedWidth` gives `width`, and an outer rectangle without them gives `none`.
|
|
562
|
+
* - A locked rectangle gives a locked item at its position.
|
|
563
|
+
* - An outer rectangle at a position other than 0, 0 gives a rectangle shape at that position.
|
|
564
|
+
*/
|
|
565
|
+
export declare function fromRects<T>(rects: readonly Rect<T>[], outer: Rect<T>): PackInput;
|
|
566
|
+
/**
|
|
567
|
+
* This function writes an output back into the `Rect` objects of `fromRects`. It sets the position and `wasPacked` of
|
|
568
|
+
* each rectangle, and the free sides of the outer rectangle. It gives the outer rectangle.
|
|
569
|
+
*/
|
|
570
|
+
export declare function toRects<T>(output: PackOutput, rects: Rect<T>[], outer: Rect<T>): Rect<T>;
|
|
571
|
+
/** Each strategy of the package. The benchmark starts each one on each input of the corpus. */
|
|
572
|
+
export declare const strategies: readonly Strategy[];
|
|
573
|
+
/** This function gives the strategy with an id. It throws a `RangeError` for an id that the registry does not have. */
|
|
574
|
+
export declare function strategy(id: string): Strategy;
|
|
575
|
+
/**
|
|
576
|
+
* This function packs an input with the strategy of an id. The options go over the defaults of the strategy. The
|
|
577
|
+
* context gets `mulberry32` with the seed. The default seed is 0.
|
|
578
|
+
*/
|
|
579
|
+
export declare function packWith(id: string, input: PackInput, options?: unknown, seed?: number): PackOutput;
|
|
580
|
+
/** The count of the breaks of each hard rule of the packer (`docs/FORMAT.md`). A good run has 0 for each rule. */
|
|
581
|
+
interface HardBreaks {
|
|
582
|
+
"no-overlap": number;
|
|
583
|
+
"in-container": number;
|
|
584
|
+
"locked-kept": number;
|
|
585
|
+
complete: number;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* This function counts the breaks of the 4 hard rules of the packer for an output.
|
|
589
|
+
*
|
|
590
|
+
* - `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`.
|
|
591
|
+
* - `in-container`: each item with its margin that goes out of a fixed side by more than `tolerance.overlap`.
|
|
592
|
+
* - `locked-kept`: each locked item that moved by more than `RECORD_EPS`, or that has no position.
|
|
593
|
+
* - `complete`: each item with no position that is not in the overflow.
|
|
594
|
+
*
|
|
595
|
+
* The rules read a shape of the container or of an obstacle as its bounding box. The result has no tolerance in it.
|
|
596
|
+
*/
|
|
597
|
+
export declare function checkHard(input: PackInput, output: PackOutput, tolerance?: Pick<Tolerance, "overlap">): HardBreaks;
|
|
598
|
+
export type { Cell, Container, Dimension, DimensionValue, FreeWidthOptions, FreeWidthResult, FreeWidthTry, HardBreaks, Item, LayoutStrategyOptions, Margin, MetricsOptions, Obstacle, PackContext, PackInput, PackLayoutOptions, PackOptions, PackOutput, PackingMetrics, Placement, Port, PushOptions, PushStrategyOptions, Region, ShelfOptions, SizeSearch, SortOrder, StageTrace, Strategy, Supports, Tolerance };
|
|
262
599
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -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"],"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;;SAKxB,UAAU,GAAG,OAAO,KAAK;;;;;;KC/DtB;;qBAGC,sBAAsB;;wBAGnB,aAAa,OAAO,aAAa,GAAG,GAAG,KAAK,IAAI,GAAG,KAAK;;UCLvD;;EAEf,YAAY;;;UAIG,0BAA0B;;;;;EAKzC;;;;;;;
|
|
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/strategy.ts","../src/adapters.ts","../src/convert.ts","../src/registry.ts","../src/check.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,GAA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