Skip to content

Commit

Permalink
Merge pull request #755 from jonobr1/747-nested-group-client-rect
Browse files Browse the repository at this point in the history
747 Fix Nested Group and Shallow Bounding Box Calculations
  • Loading branch information
jonobr1 authored Jan 6, 2025
2 parents fae372b + 9236652 commit 1e11d78
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 17 deletions.
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

0 comments on commit 1e11d78

Please sign in to comment.