mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-27 06:10:14 -04:00
Implement Item#controlBounds and Path#controlBounds, and test it in StrokeBounds example. This is a first step towards fast hit-testing.
This commit is contained in:
parent
ee23877fd1
commit
9fa51a0457
3 changed files with 45 additions and 7 deletions
src/path
|
@ -1894,9 +1894,37 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
|
||||
/**
|
||||
* The bounding rectangle of the item including handles.
|
||||
*
|
||||
* @type Rectangle
|
||||
* @bean
|
||||
*/
|
||||
getControlBounds: function() {
|
||||
// TODO: Implement!
|
||||
var x1 = Infinity,
|
||||
x2 = -Infinity,
|
||||
y1 = x1,
|
||||
y2 = x2;
|
||||
|
||||
function add(point, relative) {
|
||||
var x = point._x,
|
||||
y = point._y;
|
||||
if (relative) {
|
||||
x += relative._x;
|
||||
y += relative._y;
|
||||
}
|
||||
if (x < x1) x1 = x;
|
||||
if (x > x2) x2 = x;
|
||||
if (y < y1) y1 = y;
|
||||
if (y > y2) y2 = y;
|
||||
}
|
||||
|
||||
for (var i = 0, l = this._segments.length; i < l; i++) {
|
||||
var segment = this._segments[i],
|
||||
point = segment._point;
|
||||
add(point);
|
||||
add(segment._handleIn, point);
|
||||
add(segment.handleOut, point);
|
||||
}
|
||||
return Rectangle.create(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
// TODO: intersects(item)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue