2011-07-07 16:14:58 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name HitResult
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* @extends CurveLocation
|
|
|
|
*/
|
2011-07-08 16:25:42 -04:00
|
|
|
HitResult = Base.extend(/** @lends HitResult# */{
|
2011-07-08 17:26:21 -04:00
|
|
|
initialize: function(type, item, values) {
|
2011-07-08 16:25:42 -04:00
|
|
|
this.type = type;
|
|
|
|
this.item = item;
|
2011-07-08 17:26:21 -04:00
|
|
|
if (values) {
|
|
|
|
// Copy over passed values, depending on use case.
|
2011-07-08 17:32:50 -04:00
|
|
|
// DOCS: HitResult#location, #segment, #name, #point
|
2011-07-08 17:26:21 -04:00
|
|
|
Base.each(values, function(value, key) {
|
|
|
|
this[key] = value;
|
|
|
|
}, this);
|
|
|
|
}
|
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
|
|
|
|
*/
|
2011-07-08 17:25:27 -04:00
|
|
|
getOptions: function(point, options) {
|
2011-07-07 16:14:58 -04:00
|
|
|
return options && options._merged ? options : Base.merge({
|
2011-07-08 17:25:27 -04:00
|
|
|
// Use the converted options object to perform point conversion
|
|
|
|
// only once.
|
|
|
|
point: Point.read(arguments, 0, 1),
|
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
|
|
|
|
tolerance: 2,
|
2011-07-07 16:14:58 -04:00
|
|
|
// Hit the fill of items
|
|
|
|
fill: true,
|
|
|
|
// Hit the curves of path items, taking into account the stroke
|
|
|
|
// width.
|
|
|
|
stroke: true,
|
2011-07-08 16:25:42 -04:00
|
|
|
// Hit the part of segments that curves pass through, excluding
|
|
|
|
// its segments (Segment#point)
|
2011-07-07 16:14:58 -04:00
|
|
|
segments: true,
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|