From f8106ae18f84c52f8568a4c3ef109b20de307de1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 18 Oct 2013 15:20:32 +0200 Subject: [PATCH] Improve code handling special winding cases. --- src/path/Curve.js | 8 ++++---- test/tests/Item_Contains.js | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 697a4775..19291bc9 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -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. diff --git a/test/tests/Item_Contains.js b/test/tests/Item_Contains.js index 115f872b..c26d20cb 100644 --- a/test/tests/Item_Contains.js +++ b/test/tests/Item_Contains.js @@ -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),