From 673d157f31b2aad75aac6e0281e39874cd5f6980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 8 Jan 2017 15:07:40 +0100 Subject: [PATCH] Implement unit tests for #1116 Closes #1116 --- src/path/PathItem.js | 2 + test/tests/PathItem_Contains.js | 73 +++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/path/PathItem.js b/src/path/PathItem.js index ca25628b..84d7721d 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -272,6 +272,8 @@ var PathItem = Item.extend(/** @lends PathItem# */{ this.getBounds({ internal: true, handle: true })) ? this._getWinding(point) : {}; + // See #1116#issuecomment-243794824 for an explanation of the + // winding.onPath check here. return winding.onPath || !!(this.getFillRule() === 'evenodd' ? winding.windingL & 1 || winding.windingR & 1 : winding.winding); diff --git a/test/tests/PathItem_Contains.js b/test/tests/PathItem_Contains.js index 6e722ae8..30367955 100644 --- a/test/tests/PathItem_Contains.js +++ b/test/tests/PathItem_Contains.js @@ -292,8 +292,7 @@ test('Path#contains() (straight curves with zero-winding: #943)', function() { } }); -/* -test('CompoundPath#contains() (nested touching circles: #944)', function() { +test('CompoundPath#contains() (nested touching circles and other edge cases: #944)', function() { var cp = new CompoundPath({ children: [ new Path.Circle({ @@ -308,8 +307,76 @@ test('CompoundPath#contains() (nested touching circles: #944)', function() { fillRule: 'evenodd' }); testPoint(cp, new Point(100, 200), true); + + var cp = new CompoundPath({ + children: [ + new Path.Circle({ + center: [200, 200], + radius: 100 + }), + new Path.Circle({ + center: [200, 200], + radius: 100, + clockwise: false + }), + new Path.Circle({ + center: [200, 200], + radius: 100 + }), + new Path.Circle({ + center: [150, 200], + radius: 50, + clockwise: false + }) + ] + }); + testPoint(cp, new Point(100, 200), true); + + var cp = new CompoundPath({ + children: [ + new Path.Rectangle({ + point: [100, 100], + size: [200, 200] + }), + new Path.Rectangle({ + point: [100, 150], + size: [100, 100] + }) + ], + fillRule: 'evenodd' + }); + testPoint(cp, new Point(100, 200), true); + + var cp = new CompoundPath({ + children: [ + new Path.Rectangle({ + point: [100, 100], + size: [200, 200] + }), + new Path.Rectangle({ + point: [100, 100], + size: [200, 200] + }) + ], + fillRule: 'nonzero' + }); + testPoint(cp, new Point(100, 200), true); + + var cp = new CompoundPath({ + children: [ + new Path.Rectangle({ + point: [100, 100], + size: [200, 200] + }), + new Path.Rectangle({ + point: [300, 100], + size: [200, 200] + }) + ], + fillRule: 'evenodd' + }); + testPoint(cp, new Point(300, 200), true); }); -*/ test('Path#contains() with Path#interiorPoint: #854, #1064', function() { var paths = [