2011-07-07 16:14:58 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-07 16:14:58 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2011-07-07 16:14:58 -04:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name HitResult
|
|
|
|
*
|
2011-07-31 16:58:51 -04:00
|
|
|
* @class A HitResult object contains information about the results of a hit
|
2011-08-01 06:47:08 -04:00
|
|
|
* test. It is returned by {@link Item#hitTest(point)} and
|
|
|
|
* {@link Project#hitTest(point)}.
|
2011-07-07 16:14:58 -04:00
|
|
|
*/
|
2013-05-27 15:48:58 -04:00
|
|
|
var HitResult = Base.extend(/** @lends HitResult# */{
|
2013-06-23 23:18:32 -04:00
|
|
|
_class: 'HitResult',
|
|
|
|
|
2013-05-27 15:48:58 -04:00
|
|
|
initialize: function HitResult(type, item, values) {
|
2011-07-08 16:25:42 -04:00
|
|
|
this.type = type;
|
|
|
|
this.item = item;
|
2011-11-11 07:11:10 -05:00
|
|
|
// Inject passed values, so we can be flexible about the HitResult
|
|
|
|
// properties.
|
|
|
|
// This allows the definition of getters too, e.g. for 'pixel'.
|
2012-09-30 17:07:27 -04:00
|
|
|
if (values) {
|
|
|
|
values.enumerable = true;
|
2011-11-11 07:11:10 -05:00
|
|
|
this.inject(values);
|
2012-09-30 17:07:27 -04:00
|
|
|
}
|
2011-07-07 16:14:58 -04:00
|
|
|
},
|
|
|
|
|
2011-07-31 16:58:51 -04:00
|
|
|
/**
|
|
|
|
* Describes the type of the hit result. For example, if you hit a segment
|
|
|
|
* point, the type would be 'segment'.
|
|
|
|
*
|
|
|
|
* @name HitResult#type
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @type String('segment', 'handle-in', 'handle-out', 'stroke', 'fill',
|
2011-11-11 09:00:53 -05:00
|
|
|
* 'bounds', 'center', 'pixel')
|
2011-07-31 16:58:51 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the HitResult has a {@link HitResult#type} of 'bounds', this property
|
|
|
|
* describes which corner of the bounding rectangle was hit.
|
|
|
|
*
|
|
|
|
* @name HitResult#name
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @type String('top-left', 'top-right', 'bottom-left', 'bottom-right',
|
|
|
|
* 'left-center', 'top-center', 'right-center', 'bottom-center')
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The item that was hit.
|
|
|
|
*
|
|
|
|
* @name HitResult#item
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @name HitResult#location
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @type CurveLocation
|
|
|
|
*/
|
|
|
|
|
2011-11-11 09:00:53 -05:00
|
|
|
/**
|
|
|
|
* If the HitResult has a type of 'pixel', this property refers to the color
|
|
|
|
* of the pixel on the {@link Raster} that was hit.
|
|
|
|
*
|
|
|
|
* @name HitResult#color
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2013-04-08 03:11:43 -04:00
|
|
|
* @type Color
|
2011-11-11 09:00:53 -05:00
|
|
|
*/
|
|
|
|
|
2011-07-31 16:58:51 -04:00
|
|
|
/**
|
|
|
|
* If the HitResult has a type of 'stroke', 'segment', 'handle-in' or
|
2013-10-16 08:20:13 -04:00
|
|
|
* 'handle-out', this property refers to the segment that was hit or that
|
2011-07-31 16:58:51 -04:00
|
|
|
* is closest to the hitResult.location on the curve.
|
|
|
|
*
|
|
|
|
* @name HitResult#segment
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @type Segment
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-11-11 08:47:03 -05:00
|
|
|
* Describes the actual coordinates of the segment, handle or bounding box
|
|
|
|
* corner that was hit.
|
2011-07-31 16:58:51 -04:00
|
|
|
*
|
|
|
|
* @name HitResult#point
|
2011-11-12 07:27:29 -05:00
|
|
|
* @property
|
2011-07-31 16:58:51 -04:00
|
|
|
* @type Point
|
|
|
|
*/
|
|
|
|
|
2011-07-07 16:14:58 -04:00
|
|
|
statics: {
|
|
|
|
/**
|
|
|
|
* Merges default options into options hash for #hitTest() calls, and
|
|
|
|
* marks as merged, to prevent repeated merging in nested calls.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
*/
|
2012-11-23 15:41:00 -05:00
|
|
|
getOptions: function(options) {
|
2012-10-18 17:24:15 -04:00
|
|
|
// Use _merged property to not repeatetly call merge in recursion.
|
2011-07-07 16:14:58 -04:00
|
|
|
return options && options._merged ? options : Base.merge({
|
2011-07-08 16:25:42 -04:00
|
|
|
// Type of item, for instanceof check: PathItem, TexItem, etc
|
2011-07-09 03:28:36 -04:00
|
|
|
type: null,
|
2011-07-08 16:25:42 -04:00
|
|
|
// Tolerance
|
2013-03-01 23:25:46 -05:00
|
|
|
tolerance: paper.project.options.hitTolerance || 2,
|
2011-07-07 16:14:58 -04:00
|
|
|
// Hit the fill of items
|
2011-07-15 08:52:38 -04:00
|
|
|
fill: !options,
|
2011-07-07 16:14:58 -04:00
|
|
|
// Hit the curves of path items, taking into account the stroke
|
|
|
|
// width.
|
2011-07-15 08:52:38 -04:00
|
|
|
stroke: !options,
|
2011-07-08 16:25:42 -04:00
|
|
|
// Hit the part of segments that curves pass through, excluding
|
|
|
|
// its segments (Segment#point)
|
2011-07-15 08:52:38 -04:00
|
|
|
segments: !options,
|
2011-07-08 16:25:42 -04:00
|
|
|
// Hit the parts of segments that define the curvature
|
2011-07-08 17:26:21 -04:00
|
|
|
handles: false,
|
2011-07-07 16:14:58 -04:00
|
|
|
// Only first or last segment hits on path (mutually exclusive
|
|
|
|
// with segments: true)
|
|
|
|
ends: false,
|
2011-07-08 16:25:42 -04:00
|
|
|
// Hit test the center of the bounds
|
|
|
|
center: false,
|
|
|
|
// Hit test the corners and side-centers of the boudning box
|
|
|
|
bounds: false,
|
2011-07-07 16:14:58 -04:00
|
|
|
// Hit items that are marked as guides
|
|
|
|
guides: false,
|
|
|
|
// Only hit selected objects
|
|
|
|
selected: false,
|
|
|
|
// Mark as merged, so next time Base.merge isn't called
|
|
|
|
_merged: true
|
|
|
|
}, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|