aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/sub-path.js51
1 files changed, 32 insertions, 19 deletions
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js
index 7046673e..9bd9ad9a 100755
--- a/js/lib/geom/sub-path.js
+++ b/js/lib/geom/sub-path.js
@@ -567,37 +567,50 @@ GLSubpath.prototype._isWithinBoundingBox = function(point, ctrlPts, radius) {
567 return true; 567 return true;
568}; 568};
569 569
570GLSubpath.prototype._checkAnchorIntersection = function(pickX, pickY, pickZ, radSq, anchorIndex, minDistance) {
571 var distSq = this._Anchors[anchorIndex].getDistanceSq(pickX, pickY, pickZ);
572 //check the anchor point
573 if (distSq < radSq && distSq<minDistance) {
574 return this.SEL_ANCHOR;
575 }
576 //check the prev. and next of the selected anchor point
577 distSq = this._Anchors[anchorIndex].getPrevDistanceSq(pickX, pickY, pickZ);
578 if (distSq<radSq && distSq<minDistance){
579 return this.SEL_PREV;
580 }
581 distSq = this._Anchors[anchorIndex].getNextDistanceSq(pickX, pickY, pickZ);
582 if (distSq<radSq && distSq<minDistance){
583 return this.SEL_NEXT;
584 }
585 return this.SEL_NONE;
586};
587
570GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { 588GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) {
571 var numAnchors = this._Anchors.length; 589 var numAnchors = this._Anchors.length;
572 var selAnchorIndex = -1; 590 var selAnchorIndex = -1;
573 var retCode = this.SEL_NONE; 591 var retCode = this.SEL_NONE;
574 var radSq = radius * radius;
575 var minDistance = Infinity; 592 var minDistance = Infinity;
593 var radSq = radius * radius;
576 //check if the clicked location is close to the currently selected anchor position 594 //check if the clicked location is close to the currently selected anchor position
577 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){ 595 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){
578 var distSq = this._Anchors[this._selectedAnchorIndex].getDistanceSq(pickX, pickY, pickZ); 596 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, this._selectedAnchorIndex, minDistance);
579 //check the anchor point 597 if (retCode!==this.SEL_NONE){
580 if (distSq < minDistance && distSq < radSq) { 598 return [this._selectedAnchorIndex, retCode];
581 selAnchorIndex = this._selectedAnchorIndex;
582 minDistance = distSq;
583 retCode = retCode | this.SEL_ANCHOR;
584 } 599 }
585 } 600 }
586 //now check if the click location is close to any anchor position 601 //now check if the click location is close to any anchor position
587 if (selAnchorIndex===-1) { 602 for (var i = 0; i < numAnchors; i++) {
588 for (var i = 0; i < numAnchors; i++) { 603 retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, i, minDistance);
589 var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ); 604 if (retCode!==this.SEL_NONE){
590 //check the anchor point 605 selAnchorIndex=i;
591 if (distSq < minDistance && distSq < radSq) { 606 break;
592 selAnchorIndex = i; 607 }
593 minDistance = distSq; 608 }//for every anchor i
594 } 609
595 }//for every anchor i 610 return [selAnchorIndex, retCode];
596 }
597 return selAnchorIndex;
598}; 611};
599 612
600GLSubpath.prototype.isWithinBBox =function(x,y,z){ 613GLSubpath.prototype.isWithinBBox = function(x,y,z) {
601 if (this._BBoxMin[0]>x || this._BBoxMin[1]>y || this._BBoxMin[2]>z){ 614 if (this._BBoxMin[0]>x || this._BBoxMin[1]>y || this._BBoxMin[2]>z){
602 return false; 615 return false;
603 } 616 }