diff options
Diffstat (limited to 'src')
-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 |