mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Simplify fix for #1685
Create `Base` objects for options, so `extend()` can be used to override properties in a fast and nondestructive manner.
This commit is contained in:
parent
aec1c2c138
commit
0bb04fffff
3 changed files with 8 additions and 13 deletions
|
@ -105,7 +105,7 @@ var HitResult = Base.extend(/** @lends HitResult# */{
|
||||||
*/
|
*/
|
||||||
getOptions: function(args) {
|
getOptions: function(args) {
|
||||||
var options = args && Base.read(args);
|
var options = args && Base.read(args);
|
||||||
return Base.set({
|
return new Base({
|
||||||
// Type of item, for instanceof check: Group, Layer, Path,
|
// Type of item, for instanceof check: Group, Layer, Path,
|
||||||
// CompoundPath, Shape, Raster, SymbolItem, ...
|
// CompoundPath, Shape, Raster, SymbolItem, ...
|
||||||
type: null,
|
type: null,
|
||||||
|
|
|
@ -1818,7 +1818,7 @@ new function() { // Injection scope for various item event handlers
|
||||||
// See CompoundPath#_contains() for the reason for !!
|
// See CompoundPath#_contains() for the reason for !!
|
||||||
var matrix = this._matrix;
|
var matrix = this._matrix;
|
||||||
return (
|
return (
|
||||||
matrix.isInvertible() &&
|
matrix.isInvertible() &&
|
||||||
!!this._contains(matrix._inverseTransform(Point.read(arguments)))
|
!!this._contains(matrix._inverseTransform(Point.read(arguments)))
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -1886,7 +1886,7 @@ new function() { // Injection scope for hit-test functions shared with project
|
||||||
var point = Point.read(arguments),
|
var point = Point.read(arguments),
|
||||||
options = HitResult.getOptions(arguments),
|
options = HitResult.getOptions(arguments),
|
||||||
all = [];
|
all = [];
|
||||||
this._hitTest(point, Base.set({ all: all }, options));
|
this._hitTest(point, new Base({ all: all }, options));
|
||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,16 +121,11 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
_hitTestSelf: function(point, options, viewMatrix) {
|
_hitTestSelf: function(point, options, viewMatrix) {
|
||||||
// We need to call definition item hit test with `options.all`
|
// We need to call definition item hit test with `options.all = false`,
|
||||||
// disabled, otherwise it would populate the array with its own
|
// as otherwise it would populate the array with its own matches.
|
||||||
// matches. What we want instead is only returning one match per symbol
|
// Instead we want only returning one match per symbol-item, see #1680
|
||||||
// item (#1680). So we store original matches array...
|
var opts = options.extend({ all: false });
|
||||||
var all = options.all;
|
var res = this._definition._item._hitTest(point, opts, viewMatrix);
|
||||||
// ...we temporarily disable `options.all`...
|
|
||||||
delete options.all;
|
|
||||||
var res = this._definition._item._hitTest(point, options, viewMatrix);
|
|
||||||
// ...then after hit testing, we restore the original matches array.
|
|
||||||
options.all = all;
|
|
||||||
// TODO: When the symbol's definition is a path, should hitResult
|
// TODO: When the symbol's definition is a path, should hitResult
|
||||||
// contain information like HitResult#curve?
|
// contain information like HitResult#curve?
|
||||||
if (res)
|
if (res)
|
||||||
|
|
Loading…
Reference in a new issue