mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement unit tests for getWinding() and zero-winding curves.
Closes #819
This commit is contained in:
parent
85f08825d7
commit
9d4066da1c
2 changed files with 75 additions and 9 deletions
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
module('HitResult');
|
module('HitResult');
|
||||||
|
|
||||||
test('hit-testing options', function() {
|
test('Hit-testing options', function() {
|
||||||
var defaultOptions = {
|
var defaultOptions = {
|
||||||
type: null,
|
type: null,
|
||||||
tolerance: paper.settings.hitTolerance,
|
tolerance: paper.settings.hitTolerance,
|
||||||
|
@ -296,7 +296,7 @@ test('hit-testing stroke on segment point of a path', function() {
|
||||||
equals(error == null, true, description);
|
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]);
|
var path = new Path.Rectangle([0, 0], [100, 100]);
|
||||||
// A point whose x value is extremely close to 0:
|
// A point whose x value is extremely close to 0:
|
||||||
var point = new Point(2.842 / Math.pow(10, 14), 0);
|
var point = new Point(2.842 / Math.pow(10, 14), 0);
|
||||||
|
@ -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';
|
paper.project.currentStyle.fillColor = 'black';
|
||||||
var point1 = new Point(100, 100);
|
var point1 = new Point(100, 100);
|
||||||
var point2 = new Point(140, 100);
|
var point2 = new Point(140, 100);
|
||||||
|
@ -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.');
|
}, 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 point = new Point(100, 100);
|
||||||
|
|
||||||
var path = new Path.Circle([0, 0], 20);
|
var path = new Path.Circle([0, 0], 20);
|
||||||
|
@ -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({
|
var rect = new Path.Rectangle({
|
||||||
rectangle: [100, 100, 300, 200],
|
rectangle: [100, 100, 300, 200],
|
||||||
fillColor: '#f00',
|
fillColor: '#f00',
|
||||||
|
@ -583,7 +583,7 @@ test('Hit testing the corner of a rectangle with miter stroke.', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Hit testing invisible items.', function() {
|
test('hit-testing invisible items.', function() {
|
||||||
var point = new Point(0, 0);
|
var point = new Point(0, 0);
|
||||||
var circle1 = new Path.Circle({
|
var circle1 = new Path.Circle({
|
||||||
center: point.subtract([25, 0]),
|
center: point.subtract([25, 0]),
|
||||||
|
@ -607,7 +607,7 @@ test('Hit testing invisible items.', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Hit testing guides.', function() {
|
test('hit-testing guides.', function() {
|
||||||
var point = new Point(0, 0);
|
var point = new Point(0, 0);
|
||||||
var circle1 = new Path.Circle({
|
var circle1 = new Path.Circle({
|
||||||
center: point.subtract([25, 0]),
|
center: point.subtract([25, 0]),
|
||||||
|
@ -641,7 +641,7 @@ test('Hit testing guides.', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Hit testing fill with tolerance', function() {
|
test('hit-testing fill with tolerance', function() {
|
||||||
var path = new Path.Rectangle({
|
var path = new Path.Rectangle({
|
||||||
from: [50, 50],
|
from: [50, 50],
|
||||||
to: [200, 200],
|
to: [200, 200],
|
||||||
|
@ -658,7 +658,7 @@ test('Hit testing fill with tolerance', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Hit testing compound-paths', function() {
|
test('hit-testing compound-paths', function() {
|
||||||
var center = new Point(100, 100);
|
var center = new Point(100, 100);
|
||||||
var path1 = new Path.Circle({
|
var path1 = new Path.Circle({
|
||||||
center: center,
|
center: center,
|
||||||
|
|
|
@ -214,3 +214,69 @@ test('Path#contains() (complex shape)', function() {
|
||||||
testPoint(path, new Point(431, 104), false);
|
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]);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in a new issue