mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05: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
|
@ -23,7 +23,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var path = makePath();
|
var path = makePath();
|
||||||
path.fullySelected = true;
|
|
||||||
path.strokeColor = 'black';
|
path.strokeColor = 'black';
|
||||||
path.strokeCap = 'butt';
|
path.strokeCap = 'butt';
|
||||||
path.strokeJoin = 'round';
|
path.strokeJoin = 'round';
|
||||||
|
@ -70,6 +69,7 @@
|
||||||
|
|
||||||
for (var i = 0; i < paths.length; i++) {
|
for (var i = 0; i < paths.length; i++) {
|
||||||
var path = paths[i];
|
var path = paths[i];
|
||||||
|
path.fullySelected = true;
|
||||||
path.scale(1.5, new Point(300, 0));
|
path.scale(1.5, new Point(300, 0));
|
||||||
var rect = new Path.Rectangle(path.strokeBounds);
|
var rect = new Path.Rectangle(path.strokeBounds);
|
||||||
rect.strokeWidth = 0.25;
|
rect.strokeWidth = 0.25;
|
||||||
|
@ -79,6 +79,11 @@
|
||||||
rect.strokeWidth = 0.25;
|
rect.strokeWidth = 0.25;
|
||||||
rect.strokeColor = 'red';
|
rect.strokeColor = 'red';
|
||||||
rect.fillColor = null;
|
rect.fillColor = null;
|
||||||
|
console.log(path.controlBounds);
|
||||||
|
var rect = new Path.Rectangle(path.controlBounds);
|
||||||
|
rect.strokeWidth = 0.25;
|
||||||
|
rect.strokeColor = 'green';
|
||||||
|
rect.fillColor = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
project.activeLayer.position = view.center;
|
project.activeLayer.position = view.center;
|
||||||
|
|
|
@ -1077,6 +1077,16 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
|
||||||
return this._getBounds('getStrokeBounds');
|
return this._getBounds('getStrokeBounds');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The bounding rectangle of the item including handles.
|
||||||
|
*
|
||||||
|
* @type Rectangle
|
||||||
|
* @bean
|
||||||
|
*/
|
||||||
|
getControlBounds: function() {
|
||||||
|
return this._getBounds('getControlBounds');
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loops through all children, gets their bounds and finds the bounds around
|
* Loops through all children, gets their bounds and finds the bounds around
|
||||||
* all of them.
|
* all of them.
|
||||||
|
@ -1113,11 +1123,6 @@ var Item = this.Item = Base.extend(/** @lends Item# */{
|
||||||
rect.x, rect.y, rect.width, rect.height);
|
rect.x, rect.y, rect.width, rect.height);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* The bounding rectangle of the item including stroke width and controls.
|
|
||||||
*/
|
|
||||||
// TODO: getControlBounds
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@grouptitle Stroke Style}
|
* {@grouptitle Stroke Style}
|
||||||
*
|
*
|
||||||
|
|
|
@ -1894,9 +1894,37 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bounding rectangle of the item including handles.
|
* The bounding rectangle of the item including handles.
|
||||||
|
*
|
||||||
|
* @type Rectangle
|
||||||
|
* @bean
|
||||||
*/
|
*/
|
||||||
getControlBounds: function() {
|
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)
|
// TODO: intersects(item)
|
||||||
|
|
Loading…
Reference in a new issue