From 25e406c9924438697564bc2341bd5b045a1dd85c Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 11 Apr 2012 10:07:42 -0700 Subject: Use local coordinates to pick a point within the path (works correctly even with canvas and/or stage transformation). Dragging does not yet work in case of canvas transformation --- js/lib/geom/sub-path.js | 87 +++++++++++++++++++++++++++++++++++-------------- js/tools/PenTool.js | 20 ++++++++---- 2 files changed, 75 insertions(+), 32 deletions(-) diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 64f27bd3..87840bdc 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -752,9 +752,9 @@ GLSubpath.prototype.pathSamplesLocalHitTest = function(pickX, pickY, pickZ, radi currAnchor = nextAnchor; }//for every anchor i return [selAnchorIndex,retParam]; - }; + //pick the path point closest to the specified location, return null if some anchor point (or its handles) is within radius, else return the parameter distance GLSubpath.prototype.pathHitTest = function (pickX, pickY, pickZ, radius) { var numAnchors = this._Anchors.length; @@ -828,16 +828,27 @@ GLSubpath.prototype.pathHitTest = function (pickX, pickY, pickZ, radius) { return [selAnchorIndex,retParam]; } //GLSubpath.pathHitTest function + //pick the path point closest to the specified location, return null if some anchor point (or its handles) is within radius, else return the parameter distance -GLSubpath.prototype.pickPath = function (pickX, pickY, pickZ, radius) { +GLSubpath.prototype.pickPath = function (pickX, pickY, pickZ, radius, useLocal) { var numAnchors = this._Anchors.length; var selAnchorIndex = -1; var retCode = this.SEL_NONE; var radSq = radius * radius; var minDistance = Infinity; + + //ignore the useLocal flag if the anchor points are not in-sync. with the local coordinates + if (numAnchors != this._AnchorLocalCoords.length){ + useLocal = false; + } + //check if the clicked location is close to the currently selected anchor position if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex=0 && selAnchorIndex === -1) { - var distSq = this._Anchors[this._selectedAnchorIndex].getPrevDistanceSq(pickX, pickY, pickZ); + var distSq; + if (!useLocal) + distSq = this._Anchors[this._selectedAnchorIndex].getPrevDistanceSq(pickX, pickY, pickZ); + else + distSq = VecUtils.vecDistSq(3, this._AnchorLocalCoords[this._selectedAnchorIndex][0], [pickX, pickY, pickZ]); + if (distSq < minDistance && distSq < radSq){ selAnchorIndex = this._selectedAnchorIndex; minDistance = distSq; retCode = retCode | this.SEL_PREV; } else { //check the next for this anchor point - distSq = this._Anchors[this._selectedAnchorIndex].getNextDistanceSq(pickX, pickY, pickZ); + if (!useLocal) + distSq = this._Anchors[this._selectedAnchorIndex].getNextDistanceSq(pickX, pickY, pickZ); + else + distSq = VecUtils.vecDistSq(3, this._AnchorLocalCoords[this._selectedAnchorIndex][2], [pickX, pickY, pickZ]); + if (distSq 1) { @@ -1011,7 +1018,6 @@ exports.PenTool = Montage.create(ShapeTool, { ctx.stroke(); } - //display selected anchor and its prev. and next points if (this._selectedSubpath && subpath === this._selectedSubpath && this._selectedSubpath.getSelectedAnchorIndex()!== -1) { ctx.lineWidth = 1; -- cgit v1.2.3