From 711346f1092c1347113b86e2b833e26061807606 Mon Sep 17 00:00:00 2001
From: Jeff Schiller
Date: Mon, 8 Nov 2010 08:42:46 +0000
Subject: [PATCH] Start on a svgutils unit test file
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1856 eee81c28-f429-11dd-99c0-75d572ba1ddd
---
editor/math.js | 18 +++++++++
editor/svgcanvas.js | 6 +--
editor/svgutils.js | 18 +--------
test/all_tests.html | 1 +
test/svgutils_test.html | 83 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 107 insertions(+), 19 deletions(-)
create mode 100644 test/svgutils_test.html
diff --git a/editor/math.js b/editor/math.js
index 08f253b3..5ae1e949 100644
--- a/editor/math.js
+++ b/editor/math.js
@@ -213,4 +213,22 @@ svgedit.math.snapToAngle = function(x1,y1,x2,y2) {
return {x:x, y:y, a:snapangle};
};
+
+// Function: rectsIntersect
+// Check if two rectangles (BBoxes objects) intersect each other
+//
+// Paramaters:
+// r1 - The first BBox-like object
+// r2 - The second BBox-like object
+//
+// Returns:
+// Boolean that's true if rectangles intersect
+svgedit.math.rectsIntersect = function(r1, r2) {
+ return r2.x < (r1.x+r1.width) &&
+ (r2.x+r2.width) > r1.x &&
+ r2.y < (r1.y+r1.height) &&
+ (r2.y+r2.height) > r1.y;
+};
+
+
})();
\ No newline at end of file
diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js
index a8541d8d..bea47484 100644
--- a/editor/svgcanvas.js
+++ b/editor/svgcanvas.js
@@ -1503,7 +1503,7 @@ var getIntersectionList = this.getIntersectionList = function(rect) {
var i = curBBoxes.length;
while (i--) {
if(!rubberBBox.width || !rubberBBox.width) continue;
- if (svgedit.utilities.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
+ if (svgedit.math.rectsIntersect(rubberBBox, curBBoxes[i].bbox)) {
resultList.push(curBBoxes[i].elem);
}
}
@@ -4660,7 +4660,7 @@ var textActions = canvas.textActions = function() {
// TODO: Find a way to make this work: Use transformed BBox instead of evt.target
// if(last_x === mouse_x && last_y === mouse_y
-// && !svgedit.utilities.rectsIntersect(transbb, {x: pt.x, y: pt.y, width:0, height:0})) {
+// && !svgedit.math.rectsIntersect(transbb, {x: pt.x, y: pt.y, width:0, height:0})) {
// textActions.toSelectMode(true);
// }
if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) {
@@ -6123,7 +6123,7 @@ var pathActions = this.pathActions = function() {
height: 0
};
- var sel = svgedit.utilities.rectsIntersect(rbb, pt_bb);
+ var sel = svgedit.math.rectsIntersect(rbb, pt_bb);
this.select(sel);
//Note that addPtsToSelection is not being run
diff --git a/editor/svgutils.js b/editor/svgutils.js
index 6d9d43af..ecb48ec4 100644
--- a/editor/svgutils.js
+++ b/editor/svgutils.js
@@ -183,22 +183,6 @@ svgedit.utilities.convertToXMLReferences = function(input) {
return output;
};
-// Function: rectsIntersect
-// Check if two rectangles (BBoxes objects) intersect each other
-//
-// Paramaters:
-// r1 - The first BBox-like object
-// r2 - The second BBox-like object
-//
-// Returns:
-// Boolean that's true if rectangles intersect
-svgedit.utilities.rectsIntersect = function(r1, r2) {
- return r2.x < (r1.x+r1.width) &&
- (r2.x+r2.width) > r1.x &&
- r2.y < (r1.y+r1.height) &&
- (r2.y+r2.height) > r1.y;
-};
-
// Function: text2xml
// Cross-browser compatible method of converting a string to an XML tree
// found this function here: http://groups.google.com/group/jquery-dev/browse_thread/thread/c6d11387c580a77f
@@ -332,6 +316,8 @@ svgedit.utilities.findDefs = function(svgElement) {
return defs;
};
+// TODO(codedread): Consider moving the next to functions to bbox.js
+
// Function: svgedit.utilities.getPathBBox
// Get correct BBox for a path in Webkit
// Converted from code found here:
diff --git a/test/all_tests.html b/test/all_tests.html
index 614ad1bf..d3c85327 100644
--- a/test/all_tests.html
+++ b/test/all_tests.html
@@ -7,6 +7,7 @@
All SVG-edit Tests
This file frames all SVG-edit test pages. This should only include tests known to work. If a test is broken in this page, it is possible that YOU broke it. Please do not submit code that breaks any of these tests.
+
+
+
+
+
+
+