diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/lib/geom/sub-path.js | 51 | ||||
-rwxr-xr-x | js/tools/PenTool.js | 11 |
2 files changed, 38 insertions, 24 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 | ||
570 | GLSubpath.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 | |||
570 | GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { | 588 | GLSubpath.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 | ||
600 | GLSubpath.prototype.isWithinBBox =function(x,y,z){ | 613 | GLSubpath.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 | } |
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 779b7f16..39a1b15a 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -348,16 +348,17 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
348 | 348 | ||
349 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); | 349 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); |
350 | if (currMousePos && this._selectedSubpath ){ | 350 | if (currMousePos && this._selectedSubpath ){ |
351 | var selAnchor = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); | 351 | var selAnchorRetCode = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); |
352 | if (selAnchor >=0) { | 352 | if (selAnchorRetCode[0] >=0) { |
353 | this._hoveredAnchorIndex = selAnchor; | 353 | this._hoveredAnchorIndex = selAnchorRetCode[0]; |
354 | var cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 0 0, default"; | ||
355 | this.application.ninja.stage.drawingCanvas.style.cursor = cursor; | ||
354 | } else { | 356 | } else { |
355 | //detect if the current mouse position will hit the path | 357 | //detect if the current mouse position will hit the path |
356 | var pathHitTestData = this._selectedSubpath.pathHitTest(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); | 358 | var pathHitTestData = this._selectedSubpath.pathHitTest(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); |
357 | if (pathHitTestData[0]!==-1){ | 359 | if (pathHitTestData[0]!==-1){ |
358 | //change the cursor | 360 | //change the cursor |
359 | var cursor = "url('images/cursors/penAdd.png') 10 10,default"; | 361 | |
360 | this.application.ninja.stage.drawingCanvas.style.cursor = cursor; | ||
361 | } | 362 | } |
362 | } | 363 | } |
363 | } | 364 | } |