mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Improve code handling special winding cases.
This commit is contained in:
parent
75a209c002
commit
f8106ae18f
2 changed files with 22 additions and 4 deletions
|
@ -780,8 +780,8 @@ statics: {
|
|||
xt = y < mid ? left[0] : left[6];
|
||||
root = y < mid ? 0 : 1;
|
||||
// Filter out end points based on direction.
|
||||
if (dir < 0 && root == 0 && y == left[1] ||
|
||||
dir > 0 && root == 1 && y == left[7])
|
||||
if (dir < 0 && abs(root) < tolerance && y == left[1] ||
|
||||
dir > 0 && abs(root - 1) < tolerance && y == left[7])
|
||||
continue;
|
||||
}
|
||||
// See if we're touching a horizontal stationary point by looking at
|
||||
|
@ -797,8 +797,8 @@ statics: {
|
|||
if (x >= xt + (flat ? -tolerance : tolerance * dir)) {
|
||||
// When touching a stationary point, only count it if we're
|
||||
// actuall on it.
|
||||
if (flat && root == 0 && x != left[0]
|
||||
|| root == 1 && x != left[6])
|
||||
if (flat && (abs(root) < tolerance && x != left[0]
|
||||
|| abs(root - 1) < tolerance && x != left[6]))
|
||||
continue;
|
||||
// If this is a horizontal stationary point, and we're at the
|
||||
// end of the curve, flip the orientation of dir.
|
||||
|
|
|
@ -56,6 +56,24 @@ test('Path#contains() (Circle Contours)', function() {
|
|||
testPoint(path, path.bounds.bottomRight, false);
|
||||
});
|
||||
|
||||
test('Path#contains() (Transformed Circle Contours)', function() {
|
||||
var path = new Path.Circle({
|
||||
center: [200, 200],
|
||||
radius: 50,
|
||||
fillColor: 'blue',
|
||||
});
|
||||
path.translate(100, 100);
|
||||
|
||||
testPoint(path, path.bounds.topCenter, true);
|
||||
testPoint(path, path.bounds.leftCenter, true);
|
||||
testPoint(path, path.bounds.rightCenter, true);
|
||||
testPoint(path, path.bounds.bottomCenter, true);
|
||||
testPoint(path, path.bounds.topLeft, false);
|
||||
testPoint(path, path.bounds.topRight, false);
|
||||
testPoint(path, path.bounds.bottomLeft, false);
|
||||
testPoint(path, path.bounds.bottomRight, false);
|
||||
});
|
||||
|
||||
test('Path#contains() (Round Rectangle)', function() {
|
||||
var rectangle = new Rectangle({
|
||||
point: new Point(0, 0),
|
||||
|
|
Loading…
Reference in a new issue