Skip to content

Commit

Permalink
dist added
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 26, 2024
1 parent a0a51e6 commit 1f4a4d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 11 additions & 2 deletions dist/maxrects-packer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,19 @@
return false;
let tmpWidth = Math.max(this.width, node.x + node.width - this.padding + this.border);
let tmpHeight = Math.max(this.height, node.y + node.height - this.padding + this.border);
let tmpFits = !(tmpWidth > this.maxWidth || tmpHeight > this.maxHeight);
if (this.options.allowRotation) {
// do extra test on rotated node whether it's a better choice
const rotWidth = Math.max(this.width, node.x + node.height - this.padding + this.border);
const rotHeight = Math.max(this.height, node.y + node.width - this.padding + this.border);
if (rotWidth * rotHeight < tmpWidth * tmpHeight) {
const rotFits = !(rotWidth > this.maxWidth || rotHeight > this.maxHeight);
// only compare when both rects will fit into bin
if (tmpFits && rotFits && rotWidth * rotHeight < tmpWidth * tmpHeight) {
tmpWidth = rotWidth;
tmpHeight = rotHeight;
}
// if rot fits and tmpFits not then do not compare area and set rot directly (some cases area of not rotated is smaller but will not fit)
if (rotFits && !tmpFits) {
tmpWidth = rotWidth;
tmpHeight = rotHeight;
}
Expand All @@ -517,7 +525,8 @@
if (this.options.square) {
tmpWidth = tmpHeight = Math.max(tmpWidth, tmpHeight);
}
if (tmpWidth > this.maxWidth + this.padding || tmpHeight > this.maxHeight + this.padding) {
tmpFits = !(tmpWidth > this.maxWidth || tmpHeight > this.maxHeight);
if (!tmpFits) {
return false;
}
this.expandFreeRects(tmpWidth + this.padding, tmpHeight + this.padding);
Expand Down
13 changes: 11 additions & 2 deletions dist/maxrects-packer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,19 @@ class MaxRectsBin extends Bin {
return false;
let tmpWidth = Math.max(this.width, node.x + node.width - this.padding + this.border);
let tmpHeight = Math.max(this.height, node.y + node.height - this.padding + this.border);
let tmpFits = !(tmpWidth > this.maxWidth || tmpHeight > this.maxHeight);
if (this.options.allowRotation) {
// do extra test on rotated node whether it's a better choice
const rotWidth = Math.max(this.width, node.x + node.height - this.padding + this.border);
const rotHeight = Math.max(this.height, node.y + node.width - this.padding + this.border);
if (rotWidth * rotHeight < tmpWidth * tmpHeight) {
const rotFits = !(rotWidth > this.maxWidth || rotHeight > this.maxHeight);
// only compare when both rects will fit into bin
if (tmpFits && rotFits && rotWidth * rotHeight < tmpWidth * tmpHeight) {
tmpWidth = rotWidth;
tmpHeight = rotHeight;
}
// if rot fits and tmpFits not then do not compare area and set rot directly (some cases area of not rotated is smaller but will not fit)
if (rotFits && !tmpFits) {
tmpWidth = rotWidth;
tmpHeight = rotHeight;
}
Expand All @@ -511,7 +519,8 @@ class MaxRectsBin extends Bin {
if (this.options.square) {
tmpWidth = tmpHeight = Math.max(tmpWidth, tmpHeight);
}
if (tmpWidth > this.maxWidth + this.padding || tmpHeight > this.maxHeight + this.padding) {
tmpFits = !(tmpWidth > this.maxWidth || tmpHeight > this.maxHeight);
if (!tmpFits) {
return false;
}
this.expandFreeRects(tmpWidth + this.padding, tmpHeight + this.padding);
Expand Down

0 comments on commit 1f4a4d8

Please sign in to comment.