From 3aa51e81c3022386fd90284fd5aaa6f8b80c6fce Mon Sep 17 00:00:00 2001 From: Vidar Hokstad Date: Sat, 6 Jun 2009 17:06:44 +0000 Subject: [PATCH] Shortened some of the attribute setting code git-svn-id: http://svg-edit.googlecode.com/svn/trunk@40 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 61d265a3..50dbf41b 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -266,33 +266,15 @@ function SvgCanvas(doc) var size = Math.max( Math.abs(x - start_x), Math.abs(y - start_y) ); shape.setAttributeNS(null, "width", size); shape.setAttributeNS(null, "height", size); - if(start_x < x) { - shape.setAttributeNS(null, "x", start_x); - } else { - shape.setAttributeNS(null, "x", start_x - size); - } - if(start_y < y) { - shape.setAttributeNS(null, "y", start_y); - } else { - shape.setAttributeNS(null, "y", start_y - size); - } + shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size); + shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size); break; case "select": case "rect": - if (start_x < x) { - shape.setAttributeNS(null, "x", start_x); - shape.setAttributeNS(null, "width", x - start_x); - } else { - shape.setAttributeNS(null, "x", x); - shape.setAttributeNS(null, "width", start_x - x); - } - if (start_y < y) { - shape.setAttributeNS(null, "y", start_y); - shape.setAttributeNS(null, "height", y - start_y); - } else { - shape.setAttributeNS(null, "y", y); - shape.setAttributeNS(null, "height", start_y - y); - } + shape.setAttributeNS(null, "x", Math.min(start_x,x)); + shape.setAttributeNS(null, "y", Math.min(start_y,y)); + shape.setAttributeNS(null, "width", Math.abs(x-start_x)); + shape.setAttributeNS(null, "height", Math.abs(y-start_y)); break; case "circle": var cx = shape.getAttributeNS(null, "cx");