Streamline PathItem_Contains tests and add more tests.

This commit is contained in:
Jürg Lehni 2014-02-19 23:53:06 +01:00
commit f6061905be

View file

@ -12,9 +12,9 @@
module('PathItem Contains');
function testPoint(item, point, inside) {
equals(item.contains(point), inside, 'The point ' + point
+ ' should be ' + (inside ? 'inside' : 'outside') + '.');
function testPoint(item, point, inside, message) {
equals(item.contains(point), inside, message || ('The point ' + point
+ ' should be ' + (inside ? 'inside' : 'outside') + '.'));
}
test('Path#contains() (Regular Polygon)', function() {
@ -96,29 +96,35 @@ test('CompoundPath#contains() (Donut)', function() {
new Path.Circle([0, 0], 25)
]);
equals(path.contains(new Point(0, 0)), false,
testPoint(path, new Point(0, -50), true,
'The top center point of the outer circle should be inside the donut.');
testPoint(path, new Point(0, 0), false,
'The center point should be outside the donut.');
equals(path.contains(new Point(-35, 0)), true,
testPoint(path, new Point(-35, 0), true,
'A vertically centered point on the left side should be inside the donut.');
equals(path.contains(new Point(35, 0)), true,
testPoint(path, new Point(35, 0), true,
'A vertically centered point on the right side should be inside the donut.');
equals(path.contains(new Point(0, 49)), true,
testPoint(path, new Point(0, 49), true,
'The near bottom center point of the outer circle should be inside the donut.');
equals(path.contains(new Point(0, 50)), true,
testPoint(path, new Point(0, 50), true,
'The bottom center point of the outer circle should be inside the donut.');
equals(path.contains(new Point(0, 51)), false,
testPoint(path, new Point(0, 51), false,
'The near bottom center point of the outer circle should be outside the donut.');
equals(path.contains(new Point({ length: 50, angle: 30 })), true,
testPoint(path, new Point({ length: 50, angle: 30 }), true,
'A random point on the periphery of the outer circle should be inside the donut.');
equals(path.contains(new Point(0, 25)), false,
testPoint(path, new Point(0, 25), false,
'The bottom center point of the inner circle should be outside the donut.');
equals(path.contains(new Point({ length: 25, angle: 30 })), false,
testPoint(path, new Point({ length: 25, angle: 30 }), false,
'A random point on the periphery of the inner circle should be outside the donut.');
equals(path.contains(new Point(-50, -50)), false,
testPoint(path, new Point(-50, -50), false,
'The top left point of bounding box should be outside the donut.');
equals(path.contains(new Point(-50, 50)), false,
testPoint(path, new Point(50, -50), false,
'The top right point of the bounding box should be inside the donut.');
testPoint(path, new Point(-50, 50), false,
'The bottom left point of bounding box should be outside the donut.');
equals(path.contains(new Point(-45, 45)), false,
testPoint(path, new Point(50, 50), false,
'The bottom right point of the bounding box should be inside the donut.');
testPoint(path, new Point(-45, 45), false,
'The near bottom left point of bounding box should be outside the donut.');
});