mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-28 17:02:24 -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) {
|
||||
var options = args && Base.read(args);
|
||||
return Base.set({
|
||||
return new Base({
|
||||
// Type of item, for instanceof check: Group, Layer, Path,
|
||||
// CompoundPath, Shape, Raster, SymbolItem, ...
|
||||
type: null,
|
||||
|
|
|
@ -1818,7 +1818,7 @@ new function() { // Injection scope for various item event handlers
|
|||
// See CompoundPath#_contains() for the reason for !!
|
||||
var matrix = this._matrix;
|
||||
return (
|
||||
matrix.isInvertible() &&
|
||||
matrix.isInvertible() &&
|
||||
!!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),
|
||||
options = HitResult.getOptions(arguments),
|
||||
all = [];
|
||||
this._hitTest(point, Base.set({ all: all }, options));
|
||||
this._hitTest(point, new Base({ all: all }, options));
|
||||
return all;
|
||||
}
|
||||
|
||||
|
|
|
@ -121,16 +121,11 @@ var SymbolItem = Item.extend(/** @lends SymbolItem# */{
|
|||
},
|
||||
|
||||
_hitTestSelf: function(point, options, viewMatrix) {
|
||||
// We need to call definition item hit test with `options.all`
|
||||
// disabled, otherwise it would populate the array with its own
|
||||
// matches. What we want instead is only returning one match per symbol
|
||||
// item (#1680). So we store original matches array...
|
||||
var all = options.all;
|
||||
// ...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;
|
||||
// We need to call definition item hit test with `options.all = false`,
|
||||
// as otherwise it would populate the array with its own matches.
|
||||
// Instead we want only returning one match per symbol-item, see #1680
|
||||
var opts = options.extend({ all: false });
|
||||
var res = this._definition._item._hitTest(point, opts, viewMatrix);
|
||||
// TODO: When the symbol's definition is a path, should hitResult
|
||||
// contain information like HitResult#curve?
|
||||
if (res)
|
||||
|
|
Loading…
Reference in a new issue