mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement Shape#contains() and define unit tests for it.
This commit is contained in:
parent
2793709935
commit
4b24690207
4 changed files with 21 additions and 6 deletions
|
@ -68,7 +68,13 @@ var Shape = this.Shape = Item.extend(/** @lends Shape# */{
|
||||||
|
|
||||||
contains: function(point) {
|
contains: function(point) {
|
||||||
point = Point.read(arguments);
|
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) {
|
_getBounds: function(getter, matrix) {
|
||||||
|
|
|
@ -123,7 +123,6 @@ test('Gray Color', function() {
|
||||||
compareNumbers(color.blue, 1, 'color.blue');
|
compareNumbers(color.blue, 1, 'color.blue');
|
||||||
|
|
||||||
color.red = 0.5;
|
color.red = 0.5;
|
||||||
console.log(color + '');
|
|
||||||
compareNumbers(color.gray, 0.85045, 'color.gray');
|
compareNumbers(color.gray, 0.85045, 'color.gray');
|
||||||
|
|
||||||
color.green = 0.2;
|
color.green = 0.2;
|
||||||
|
|
|
@ -10,10 +10,10 @@
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module('Path Contains');
|
module('Item Contains');
|
||||||
|
|
||||||
function testPoint(path, point, inside) {
|
function testPoint(item, point, inside) {
|
||||||
equals(path.contains(point), inside, 'The point ' + point
|
equals(item.contains(point), inside, 'The point ' + point
|
||||||
+ ' should be ' + (inside ? 'inside' : 'outside') + '.');
|
+ ' should be ' + (inside ? 'inside' : 'outside') + '.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,3 +70,13 @@ test('CompoundPath#contains (Donut)', function() {
|
||||||
equals(path.contains(new Point(-45, 45)), false,
|
equals(path.contains(new Point(-45, 45)), false,
|
||||||
'The near bottom left point of bounding box should be outside the donut.');
|
'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);
|
||||||
|
});
|
|
@ -23,6 +23,7 @@
|
||||||
/*#*/ include('Item_Cloning.js');
|
/*#*/ include('Item_Cloning.js');
|
||||||
/*#*/ include('Item_Order.js');
|
/*#*/ include('Item_Order.js');
|
||||||
/*#*/ include('Item_Bounds.js');
|
/*#*/ include('Item_Bounds.js');
|
||||||
|
/*#*/ include('Item_Contains.js');
|
||||||
|
|
||||||
/*#*/ include('Layer.js');
|
/*#*/ include('Layer.js');
|
||||||
/*#*/ include('Group.js');
|
/*#*/ include('Group.js');
|
||||||
|
@ -35,7 +36,6 @@
|
||||||
/*#*/ include('Path_Curves.js');
|
/*#*/ include('Path_Curves.js');
|
||||||
/*#*/ include('Path_Bounds.js');
|
/*#*/ include('Path_Bounds.js');
|
||||||
/*#*/ include('Path_Length.js');
|
/*#*/ include('Path_Length.js');
|
||||||
/*#*/ include('Path_Contains.js');
|
|
||||||
/*#*/ include('CompoundPath.js');
|
/*#*/ include('CompoundPath.js');
|
||||||
|
|
||||||
/*#*/ include('PlacedSymbol.js');
|
/*#*/ include('PlacedSymbol.js');
|
||||||
|
|
Loading…
Reference in a new issue