From 40a4d9dbc12e802e2d0a7c3acd69bc7e394d4529 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Fri, 27 Apr 2012 10:03:58 -0700 Subject: Fix for 1525 Pen: "Uncaught RangeError: Maximum call stack size exceeded". (check if the second mouse click actually selects the existing first anchor point) --- js/helper-classes/3D/math-utils.js | 11 ++++++----- js/tools/PenTool.js | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 2f0283a9..35ee8112 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -928,17 +928,18 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { return 0; } //TODO testing...remove this block - console.log("getAxisAngleBetween3DVectors Angle: "+angle); if (isNaN(angle)){ - console.log("getAxisAngleBetween3DVectors Angle is NaN"); + console.log("Warning! getAxisAngleBetween3DVectors Angle is NaN"); } //TODO end testing block //optionally, if axis is provided, create the axis of rotation as well var rotAxis = VecUtils.vecCross(3, v1n, v2n); rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); - axis[0] = rotAxis[0]; - axis[1] = rotAxis[1]; - axis[2] = rotAxis[2]; + if (axis){ + axis[0] = rotAxis[0]; + axis[1] = rotAxis[1]; + axis[2] = rotAxis[2]; + } return angle; } }, diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 8ecc9f79..8cc32536 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -273,14 +273,36 @@ exports.PenTool = Montage.create(ShapeTool, { var swMousePos = hitRec.calculateStageWorldPoint(); swMousePos[0]+= snapManager.getStageWidth()*0.5; swMousePos[1]+= snapManager.getStageHeight()*0.5; - this._selectedSubpath.addAnchor(new AnchorPoint()); - var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); - newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); - newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); - newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); - //set the mode so that dragging will update the next and previous locations - this._editMode = this.EDIT_PREV_NEXT; - } + //check if the mouse click location is close to the existing anchor + var indexAndCode = this._selectedSubpath.pickAnchor(swMousePos[0], swMousePos[1], swMousePos[2], this._PICK_POINT_RADIUS); + if (indexAndCode[0]>=0){ + //the anchor point was hit, so we do not add another anchor + switch(indexAndCode[1]){ + case this._selectedSubpath.SEL_ANCHOR: + this._editMode = this.EDIT_ANCHOR; + break; + case this._selectedSubpath.SEL_PREV: + this._editMode = this.EDIT_PREV; + break; + case this._selectedSubpath.SEL_NEXT: + this._editMode = this.EDIT_NEXT; + break; + default: + this._editMode = this.EDIT_ANCHOR; + console.log("WARNING picked anchor point with incorrect mode"); + break; + } + + } else { + this._selectedSubpath.addAnchor(new AnchorPoint()); + var newAnchor = this._selectedSubpath.getAnchor(this._selectedSubpath.getSelectedAnchorIndex()); + newAnchor.setPos(swMousePos[0], swMousePos[1], swMousePos[2]); + newAnchor.setPrevPos(swMousePos[0], swMousePos[1], swMousePos[2]); + newAnchor.setNextPos(swMousePos[0], swMousePos[1], swMousePos[2]); + //set the mode so that dragging will update the next and previous locations + this._editMode = this.EDIT_PREV_NEXT; + } + } //if we have not yet created a canvas for this path //the selected subpath has a canvas, so test within that canvas' space else -- cgit v1.2.3