Skip to content

Commit 1e11d78

Browse files
authored
Merge pull request #755 from jonobr1/747-nested-group-client-rect
747 Fix Nested Group and Shallow Bounding Box Calculations
2 parents fae372b + 9236652 commit 1e11d78

File tree

6 files changed

+64
-17
lines changed

6 files changed

+64
-17
lines changed

build/two.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ var Two = (() => {
766766
svg: "SVGRenderer",
767767
canvas: "CanvasRenderer"
768768
},
769-
Version: "v0.8.15",
770-
PublishDate: "2025-01-01T01:30:08.872Z",
769+
Version: "v0.8.16",
770+
PublishDate: "2025-01-06T21:30:44.526Z",
771771
Identifier: "two-",
772772
Resolution: 12,
773773
AutoCalculateImportedMatrices: true,
@@ -6186,10 +6186,10 @@ var Two = (() => {
61866186
const [bx, by] = matrix.multiply(rect.right, rect.top);
61876187
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
61886188
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);
6189-
top = min3(ay, by, cy, dy);
6190-
left = min3(ax, bx, cx, dx);
6191-
right = max3(ax, bx, cx, dx);
6192-
bottom = max3(ay, by, cy, dy);
6189+
top = min3(ay, by, cy, dy, top);
6190+
left = min3(ax, bx, cx, dx, left);
6191+
right = max3(ax, bx, cx, dx, right);
6192+
bottom = max3(ay, by, cy, dy, bottom);
61936193
} else {
61946194
top = min3(rect.top, top);
61956195
left = min3(rect.left, left);

build/two.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/two.module.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ var Constants = {
782782
svg: "SVGRenderer",
783783
canvas: "CanvasRenderer"
784784
},
785-
Version: "v0.8.15",
786-
PublishDate: "2025-01-01T01:30:08.872Z",
785+
Version: "v0.8.16",
786+
PublishDate: "2025-01-06T21:30:44.526Z",
787787
Identifier: "two-",
788788
Resolution: 12,
789789
AutoCalculateImportedMatrices: true,
@@ -6206,10 +6206,10 @@ var _Group = class extends Shape {
62066206
const [bx, by] = matrix.multiply(rect.right, rect.top);
62076207
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
62086208
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);
6209-
top = min3(ay, by, cy, dy);
6210-
left = min3(ax, bx, cx, dx);
6211-
right = max3(ax, bx, cx, dx);
6212-
bottom = max3(ay, by, cy, dy);
6209+
top = min3(ay, by, cy, dy, top);
6210+
left = min3(ax, bx, cx, dx, left);
6211+
right = max3(ax, bx, cx, dx, right);
6212+
bottom = max3(ay, by, cy, dy, bottom);
62136213
} else {
62146214
top = min3(rect.top, top);
62156215
left = min3(rect.left, left);

src/group.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ export class Group extends Shape {
672672
const [cx, cy] = matrix.multiply(rect.left, rect.bottom);
673673
const [dx, dy] = matrix.multiply(rect.right, rect.bottom);
674674

675-
top = min(ay, by, cy, dy);
676-
left = min(ax, bx, cx, dx);
677-
right = max(ax, bx, cx, dx);
678-
bottom = max(ay, by, cy, dy);
675+
top = min(ay, by, cy, dy, top);
676+
left = min(ax, bx, cx, dx, left);
677+
right = max(ax, bx, cx, dx, right);
678+
bottom = max(ay, by, cy, dy, bottom);
679679
} else {
680680
top = min(rect.top, top);
681681
left = min(rect.left, left);

tests/suite/core.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,52 @@ QUnit.test('Two.Group Object Conversion', function (assert) {
11861186
// );
11871187
});
11881188

1189+
QUnit.test('Two.Group.getBoundingClientRect(shallow)', function (assert) {
1190+
assert.expect(6);
1191+
1192+
const group = new Two.Group();
1193+
1194+
for (let i = 0; i < 3; i++) {
1195+
const x = i * 100;
1196+
const width = 100;
1197+
const height = 50;
1198+
const child = new Two.Rectangle(x, 0, width, height);
1199+
group.add(child);
1200+
}
1201+
1202+
const rect = group.getBoundingClientRect(true);
1203+
assert.equal(
1204+
rect.top,
1205+
-25.5,
1206+
'Two.Group.getBoundingClientRect(shallow) correctly calculates top property.'
1207+
);
1208+
assert.equal(
1209+
rect.bottom,
1210+
25.5,
1211+
'Two.Group.getBoundingClientRect(shallow) correctly calculates bottom property.'
1212+
);
1213+
assert.equal(
1214+
rect.left,
1215+
-50.5,
1216+
'Two.Group.getBoundingClientRect(shallow) correctly calculates left property.'
1217+
);
1218+
assert.equal(
1219+
rect.right,
1220+
250.5,
1221+
'Two.Group.getBoundingClientRect(shallow) correctly calculates right property.'
1222+
);
1223+
assert.equal(
1224+
rect.width,
1225+
301,
1226+
'Two.Group.getBoundingClientRect(shallow) correctly calculates width property.'
1227+
);
1228+
assert.equal(
1229+
rect.height,
1230+
51,
1231+
'Two.Group.getBoundingClientRect(shallow) correctly calculates height property.'
1232+
);
1233+
});
1234+
11891235
QUnit.test('Two.Text Object Conversion', function (assert) {
11901236
assert.expect(9);
11911237

wiki/changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. The format
1414
## Nightly
1515

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

1819
## Dec 31, 2024 v0.8.15
1920

0 commit comments

Comments
 (0)