mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Document HitResult, Item#hitTest(point, options) and Project#hitTest(point, options).
This commit is contained in:
parent
e73a2df6b2
commit
e0650cae73
3 changed files with 128 additions and 1 deletions
|
@ -17,7 +17,8 @@
|
|||
/**
|
||||
* @name HitResult
|
||||
*
|
||||
* @class
|
||||
* @class A HitResult object contains information about the results of a hit
|
||||
* test.
|
||||
*
|
||||
* @extends CurveLocation
|
||||
*/
|
||||
|
@ -34,6 +35,61 @@ HitResult = Base.extend(/** @lends HitResult# */{
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Describes the type of the hit result. For example, if you hit a segment
|
||||
* point, the type would be 'segment'.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#type
|
||||
* @type String('segment', 'handle-in', 'handle-out', 'stroke', 'fill',
|
||||
* 'bounds', 'center')
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the HitResult has a {@link HitResult#type} of 'bounds', this property
|
||||
* describes which corner of the bounding rectangle was hit.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#name
|
||||
* @type String('top-left', 'top-right', 'bottom-left', 'bottom-right',
|
||||
* 'left-center', 'top-center', 'right-center', 'bottom-center')
|
||||
*/
|
||||
|
||||
/**
|
||||
* The item that was hit.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#item
|
||||
* @type Item
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the HitResult has a type of 'stroke', this property gives more
|
||||
* information about the exact position that was hit on the path.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#location
|
||||
* @type CurveLocation
|
||||
*/
|
||||
|
||||
/**
|
||||
* If the HitResult has a type of 'stroke', 'segment', 'handle-in' or
|
||||
* 'handle-out', this property refers to the Segment that was hit or that
|
||||
* is closest to the hitResult.location on the curve.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#segment
|
||||
* @type Segment
|
||||
*/
|
||||
|
||||
/**
|
||||
* The hit point.
|
||||
*
|
||||
* @property
|
||||
* @name HitResult#point
|
||||
* @type Point
|
||||
*/
|
||||
|
||||
statics: {
|
||||
/**
|
||||
* Merges default options into options hash for #hitTest() calls, and
|
||||
|
|
|
@ -682,6 +682,43 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
|
|||
return raster;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* The optional options object allows you to control the specifics of the
|
||||
* hit test and may contain a combination of the following values:
|
||||
* <b>tolerance:</b> {@code Number} - The tolerance of the hit test in
|
||||
* points.
|
||||
* <b>type:</b> Only hit test again a certain item
|
||||
* type: {@link PathItem}, {@link Raster}, {@link TextItem}, etc.
|
||||
* <b>fill:</b> {@code Boolean} - Hit test the fill of items.
|
||||
* <b>stroke:</b> {@code Boolean} - Hit test the curves of path items,
|
||||
* taking into account stroke width.
|
||||
* <b>segment:</b> {@code Boolean} - Hit test for {@link Segment#point} of
|
||||
* {@link Path} items.
|
||||
* <b>handles:</b> {@code Boolean} - Hit test for the handles
|
||||
* ({@link Segment#handleIn} / {@link Segment#handleOut}) of path segments.
|
||||
* <b>ends:</b> {@code Boolean} - Only hit test for the first or last
|
||||
* segment points of open path items.
|
||||
* <b>bounds:</b> {@code Boolean} - Hit test the corners and side-centers
|
||||
* of the bounding rectangle of items ({@link Item#bounds}).
|
||||
* <b>center:</b> {@code Boolean} - Hit test the {@link Rectangle#center}
|
||||
* of the bounding rectangle of items ({@link Item#bounds}).
|
||||
* <b>guide:</b> {@code Boolean} - Hit test items that have
|
||||
* {@link Item#guide} set to {@code true}.
|
||||
* <b>selected:</b> {@code Boolean} - Only hit selected items.
|
||||
*
|
||||
* @param {Point} point The point where the hit test should be performed
|
||||
* @param {Object} [options={ fill: true, stroke: true, segments: true,
|
||||
* tolerance: 2 }]
|
||||
* @param {Matrix} [matrix]
|
||||
* @return {HitResult|null} A hit result object that contains more
|
||||
* information about what exactly was hit or {@code null} if nothing was
|
||||
* hit.
|
||||
*/
|
||||
hitTest: function(point, options, matrix) {
|
||||
options = HitResult.getOptions(point, options);
|
||||
point = options.point;
|
||||
|
|
|
@ -181,6 +181,40 @@ var Project = this.Project = Base.extend(/** @lends Project# */{
|
|||
this._selectedItems[i].setSelected(false);
|
||||
},
|
||||
|
||||
/**
|
||||
* Perform a hit test on the items contained within the project at the
|
||||
* location of the specified point.
|
||||
*
|
||||
* The optional options object allows you to control the specifics of the
|
||||
* hit test and may contain a combination of the following values:
|
||||
* <b>tolerance:</b> {@code Number} - The tolerance of the hit test in
|
||||
* points.
|
||||
* <b>type:</b> Only hit test again a certain item
|
||||
* type: {@link PathItem}, {@link Raster}, {@link TextItem}, etc.
|
||||
* <b>fill:</b> {@code Boolean} - Hit test the fill of items.
|
||||
* <b>stroke:</b> {@code Boolean} - Hit test the curves of path items,
|
||||
* taking into account stroke width.
|
||||
* <b>segment:</b> {@code Boolean} - Hit test for {@link Segment#point} of
|
||||
* {@link Path} items.
|
||||
* <b>handles:</b> {@code Boolean} - Hit test for the handles
|
||||
* ({@link Segment#handleIn} / {@link Segment#handleOut}) of path segments.
|
||||
* <b>ends:</b> {@code Boolean} - Only hit test for the first or last
|
||||
* segment points of open path items.
|
||||
* <b>bounds:</b> {@code Boolean} - Hit test the corners and side-centers
|
||||
* of the bounding rectangle of items ({@link Item#bounds}).
|
||||
* <b>center:</b> {@code Boolean} - Hit test the {@link Rectangle#center}
|
||||
* of the bounding rectangle of items ({@link Item#bounds}).
|
||||
* <b>guide:</b> {@code Boolean} - Hit test items that have
|
||||
* {@link Item#guide} set to {@code true}.
|
||||
* <b>selected:</b> {@code Boolean} - Only hit selected items.
|
||||
*
|
||||
* @param {Point} point The point where the hit test should be performed
|
||||
* @param {Object} [options={ fill: true, stroke: true, segments: true,
|
||||
* tolerance: true }]
|
||||
* @return {HitResult|null} A hit result object that contains more
|
||||
* information about what exactly was hit or {@code null} if nothing was
|
||||
* hit.
|
||||
*/
|
||||
hitTest: function(point, options) {
|
||||
options = HitResult.getOptions(point, options);
|
||||
point = options.point;
|
||||
|
|
Loading…
Reference in a new issue