Skip to content

Commit 90db9fc

Browse files
authored
Fix bug in bounds (#1009)
1 parent 3868fe0 commit 90db9fc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { importSkia } from "../../renderer/__tests__/setup";
2+
3+
describe("Geometry", () => {
4+
it("should calculate the bounding box the union of multiple rectangles", () => {
5+
const { bounds, rect } = importSkia();
6+
7+
const r1 = rect(-10, -10, 30, 30);
8+
const r2 = rect(30, 30, 100, 20);
9+
const result = bounds([r1, r2]);
10+
expect(result.x).toBe(-10);
11+
expect(result.y).toBe(-10);
12+
expect(result.width).toBe(140);
13+
expect(result.height).toBe(60);
14+
});
15+
});

package/src/skia/core/Rect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const bounds = (rects: SkRect[]) => {
1212
const y = Math.min(...rects.map((r) => r.y));
1313
const width = Math.max(...rects.map((r) => r.x + r.width));
1414
const height = Math.max(...rects.map((r) => r.y + r.height));
15-
return rect(x, y, width, height);
15+
return rect(x, y, width - x, height - y);
1616
};
1717

1818
export const topLeft = (r: SkRect | SkRRect) =>

0 commit comments

Comments
 (0)