aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorPushkar Joshi2012-04-09 15:55:10 -0700
committerPushkar Joshi2012-04-09 15:55:10 -0700
commitdae3041e6b8269da3d593a44c09e2288bb434a02 (patch)
tree495fc661a2e90816706a09b8d7d702550bd7fd8c /js/lib
parent6cce5e9367676f5b452c28dd7d960aa46f4e464c (diff)
downloadninja-dae3041e6b8269da3d593a44c09e2288bb434a02.tar.gz
snapping feedback for pen tool, correct for subpaths that may lie on rotated canvas, and with a rotated view
Diffstat (limited to 'js/lib')
-rwxr-xr-xjs/lib/geom/sub-path.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index d784fbc6..33bcfc9a 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -620,7 +620,28 @@ GLSubpath.prototype._isWithinBoundingBox = function(point, ctrlPts, radius) {
620 return true; 620 return true;
621}; 621};
622 622
623GLSubpath.prototype._checkAnchorIntersection = function(pickX, pickY, pickZ, radSq, anchorIndex, minDistance) { 623GLSubpath.prototype._checkAnchorIntersection = function(pickX, pickY, pickZ, radSq, anchorIndex, minDistance, useLocal) {
624 //if we are asked to use the local coordinate and the local coordinate for this anchor exists
625 if (useLocal && this._anchorSampleIndex.length>anchorIndex && this._LocalPoints.length > this._anchorSampleIndex[anchorIndex]) {
626 var localCoord = this._LocalPoints[this._anchorSampleIndex[anchorIndex]]
627 var distSq = VecUtils.vecDistSq(3, [pickX, pickY, pickZ], localCoord);
628 //check the anchor point
629 if (distSq < radSq && distSq<minDistance) {
630 return this.SEL_ANCHOR;
631 }
632 /*
633 //check the prev. and next of the selected anchor point
634 distSq = this._Anchors[anchorIndex].getPrevDistanceSq(pickX, pickY, pickZ);
635 if (distSq<radSq && distSq<minDistance){
636 return this.SEL_PREV;
637 }
638 distSq = this._Anchors[anchorIndex].getNextDistanceSq(pickX, pickY, pickZ);
639 if (distSq<radSq && distSq<minDistance){
640 return this.SEL_NEXT;
641 }*/
642 return this.SEL_NONE;
643 }
644
624 var distSq = this._Anchors[anchorIndex].getDistanceSq(pickX, pickY, pickZ); 645 var distSq = this._Anchors[anchorIndex].getDistanceSq(pickX, pickY, pickZ);
625 //check the anchor point 646 //check the anchor point
626 if (distSq < radSq && distSq<minDistance) { 647 if (distSq < radSq && distSq<minDistance) {
@@ -638,7 +659,7 @@ GLSubpath.prototype._checkAnchorIntersection = function(pickX, pickY, pickZ, rad
638 return this.SEL_NONE; 659 return this.SEL_NONE;
639}; 660};
640 661
641GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { 662GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius, useLocal) {
642 var numAnchors = this._Anchors.length; 663 var numAnchors = this._Anchors.length;
643 var selAnchorIndex = -1; 664 var selAnchorIndex = -1;
644 var retCode = this.SEL_NONE; 665 var retCode = this.SEL_NONE;
@@ -646,14 +667,14 @@ GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) {
646 var radSq = radius * radius; 667 var radSq = radius * radius;
647 //check if the clicked location is close to the currently selected anchor position 668 //check if the clicked location is close to the currently selected anchor position
648 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){ 669 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){
649 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, this._selectedAnchorIndex, minDistance); 670 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, this._selectedAnchorIndex, minDistance, useLocal);
650 if (retCode!==this.SEL_NONE){ 671 if (retCode!==this.SEL_NONE){
651 return [this._selectedAnchorIndex, retCode]; 672 return [this._selectedAnchorIndex, retCode];
652 } 673 }
653 } 674 }
654 //now check if the click location is close to any anchor position 675 //now check if the click location is close to any anchor position
655 for (var i = 0; i < numAnchors; i++) { 676 for (var i = 0; i < numAnchors; i++) {
656 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, i, minDistance); 677 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, i, minDistance, useLocal);
657 if (retCode!==this.SEL_NONE){ 678 if (retCode!==this.SEL_NONE){
658 selAnchorIndex=i; 679 selAnchorIndex=i;
659 break; 680 break;