diff --git a/src/item/Shape.js b/src/item/Shape.js index 7faaad3a..16041d66 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -68,7 +68,13 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{ contains: function(point) { point = Point.read(arguments); - // TODO: Implement. + switch (this._type) { + case 'rect': + return this.base(point); + case 'circle': + case 'ellipse': + return point.divide(this._size).getLength() <= 0.5; + } }, _getBounds: function(getter, matrix) { diff --git a/test/tests/Color.js b/test/tests/Color.js index ae166f69..05ede856 100644 --- a/test/tests/Color.js +++ b/test/tests/Color.js @@ -123,7 +123,6 @@ test('Gray Color', function() { compareNumbers(color.blue, 1, 'color.blue'); color.red = 0.5; - console.log(color + ''); compareNumbers(color.gray, 0.85045, 'color.gray'); color.green = 0.2; diff --git a/test/tests/Path_Contains.js b/test/tests/Item_Contains.js similarity index 85% rename from test/tests/Path_Contains.js rename to test/tests/Item_Contains.js index cd8a8f68..8e9febbb 100644 --- a/test/tests/Path_Contains.js +++ b/test/tests/Item_Contains.js @@ -10,10 +10,10 @@ * All rights reserved. */ -module('Path Contains'); +module('Item Contains'); -function testPoint(path, point, inside) { - equals(path.contains(point), inside, 'The point ' + point +function testPoint(item, point, inside) { + equals(item.contains(point), inside, 'The point ' + point + ' should be ' + (inside ? 'inside' : 'outside') + '.'); } @@ -70,3 +70,13 @@ test('CompoundPath#contains (Donut)', function() { equals(path.contains(new Point(-45, 45)), false, 'The near bottom left point of bounding box should be outside the donut.'); }); + +test('Shape#contains', function() { + var shape = new Shape.Circle([0, 0], 100); + + testPoint(shape, new Point(0, 0), true); + testPoint(shape, new Point(0, -100), true); + testPoint(shape, new Point({ length: 99, angle: 45 }), true); + testPoint(shape, new Point({ length: 100, angle: 45 }), true); + testPoint(shape, new Point({ length: 101, angle: 45 }), false); +}); \ No newline at end of file diff --git a/test/tests/load.js b/test/tests/load.js index aae21f43..ad481e46 100644 --- a/test/tests/load.js +++ b/test/tests/load.js @@ -23,6 +23,7 @@ /*#*/ include('Item_Cloning.js'); /*#*/ include('Item_Order.js'); /*#*/ include('Item_Bounds.js'); +/*#*/ include('Item_Contains.js'); /*#*/ include('Layer.js'); /*#*/ include('Group.js'); @@ -35,7 +36,6 @@ /*#*/ include('Path_Curves.js'); /*#*/ include('Path_Bounds.js'); /*#*/ include('Path_Length.js'); -/*#*/ include('Path_Contains.js'); /*#*/ include('CompoundPath.js'); /*#*/ include('PlacedSymbol.js');