Move snapToAngle() to math.js. Add build rule for Closure compiler in release mode.
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1834 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
33fdd28713
commit
6a74f57cf4
|
@ -12,11 +12,13 @@
|
|||
|
||||
(function() {
|
||||
|
||||
if (window.svgedit == undefined) {
|
||||
if (!window.svgedit) {
|
||||
window.svgedit = {};
|
||||
}
|
||||
|
||||
svgedit.BrowserSupport = {};
|
||||
if (!svgedit.BrowserSupport) {
|
||||
svgedit.BrowserSupport = {};
|
||||
}
|
||||
|
||||
var svgns = 'http://www.w3.org/2000/svg';
|
||||
var userAgent = navigator.userAgent;
|
||||
|
@ -27,7 +29,7 @@ svgedit.BrowserSupport.isWebkit = userAgent.indexOf("AppleWebKit") >= 0;
|
|||
svgedit.BrowserSupport.isGecko = userAgent.indexOf('Gecko/') >= 0;
|
||||
|
||||
// segList functions (for FF1.5 and 2.0)
|
||||
function getPathReplaceItem() {
|
||||
function supportPathReplaceItem() {
|
||||
var path = document.createElementNS(svgns,'path');
|
||||
path.setAttribute('d','M0,0 10,10');
|
||||
var seglist = path.pathSegList;
|
||||
|
@ -39,7 +41,7 @@ function getPathReplaceItem() {
|
|||
return false;
|
||||
}
|
||||
|
||||
function getPathInsertItemBefore() {
|
||||
function supportPathInsertItemBefore() {
|
||||
var path = document.createElementNS(svgns,'path');
|
||||
path.setAttribute('d','M0,0 10,10');
|
||||
var seglist = path.pathSegList;
|
||||
|
@ -52,7 +54,7 @@ function getPathInsertItemBefore() {
|
|||
}
|
||||
|
||||
// text character positioning
|
||||
function getTextCharPos() {
|
||||
function supportTextCharPos() {
|
||||
var retValue = false;
|
||||
var svgcontent = document.createElementNS(svgns, 'svg');
|
||||
document.documentElement.appendChild(svgcontent);
|
||||
|
@ -67,12 +69,12 @@ function getTextCharPos() {
|
|||
return retValue;
|
||||
}
|
||||
|
||||
function getEditableText() {
|
||||
function supportEditableText() {
|
||||
// TODO: Find better way to check support for this
|
||||
return svgedit.BrowserSupport.isOpera;
|
||||
}
|
||||
|
||||
function getGoodDecimals() {
|
||||
function supportGoodDecimals() {
|
||||
// Correct decimals on clone attributes (Opera < 10.5/win/non-en)
|
||||
var rect = document.createElementNS(svgns,'rect');
|
||||
rect.setAttribute('x',.1);
|
||||
|
@ -85,17 +87,17 @@ function getGoodDecimals() {
|
|||
return retValue;
|
||||
}
|
||||
|
||||
function getNonScalingStroke() {
|
||||
function supportNonScalingStroke() {
|
||||
var rect = document.createElementNS(svgns,'rect');
|
||||
rect.setAttribute('style','vector-effect:non-scaling-stroke');
|
||||
return rect.style.vectorEffect === 'non-scaling-stroke';
|
||||
}
|
||||
|
||||
svgedit.BrowserSupport.pathReplaceItem = getPathReplaceItem();
|
||||
svgedit.BrowserSupport.pathInsertItemBefore = getPathInsertItemBefore();
|
||||
svgedit.BrowserSupport.textCharPos = getTextCharPos();
|
||||
svgedit.BrowserSupport.editableText = getEditableText();
|
||||
svgedit.BrowserSupport.goodDecimals = getGoodDecimals();
|
||||
svgedit.BrowserSupport.nonScalingStroke = getNonScalingStroke();
|
||||
svgedit.BrowserSupport.pathReplaceItem = supportPathReplaceItem();
|
||||
svgedit.BrowserSupport.pathInsertItemBefore = supportPathInsertItemBefore();
|
||||
svgedit.BrowserSupport.textCharPos = supportTextCharPos();
|
||||
svgedit.BrowserSupport.editableText = supportEditableText();
|
||||
svgedit.BrowserSupport.goodDecimals = supportGoodDecimals();
|
||||
svgedit.BrowserSupport.nonScalingStroke = supportNonScalingStroke();
|
||||
|
||||
})();
|
|
@ -184,4 +184,33 @@ svgedit.math.transformListToTransform = function(tlist, min, max) {
|
|||
return svg.createSVGTransformFromMatrix(m);
|
||||
};
|
||||
|
||||
|
||||
// Function: svgedit.math.snapToAngle
|
||||
// Returns a 45 degree angle coordinate associated with the two given
|
||||
// coordinates
|
||||
//
|
||||
// Parameters:
|
||||
// x1 - First coordinate's x value
|
||||
// x2 - Second coordinate's x value
|
||||
// y1 - First coordinate's y value
|
||||
// y2 - Second coordinate's y value
|
||||
//
|
||||
// Returns:
|
||||
// Object with the following values:
|
||||
// x - The angle-snapped x value
|
||||
// y - The angle-snapped y value
|
||||
// snapangle - The angle at which to snap
|
||||
svgedit.math.snapToAngle = function(x1,y1,x2,y2) {
|
||||
var snap = Math.PI/4; // 45 degrees
|
||||
var dx = x2 - x1;
|
||||
var dy = y2 - y1;
|
||||
var angle = Math.atan2(dy,dx);
|
||||
var dist = Math.sqrt(dx * dx + dy * dy);
|
||||
var snapangle= Math.round(angle/snap)*snap;
|
||||
var x = x1 + dist*Math.cos(snapangle);
|
||||
var y = y1 + dist*Math.sin(snapangle);
|
||||
//console.log(x1,y1,x2,y2,x,y,angle)
|
||||
return {x:x, y:y, a:snapangle};
|
||||
};
|
||||
|
||||
})();
|
|
@ -34,13 +34,7 @@
|
|||
<script type="text/javascript" src="jquerybbq/jquery.bbq.min.js"></script>
|
||||
<script type="text/javascript" src="jgraduate/jquery.jgraduate.min.js"></script>
|
||||
<script type="text/javascript" src="spinbtn/JQuerySpinBtn.min.js"></script>
|
||||
<script type="text/javascript" src="browsersupport.min.js"></script>
|
||||
<script type="text/javascript" src="svgtransformlist.min.js"></script>
|
||||
<script type="text/javascript" src="math.min.js"></script>
|
||||
<script type="text/javascript" src="svgutils.min.js"></script>
|
||||
<script type="text/javascript" src="svgcanvas.min.js"></script>
|
||||
<script type="text/javascript" src="svg-editor.min.js"></script>
|
||||
script type="text/javascript" src="locale/locale.min.js"></script-->
|
||||
<script type="text/javascript" src="svgedit.compiled.js"></script>
|
||||
|
||||
|
||||
<!-- always minified scripts -->
|
||||
|
|
|
@ -1444,13 +1444,20 @@ var SelectorManager;
|
|||
var SVGEditTransformList = svgedit.SVGTransformList;
|
||||
var svgTransformLists = {};
|
||||
|
||||
// Group: Helper functions
|
||||
|
||||
// "Import" from svgutils.js
|
||||
var walkTree = this.walkTree = svgedit.Utilities.walkTree;
|
||||
var walkTreePost = this.walkTreePost = svgedit.Utilities.walkTreePost;
|
||||
var getUrlFromAttr = this.getUrlFromAttr = svgedit.Utilities.getUrlFromAttr;
|
||||
|
||||
// "Import" from math.js.
|
||||
var transformPoint = svgedit.math.transformPoint;
|
||||
var isIdentity = svgedit.math.isIdentity;
|
||||
var matrixMultiply = this.matrixMultiply = svgedit.math.matrixMultiply;
|
||||
var hasMatrixTransform = this.hasMatrixTransform = svgedit.math.hasMatrixTransform;
|
||||
var transformBox = this.transformBox = svgedit.math.transformBox;
|
||||
var transformListToTransform = this.transformListToTransform = svgedit.math.transformListToTransform;
|
||||
var snapToAngle = svgedit.math.snapToAngle;
|
||||
|
||||
// Function: assignAttributes
|
||||
// Assigns multiple attributes to an element.
|
||||
//
|
||||
|
@ -3611,14 +3618,6 @@ var recalculateDimensions = this.recalculateDimensions = function(selected) {
|
|||
// Root Current Transformation Matrix in user units
|
||||
var root_sctm = null;
|
||||
|
||||
// "Import" math.js.
|
||||
var transformPoint = svgedit.math.transformPoint;
|
||||
var isIdentity = svgedit.math.isIdentity;
|
||||
var matrixMultiply = this.matrixMultiply = svgedit.math.matrixMultiply;
|
||||
var hasMatrixTransform = this.hasMatrixTransform = svgedit.math.hasMatrixTransform;
|
||||
var transformBox = this.transformBox = svgedit.math.transformBox;
|
||||
var transformListToTransform = this.transformListToTransform = svgedit.math.transformListToTransform;
|
||||
|
||||
// Function: getMatrix
|
||||
// Get the matrix object for a given element
|
||||
//
|
||||
|
@ -4296,7 +4295,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||
dy = snapToGrid(dy);
|
||||
}
|
||||
|
||||
if(evt.shiftKey) { var xya = Utils.snapToAngle(start_x,start_y,x,y); x=xya.x; y=xya.y; }
|
||||
if(evt.shiftKey) { var xya = snapToAngle(start_x,start_y,x,y); x=xya.x; y=xya.y; }
|
||||
|
||||
if (dx != 0 || dy != 0) {
|
||||
var len = selectedElements.length;
|
||||
|
@ -4481,7 +4480,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||
var x2 = x;
|
||||
var y2 = y;
|
||||
|
||||
if(evt.shiftKey) { var xya=Utils.snapToAngle(start_x,start_y,x2,y2); x2=xya.x; y2=xya.y; }
|
||||
if(evt.shiftKey) { var xya = snapToAngle(start_x,start_y,x2,y2); x2=xya.x; y2=xya.y; }
|
||||
|
||||
shape.setAttributeNS(null, "x2", x2);
|
||||
shape.setAttributeNS(null, "y2", y2);
|
||||
|
@ -4575,7 +4574,7 @@ var getMouseTarget = this.getMouseTarget = function(evt) {
|
|||
if(evt.shiftKey) {
|
||||
var x1 = path.dragging?path.dragging[0]:start_x;
|
||||
var y1 = path.dragging?path.dragging[1]:start_y;
|
||||
var xya=Utils.snapToAngle(x1,y1,x,y);
|
||||
var xya = snapToAngle(x1,y1,x,y);
|
||||
x=xya.x; y=xya.y;
|
||||
}
|
||||
|
||||
|
@ -6558,7 +6557,7 @@ var pathActions = this.pathActions = function() {
|
|||
var last = drawn_path.pathSegList.getItem(num -1);
|
||||
var lastx = last.x, lasty = last.y;
|
||||
|
||||
if(evt.shiftKey) { var xya=Utils.snapToAngle(lastx,lasty,x,y); x=xya.x; y=xya.y; }
|
||||
if(evt.shiftKey) { var xya = snapToAngle(lastx,lasty,x,y); x=xya.x; y=xya.y; }
|
||||
|
||||
// Use the segment defined by stretchy
|
||||
var s_seg = stretchy.pathSegList.getItem(1);
|
||||
|
|
|
@ -20,8 +20,11 @@ if (!svgedit.Utilities) {
|
|||
svgedit.Utilities = {};
|
||||
}
|
||||
|
||||
// Constants
|
||||
|
||||
// String used to encode base64.
|
||||
svgedit.Utilities._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var KEYSTR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
||||
var XLINKNS = "http://www.w3.org/1999/xlink";
|
||||
|
||||
// Function: svgedit.Utilities.toXml
|
||||
// Converts characters in a string to XML-friendly entities.
|
||||
|
@ -65,7 +68,6 @@ svgedit.Utilities.encode64 = function(input) {
|
|||
// input = svgedit.Utilities.encodeUTF8(input); // convert non-ASCII characters
|
||||
input = svgedit.Utilities.convertToXMLReferences(input);
|
||||
if(window.btoa) return window.btoa(input); // Use native if available
|
||||
var _keyStr = svgedit.Utilities._keyStr;
|
||||
var output = new Array( Math.floor( (input.length + 2) / 3 ) * 4 );
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
|
@ -87,10 +89,10 @@ svgedit.Utilities.encode64 = function(input) {
|
|||
enc4 = 64;
|
||||
}
|
||||
|
||||
output[p++] = _keyStr.charAt(enc1);
|
||||
output[p++] = _keyStr.charAt(enc2);
|
||||
output[p++] = _keyStr.charAt(enc3);
|
||||
output[p++] = _keyStr.charAt(enc4);
|
||||
output[p++] = KEYSTR.charAt(enc1);
|
||||
output[p++] = KEYSTR.charAt(enc2);
|
||||
output[p++] = KEYSTR.charAt(enc3);
|
||||
output[p++] = KEYSTR.charAt(enc4);
|
||||
} while (i < input.length);
|
||||
|
||||
return output.join('');
|
||||
|
@ -109,10 +111,10 @@ svgedit.Utilities.decode64 = function(input) {
|
|||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
do {
|
||||
enc1 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc2 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc3 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc4 = _keyStr.indexOf(input.charAt(i++));
|
||||
enc1 = KEYSTR.indexOf(input.charAt(i++));
|
||||
enc2 = KEYSTR.indexOf(input.charAt(i++));
|
||||
enc3 = KEYSTR.indexOf(input.charAt(i++));
|
||||
enc4 = KEYSTR.indexOf(input.charAt(i++));
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
|
@ -190,34 +192,6 @@ svgedit.Utilities.rectsIntersect = function(r1, r2) {
|
|||
(r2.y+r2.height) > r1.y;
|
||||
};
|
||||
|
||||
// Function: snapToAngle
|
||||
// Returns a 45 degree angle coordinate associated with the two given
|
||||
// coordinates
|
||||
//
|
||||
// Parameters:
|
||||
// x1 - First coordinate's x value
|
||||
// x2 - Second coordinate's x value
|
||||
// y1 - First coordinate's y value
|
||||
// y2 - Second coordinate's y value
|
||||
//
|
||||
// Returns:
|
||||
// Object with the following values:
|
||||
// x - The angle-snapped x value
|
||||
// y - The angle-snapped y value
|
||||
// snapangle - The angle at which to snap
|
||||
svgedit.Utilities.snapToAngle = function(x1,y1,x2,y2) {
|
||||
var snap = Math.PI/4; // 45 degrees
|
||||
var dx = x2 - x1;
|
||||
var dy = y2 - y1;
|
||||
var angle = Math.atan2(dy,dx);
|
||||
var dist = Math.sqrt(dx * dx + dy * dy);
|
||||
var snapangle= Math.round(angle/snap)*snap;
|
||||
var x = x1 + dist*Math.cos(snapangle);
|
||||
var y = y1 + dist*Math.sin(snapangle);
|
||||
//console.log(x1,y1,x2,y2,x,y,angle)
|
||||
return {x:x, y:y, a:snapangle};
|
||||
},
|
||||
|
||||
// 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
|
||||
|
@ -323,13 +297,13 @@ svgedit.Utilities.getUrlFromAttr = function(attrVal) {
|
|||
// Function: svgedit.Utilities.getHref
|
||||
// Returns the given element's xlink:href value
|
||||
svgedit.Utilities.getHref = function(elem) {
|
||||
return elem.getAttributeNS(xlinkns, "href");
|
||||
return elem.getAttributeNS(XLINKNS, "href");
|
||||
}
|
||||
|
||||
// Function: svgedit.Utilities.setHref
|
||||
// Sets the given element's xlink:href value
|
||||
svgedit.Utilities.setHref = function(elem, val) {
|
||||
elem.setAttributeNS(xlinkns, "xlink:href", val);
|
||||
elem.setAttributeNS(XLINKNS, "xlink:href", val);
|
||||
}
|
||||
|
||||
// Function: findDefs
|
||||
|
|
Loading…
Reference in New Issue