Skip to content

Commit

Permalink
feat: Add .next() method to enclose and start a new bin
Browse files Browse the repository at this point in the history
  • Loading branch information
soimy committed Jun 4, 2019
1 parent e1ff25d commit 9dbe754
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 13 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ let input = [ // any object with width & height is OK since v2.1.0
];

packer.addArray(input); // Start packing with input array
packer.next(); // Start a new packer bin
packer.addArray(input.slice(2)); // Adding to the new bin
packer.bins.forEach(bin => {
console.log(bin.rects);
});
Expand Down Expand Up @@ -91,6 +93,10 @@ Adds a rect to an existing bin or creates a new one to accomodate it. Accept any

Adds multiple rects. Since the input is automatically sorted before adding this approach usually leads to fewer bins created than separate calls to ```.add()```

#### ```packer.next()```

Stop adding new element to the current bin and return a new bin. After calling `next()` all elements will no longer added to previous bins.

#### ```let bins = packer.save()```

Save current bins settings and free area to an Array of objects for later use. Better to `JSON.stringify(bins)` and store in file.
Expand Down
6 changes: 5 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
✔ 更新README.md @done(19-05-26 17:34)
✔ Test增加Generic type部分 @done(19-05-26 17:04)
✔ 发布2.1.0版 @done(19-05-26 18:20)
☐ 增加Bin.border控制参数
☐ 增加Bin.border控制参数
✔ `hash`二次排序 @done(19-06-04 15:39)
☐ 完善注释和文档
✔ 发布gh-pages @done(19-06-04 15:39)
✔ 增加翻片儿`next()` @done(19-06-04 15:39)
11 changes: 11 additions & 0 deletions dist/maxrects-packer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ declare class MaxRectsPacker<T extends IRectangle = Rectangle> {
* @memberof MaxRectsPacker
*/
addArray(rects: T[]): void;
/**
* Stop adding new element to the current bin and return a new bin.
*
* note: After calling `next()` all elements will no longer added to previous bins.
*
* @returns {Bin}
* @memberof MaxRectsPacker
*/
next(): Bin;
/**
* Load bins to the packer, overwrite exist bins
* @param {MaxRectsBin[]} bins MaxRectsBin objects
Expand All @@ -200,6 +209,8 @@ declare class MaxRectsPacker<T extends IRectangle = Rectangle> {
* @memberof MaxRectsPacker
*/
private sort;
private _currentBinIndex;
readonly currentBinIndex: number;
}

declare class MaxRectsBin<T extends IRectangle = Rectangle> extends Bin {
Expand Down
20 changes: 18 additions & 2 deletions dist/maxrects-packer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/maxrects-packer.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/maxrects-packer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9dbe754

Please sign in to comment.