forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHitResult.js
More file actions
140 lines (130 loc) · 3.73 KB
/
Copy pathHitResult.js
File metadata and controls
140 lines (130 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, 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 A HitResult object contains information about the results of a hit
* test. It is returned by {@link Item#hitTest(point)} and
* {@link Project#hitTest(point)}.
*/
var HitResult = Base.extend(/** @lends HitResult# */{
_class: 'HitResult',
initialize: function HitResult(type, item, values) {
this.type = type;
this.item = item;
// Inject passed values, so we can be flexible about the HitResult
// properties.
// This allows the definition of getters too, e.g. for 'pixel'.
if (values) {
values.enumerable = true;
this.inject(values);
}
},
/**
* Describes the type of the hit result. For example, if you hit a segment
* point, the type would be 'segment'.
*
* @name HitResult#type
* @property
* @type String('segment', 'handle-in', 'handle-out', 'stroke', 'fill',
* 'bounds', 'center', 'pixel')
*/
/**
* If the HitResult has a {@link HitResult#type} of 'bounds', this property
* describes which corner of the bounding rectangle was hit.
*
* @name HitResult#name
* @property
* @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
* @property
* @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
* @property
* @type CurveLocation
*/
/**
* 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
* @property
* @type Color
*/
/**
* 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.
*
* @name HitResult#segment
* @property
* @type Segment
*/
/**
* Describes the actual coordinates of the segment, handle or bounding box
* corner that was hit.
*
* @name HitResult#point
* @property
* @type Point
*/
statics: {
/**
* Merges default options into options hash for #hitTest() calls, and
* marks as merged, to prevent repeated merging in nested calls.
*
* @private
*/
getOptions: function(options) {
// Use _merged property to not repeatetly call merge in recursion.
return options && options._merged ? options : Base.merge({
// Type of item, for instanceof check: PathItem, TexItem, etc
type: null,
// Tolerance
tolerance: paper.project.options.hitTolerance || 2,
// Hit the fill of items
fill: !options,
// Hit the curves of path items, taking into account the stroke
// width.
stroke: !options,
// Hit the part of segments that curves pass through, excluding
// its segments (Segment#point)
segments: !options,
// Hit the parts of segments that define the curvature
handles: false,
// Only first or last segment hits on path (mutually exclusive
// with segments: true)
ends: false,
// Hit test the center of the bounds
center: false,
// Hit test the corners and side-centers of the boudning box
bounds: false,
// 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);
}
}
});