Skip to content

Commit

Permalink
Implement unit tests for getWinding() and zero-winding curves.
Browse files Browse the repository at this point in the history
Closes #819
  • Loading branch information
lehni committed Dec 30, 2015
1 parent 85f0882 commit 9d4066d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/tests/HitResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

module('HitResult');

test('hit-testing options', function() {
test('Hit-testing options', function() {
var defaultOptions = {
type: null,
tolerance: paper.settings.hitTolerance,
Expand Down Expand Up @@ -296,7 +296,7 @@ test('hit-testing stroke on segment point of a path', function() {
equals(error == null, true, description);
});

test('Hit testing a point that is extremely close to a curve', function() {
test('hit-testing a point that is extremely close to a curve', function() {
var path = new Path.Rectangle([0, 0], [100, 100]);
// A point whose x value is extremely close to 0:
var point = new Point(2.842 / Math.pow(10, 14), 0);
Expand Down Expand Up @@ -492,7 +492,7 @@ test('hitting path with a text item in the project', function() {

});

test('Check hit-testing of items that come after a transformed group.', function() {
test('hit-testing of items that come after a transformed group.', function() {
paper.project.currentStyle.fillColor = 'black';
var point1 = new Point(100, 100);
var point2 = new Point(140, 100);
Expand Down Expand Up @@ -556,7 +556,7 @@ test('Check hit-testing of items that come after a transformed group.', function
}, path1, 'After moving group before path1, hit-testing path1 for point1 should give us path1.');
});

test('Check hit-testing of placed symbols.', function() {
test('hit-testing of placed symbols.', function() {
var point = new Point(100, 100);

var path = new Path.Circle([0, 0], 20);
Expand All @@ -570,7 +570,7 @@ test('Check hit-testing of placed symbols.', function() {

});

test('Hit testing the corner of a rectangle with miter stroke.', function() {
test('hit-testing the corner of a rectangle with miter stroke.', function() {
var rect = new Path.Rectangle({
rectangle: [100, 100, 300, 200],
fillColor: '#f00',
Expand All @@ -583,7 +583,7 @@ test('Hit testing the corner of a rectangle with miter stroke.', function() {
}, true);
});

test('Hit testing invisible items.', function() {
test('hit-testing invisible items.', function() {
var point = new Point(0, 0);
var circle1 = new Path.Circle({
center: point.subtract([25, 0]),
Expand All @@ -607,7 +607,7 @@ test('Hit testing invisible items.', function() {
}, true);
});

test('Hit testing guides.', function() {
test('hit-testing guides.', function() {
var point = new Point(0, 0);
var circle1 = new Path.Circle({
center: point.subtract([25, 0]),
Expand Down Expand Up @@ -641,7 +641,7 @@ test('Hit testing guides.', function() {
}, true);
});

test('Hit testing fill with tolerance', function() {
test('hit-testing fill with tolerance', function() {
var path = new Path.Rectangle({
from: [50, 50],
to: [200, 200],
Expand All @@ -658,7 +658,7 @@ test('Hit testing fill with tolerance', function() {
}, true);
});

test('Hit testing compound-paths', function() {
test('hit-testing compound-paths', function() {
var center = new Point(100, 100);
var path1 = new Path.Circle({
center: center,
Expand Down
66 changes: 66 additions & 0 deletions test/tests/PathItem_Contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,69 @@ test('Path#contains() (complex shape)', function() {
testPoint(path, new Point(431, 104), false);
});


test('Path#contains() (straight curves with zero-winding)', function() {
var pathPoints = [
[140, 100],
[140, 10],
[100, 10],
[100, 20],
[120, 20],
[120, 40],
[100, 40],
[100, 60],
[200, 60],
[120, 60],
[120, 100],
[300, 100],
[50, 100]
];

var path1 = new Path({
segments: pathPoints,
closed: true,
fillRule: 'evenodd'
});

var hitPoints = [
[[30,10], false],
[[110,10], true],
[[30,20], false],
[[110,20], true],
[[130,20], true],
[[170,20], false],
[[110,50], true],
[[30,60], false],
[[110,60], true],
[[130,60], true],
[[150,60], false],
[[230,60], false],
[[10,100], false],
[[60,100], false],
[[130,100], true],
[[170,100], false],
[[370,100], false]
];

for (var i = 0; i < hitPoints.length; i++) {
var entry = hitPoints[i];
testPoint(path1, new Point(entry[0]), entry[1]);
}

// Now test the x-y-reversed shape

for (var i = 0; i < pathPoints.length; i++) {
pathPoints[i].reverse();
}

var path1 = new Path({
segments: pathPoints,
closed: true,
fillRule: 'evenodd'
});

for (var i = 0; i < hitPoints.length; i++) {
var entry = hitPoints[i];
testPoint(path1, new Point(entry[0].reverse()), entry[1]);
}
})

0 comments on commit 9d4066d

Please sign in to comment.