mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Implement Item#intersects(item)
This commit is contained in:
parent
b3c7be67fc
commit
5ddbc5b07f
2 changed files with 34 additions and 0 deletions
|
@ -1626,6 +1626,7 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
// DOCS:
|
// DOCS:
|
||||||
|
// TEST:
|
||||||
/**
|
/**
|
||||||
* @param {Rectangle} rect the rectangle to check against
|
* @param {Rectangle} rect the rectangle to check against
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
|
@ -1634,6 +1635,23 @@ var Item = Base.extend(Emitter, /** @lends Item# */{
|
||||||
return Rectangle.read(arguments).contains(this.getBounds());
|
return Rectangle.read(arguments).contains(this.getBounds());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// DOCS:
|
||||||
|
// TEST:
|
||||||
|
/**
|
||||||
|
* @param {Item} item the item to check against
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
intersects: function(item, _matrix) {
|
||||||
|
if (!(item instanceof Item))
|
||||||
|
return false;
|
||||||
|
// Create a temporary rectangular path item with this item's bounds, and
|
||||||
|
// delegate the call to it.
|
||||||
|
return new Path.Rectangle({
|
||||||
|
rectangle: this.getInternalBounds(),
|
||||||
|
matrix: this._matrix,
|
||||||
|
insert: false,
|
||||||
|
}).intersects(item, _matrix);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Perform a hit test on the item (and its children, if it is a
|
* Perform a hit test on the item (and its children, if it is a
|
||||||
* {@link Group} or {@link Layer}) at the location of the specified point.
|
* {@link Group} or {@link Layer}) at the location of the specified point.
|
||||||
|
|
|
@ -181,6 +181,22 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
||||||
return locations;
|
return locations;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
intersects: function(item, _matrix) {
|
||||||
|
if (!(item instanceof Item))
|
||||||
|
return false;
|
||||||
|
var other = item instanceof PathItem
|
||||||
|
? item
|
||||||
|
// Create a temporary rectangular path item to check against.
|
||||||
|
: new Path.Rectangle({
|
||||||
|
rectangle: item.getInternalBounds(),
|
||||||
|
insert: false
|
||||||
|
});
|
||||||
|
// TODO: Optimize getIntersections(): We don't need all intersections
|
||||||
|
// when we're just curious about whether they intersect or not. Pass on
|
||||||
|
// an argument that let's it bail out after the first intersection.
|
||||||
|
return this.getIntersections(other, _matrix || item._matrix).length > 0;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The path's geometry, formatted as SVG style path data.
|
* The path's geometry, formatted as SVG style path data.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue