Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

747 Fix Nested Group and Shallow Bounding Box Calculations #755

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build/two.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,8 @@ var Two = (() => {
svg: "SVGRenderer",
canvas: "CanvasRenderer"
},
Version: "v0.8.15",
PublishDate: "2025-01-01T01:30:08.872Z",
Version: "v0.8.16",
PublishDate: "2025-01-06T21:30:44.526Z",
Identifier: "two-",
Resolution: 12,
AutoCalculateImportedMatrices: true,
Expand Down Expand Up @@ -6186,10 +6186,10 @@ var Two = (() => {
const [bx, by] = matrix.multiply(rect.right, rect.top);
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);
top = min3(ay, by, cy, dy);
left = min3(ax, bx, cx, dx);
right = max3(ax, bx, cx, dx);
bottom = max3(ay, by, cy, dy);
top = min3(ay, by, cy, dy, top);
left = min3(ax, bx, cx, dx, left);
right = max3(ax, bx, cx, dx, right);
bottom = max3(ay, by, cy, dy, bottom);
} else {
top = min3(rect.top, top);
left = min3(rect.left, left);
Expand Down
2 changes: 1 addition & 1 deletion build/two.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions build/two.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ var Constants = {
svg: "SVGRenderer",
canvas: "CanvasRenderer"
},
Version: "v0.8.15",
PublishDate: "2025-01-01T01:30:08.872Z",
Version: "v0.8.16",
PublishDate: "2025-01-06T21:30:44.526Z",
Identifier: "two-",
Resolution: 12,
AutoCalculateImportedMatrices: true,
Expand Down Expand Up @@ -6206,10 +6206,10 @@ var _Group = class extends Shape {
const [bx, by] = matrix.multiply(rect.right, rect.top);
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);
top = min3(ay, by, cy, dy);
left = min3(ax, bx, cx, dx);
right = max3(ax, bx, cx, dx);
bottom = max3(ay, by, cy, dy);
top = min3(ay, by, cy, dy, top);
left = min3(ax, bx, cx, dx, left);
right = max3(ax, bx, cx, dx, right);
bottom = max3(ay, by, cy, dy, bottom);
} else {
top = min3(rect.top, top);
left = min3(rect.left, left);
Expand Down
8 changes: 4 additions & 4 deletions src/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,10 @@ export class Group extends Shape {
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);

top = min(ay, by, cy, dy);
left = min(ax, bx, cx, dx);
right = max(ax, bx, cx, dx);
bottom = max(ay, by, cy, dy);
top = min(ay, by, cy, dy, top);
left = min(ax, bx, cx, dx, left);
right = max(ax, bx, cx, dx, right);
bottom = max(ay, by, cy, dy, bottom);
} else {
top = min(rect.top, top);
left = min(rect.left, left);
Expand Down
46 changes: 46 additions & 0 deletions tests/suite/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,52 @@ QUnit.test('Two.Group Object Conversion', function (assert) {
// );
});

QUnit.test('Two.Group.getBoundingClientRect(shallow)', function (assert) {
assert.expect(6);

const group = new Two.Group();

for (let i = 0; i < 3; i++) {
const x = i * 100;
const width = 100;
const height = 50;
const child = new Two.Rectangle(x, 0, width, height);
group.add(child);
}

const rect = group.getBoundingClientRect(true);
assert.equal(
rect.top,
-25.5,
'Two.Group.getBoundingClientRect(shallow) correctly calculates top property.'
);
assert.equal(
rect.bottom,
25.5,
'Two.Group.getBoundingClientRect(shallow) correctly calculates bottom property.'
);
assert.equal(
rect.left,
-50.5,
'Two.Group.getBoundingClientRect(shallow) correctly calculates left property.'
);
assert.equal(
rect.right,
250.5,
'Two.Group.getBoundingClientRect(shallow) correctly calculates right property.'
);
assert.equal(
rect.width,
301,
'Two.Group.getBoundingClientRect(shallow) correctly calculates width property.'
);
assert.equal(
rect.height,
51,
'Two.Group.getBoundingClientRect(shallow) correctly calculates height property.'
);
});

QUnit.test('Two.Text Object Conversion', function (assert) {
assert.expect(9);

Expand Down
1 change: 1 addition & 0 deletions wiki/changelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. The format
## Nightly

+ `Two.ZUI.reset` updates the surfaces to be reflect reset orientation
+ `Two.Group.getBoundingClientRect(shallow)` correctly infers min and max values to calculate dimensions correctly

## Dec 31, 2024 v0.8.15

Expand Down
Loading