Skip to content

Commit ffd1d21

Browse files
committed
Rectangle.Union will now cache all vars internally so you can use one of the input rectangles as the output rectangle without corrupting it.
1 parent 28744bd commit ffd1d21

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* List.sort no longer takes an array as its argument, instead it only sorts the List contents by the defined property.
107107
* List.addMultiple has been removed. Used `List.add` instead which offers the exact same functionality.
108108
* List is now internally using all of the new Utils.Array functions.
109+
* Rectangle.Union will now cache all vars internally so you can use one of the input rectangles as the output rectangle without corrupting it.
109110

110111
### Animation System Updates
111112

src/geom/rectangle/Union.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ var Union = function (rectA, rectB, out)
2424
{
2525
if (out === undefined) { out = new Rectangle(); }
2626

27+
// Cache vars so we can use one of the input rects as the output rect
2728
var x = Math.min(rectA.x, rectB.x);
2829
var y = Math.min(rectA.y, rectB.y);
30+
var w = Math.max(rectA.right, rectB.right) - x;
31+
var h = Math.max(rectA.bottom, rectB.bottom) - y;
2932

30-
return out.setTo(
31-
x,
32-
y,
33-
Math.max(rectA.right, rectB.right) - x,
34-
Math.max(rectA.bottom, rectB.bottom) - y
35-
);
33+
return out.setTo(x, y,w, h);
3634
};
3735

3836
module.exports = Union;

0 commit comments

Comments
 (0)