UNPKG

1.48 kBPlain TextView Raw
1import { IRectangle, Rectangle } from "./geom/Rectangle";
2import { IOption } from "./maxrects-packer";
3import { Bin } from "./abstract-bin";
4
5export class OversizedElementBin<T extends IRectangle = Rectangle> extends Bin {
6 public width: number;
7 public height: number;
8 public data: any;
9 public maxWidth: number;
10 public maxHeight: number;
11 public options: IOption;
12 public rects: T[] = [];
13 public freeRects: IRectangle[];
14
15 constructor (rect: T);
16 constructor (width: number, height: number, data: any);
17 constructor (...args: any[]) {
18 super();
19 if (args.length === 1) {
20 if (typeof args[0] !== 'object') throw new Error("OversizedElementBin: Wrong parameters");
21 const rect = args[0];
22 this.rects = [rect];
23 this.width = rect.width;
24 this.height = rect.height;
25 this.data = rect.data;
26 rect.oversized = true;
27 } else {
28 this.width = args[0];
29 this.height = args[1];
30 this.data = args.length > 2 ? args[2] : null;
31 const rect: any = new Rectangle(this.width, this.height);
32 rect.oversized = true;
33 rect.data = this.data;
34 this.rects.push(rect);
35 }
36 this.freeRects = [];
37 this.maxWidth = this.width;
38 this.maxHeight = this.height;
39 this.options = { smart: false, pot: false, square: false };
40 }
41
42 add () { return undefined; }
43}