diff options
author | wout <wout@impinc.co.uk> | 2013-08-22 15:30:15 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-08-22 15:30:15 +0100 |
commit | 0ceb9b29401e26181d0b05cf8fed4c6aa1627447 (patch) | |
tree | 1d61b8ea4d172e82f3a0116032e178f34ec3639b /src/rbox.js | |
parent | bd58094c43ab78bec28ec97e62e71af9ad2febb4 (diff) | |
download | svg.js-0ceb9b29401e26181d0b05cf8fed4c6aa1627447.tar.gz svg.js-0ceb9b29401e26181d0b05cf8fed4c6aa1627447.zip |
Added merge() method to SVG.RBox
Diffstat (limited to 'src/rbox.js')
-rw-r--r-- | src/rbox.js | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/rbox.js b/src/rbox.js index 5eb474f..95cc1e2 100644 --- a/src/rbox.js +++ b/src/rbox.js @@ -50,4 +50,25 @@ SVG.RBox = function(element) { this.cx = this.x + this.width / 2 this.cy = this.y + this.height / 2 -}
\ No newline at end of file +} + +// +SVG.extend(SVG.RBox, { + // merge rect box with another, return a new instance + merge: function(box) { + var b = new SVG.RBox() + + /* merge box */ + b.x = Math.min(this.x, box.x) + b.y = Math.min(this.y, box.y) + b.width = Math.max(this.x + this.width, box.x + box.width) - b.x + b.height = Math.max(this.y + this.height, box.y + box.height) - b.y + + /* add the center */ + b.cx = b.x + b.width / 2 + b.cy = b.y + b.height / 2 + + return b + } + +})
\ No newline at end of file |