From 3bb606e16a3fce172e7fa99f1da4d474519fbe9a Mon Sep 17 00:00:00 2001 From: DD Date: Fri, 22 Sep 2017 12:31:39 -0400 Subject: [PATCH] move hit options declaration into function --- src/helper/selection-tools/reshape-tool.js | 73 ++++++++++------------ 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/helper/selection-tools/reshape-tool.js b/src/helper/selection-tools/reshape-tool.js index 77b86300..424ee183 100644 --- a/src/helper/selection-tools/reshape-tool.js +++ b/src/helper/selection-tools/reshape-tool.js @@ -32,43 +32,6 @@ class ReshapeTool extends paper.Tool { this.clearHoveredItem = clearHoveredItem; this.onUpdateSvg = onUpdateSvg; this.prevHoveredItem = null; - this._hitOptionsSelected = { - match: function (item) { - if (!item.item || !item.item.selected) return; - if (item.type === 'handle-out' || item.type === 'handle-in') { - // Only hit test against handles that are visible, that is, - // their segment is selected - if (!item.segment.selected) { - return false; - } - } - return true; - }, - segments: true, - stroke: true, - curves: true, - handles: true, - fill: true, - guide: false - }; - this._hitOptions = { - match: function (item) { - if (item.type === 'handle-out' || item.type === 'handle-in') { - // Only hit test against handles that are visible, that is, - // their segment is selected - if (!item.segment.selected) { - return false; - } - } - return true; - }, - segments: true, - stroke: true, - curves: true, - handles: true, - fill: true, - guide: false - }; this.lastEvent = null; this.mode = ReshapeModes.SELECTION_BOX; this.selectionRect = null; @@ -89,9 +52,39 @@ class ReshapeTool extends paper.Tool { paper.settings.handleSize = 8; } getHitOptions (preselectedOnly) { - this._hitOptions.tolerance = ReshapeTool.TOLERANCE / paper.view.zoom; - this._hitOptionsSelected.tolerance = ReshapeTool.TOLERANCE / paper.view.zoom; - return preselectedOnly ? this._hitOptionsSelected : this._hitOptions; + const hitOptions = { + segments: true, + stroke: true, + curves: true, + handles: true, + fill: true, + guide: false + }; + if (preselectedOnly) { + hitOptions.match = item => { + if (!item.item || !item.item.selected) return; + if (item.type === 'handle-out' || item.type === 'handle-in') { + // Only hit test against handles that are visible, that is, + // their segment is selected + if (!item.segment.selected) { + return false; + } + } + return true; + }; + } else { + hitOptions.match = item => { + if (item.type === 'handle-out' || item.type === 'handle-in') { + // Only hit test against handles that are visible, that is, + // their segment is selected + if (!item.segment.selected) { + return false; + } + } + return true; + }; + } + return hitOptions; } setPrevHoveredItem (prevHoveredItem) { this.prevHoveredItem = prevHoveredItem;