mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
more unit tests working, more refactoring
This commit is contained in:
parent
86686eb590
commit
a57d6c6106
@ -218,19 +218,18 @@
|
|||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
* @param {Object} pos
|
* @param {Object} pos
|
||||||
|
* @param {Number} pos.x
|
||||||
|
* @param {Number} pos.y
|
||||||
|
* @returns {Array} array of shapes
|
||||||
*/
|
*/
|
||||||
getAllIntersections: function() {
|
getAllIntersections: function(pos) {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
|
|
||||||
var arr = [];
|
var arr = [];
|
||||||
var shapes = this.find('Shape');
|
|
||||||
|
|
||||||
var len = shapes.length;
|
this.find('Shape').each(function(shape) {
|
||||||
for(var n = 0; n < len; n++) {
|
|
||||||
var shape = shapes[n];
|
|
||||||
if(shape.isVisible() && shape.intersects(pos)) {
|
if(shape.isVisible() && shape.intersects(pos)) {
|
||||||
arr.push(shape);
|
arr.push(shape);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
},
|
},
|
||||||
@ -297,19 +296,16 @@
|
|||||||
Kinetic.Container.prototype.get = Kinetic.Container.prototype.find;
|
Kinetic.Container.prototype.get = Kinetic.Container.prototype.find;
|
||||||
|
|
||||||
// add getters setters
|
// add getters setters
|
||||||
Kinetic.Factory.addBoxGetterSetter(Kinetic.Container, 'clip');
|
Kinetic.Factory.addGetterSetter(Kinetic.Container, 'clip');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set clip
|
* set clip
|
||||||
* @method
|
* @method
|
||||||
* @name setClip
|
* @name setClip
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
* @param {Object|Array}
|
* @param {Object} clip {x:x, y:y, width:width, height:height}
|
||||||
* @example
|
* @example
|
||||||
* // set clip x, y, width and height with an array<br>
|
* // set clip x, y, width and height<br>
|
||||||
* image.setClip([20, 20, 100, 100]);<br><br>
|
|
||||||
*
|
|
||||||
* // set clip x, y, width and height with an object<br>
|
|
||||||
* image.setClip({<br>
|
* image.setClip({<br>
|
||||||
* x: 20,<br>
|
* x: 20,<br>
|
||||||
* y: 20,<br>
|
* y: 20,<br>
|
||||||
@ -318,44 +314,21 @@
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* set clipX
|
|
||||||
* @method
|
|
||||||
* @name setClipX
|
|
||||||
* @memberof Kinetic.Container.prototype
|
|
||||||
* @param {Number} x
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set clipY
|
|
||||||
* @name setClipY
|
|
||||||
* @method
|
|
||||||
* @memberof Kinetic.Container.prototype
|
|
||||||
* @param {Number} y
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set clipWidth
|
|
||||||
* @name setClipWidth
|
|
||||||
* @method
|
|
||||||
* @memberof Kinetic.Container.prototype
|
|
||||||
* @param {Number} width
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set clipHeight
|
|
||||||
* @name setClipHeight
|
|
||||||
* @method
|
|
||||||
* @memberof Kinetic.Container.prototype
|
|
||||||
* @param {Number} height
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get clip
|
* get clip
|
||||||
* @name getClip
|
* @name getClip
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
* @return {Object}
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'x', 0);
|
||||||
|
/**
|
||||||
|
* set clip x
|
||||||
|
* @method
|
||||||
|
* @name setClipX
|
||||||
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @param {Number} x
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -363,6 +336,16 @@
|
|||||||
* @name getClipX
|
* @name getClipX
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'y', 0);
|
||||||
|
/**
|
||||||
|
* set clip y
|
||||||
|
* @name setClipY
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @param {Number} y
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -370,6 +353,16 @@
|
|||||||
* @name getClipY
|
* @name getClipY
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'width', 0);
|
||||||
|
/**
|
||||||
|
* set clip width
|
||||||
|
* @name setClipWidth
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @param {Number} width
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,6 +370,16 @@
|
|||||||
* @name getClipWidth
|
* @name getClipWidth
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @returns {Number}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'height', 0);
|
||||||
|
/**
|
||||||
|
* set clip height
|
||||||
|
* @name setClipHeight
|
||||||
|
* @method
|
||||||
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @param {Number} height
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,6 +387,6 @@
|
|||||||
* @name getClipHeight
|
* @name getClipHeight
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Container.prototype
|
* @memberof Kinetic.Container.prototype
|
||||||
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -226,8 +226,8 @@
|
|||||||
this.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
this.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||||
},
|
},
|
||||||
_clip: function(container) {
|
_clip: function(container) {
|
||||||
var clipX = container.getClipX() || 0,
|
var clipX = container.getClipX(),
|
||||||
clipY = container.getClipY() || 0,
|
clipY = container.getClipY(),
|
||||||
clipWidth = container.getClipWidth(),
|
clipWidth = container.getClipWidth(),
|
||||||
clipHeight = container.getClipHeight();
|
clipHeight = container.getClipHeight();
|
||||||
|
|
||||||
|
10
src/Layer.js
10
src/Layer.js
@ -44,11 +44,13 @@
|
|||||||
* method for determining if a point intersects a shape or not
|
* method for determining if a point intersects a shape or not
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Layer.prototype
|
* @memberof Kinetic.Layer.prototype
|
||||||
* @param {Kinetic.Shape|null} shape
|
* @param {Object} pos
|
||||||
|
* @param {Number} pos.x
|
||||||
|
* @param {Number} pos.y
|
||||||
|
* @returns {Kinetic.Shape}
|
||||||
*/
|
*/
|
||||||
getIntersection: function() {
|
getIntersection: function(pos) {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
var obj, i, intersectionOffset, shape;
|
||||||
obj, i, intersectionOffset, shape;
|
|
||||||
|
|
||||||
if(this.isVisible()) {
|
if(this.isVisible()) {
|
||||||
for (i=0; i<INTERSECTION_OFFSETS_LEN; i++) {
|
for (i=0; i<INTERSECTION_OFFSETS_LEN; i++) {
|
||||||
|
@ -633,7 +633,7 @@
|
|||||||
y += changeY;
|
y += changeY;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setPosition(x, y);
|
this.setPosition({x:x, y:y});
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
_eachAncestorReverse: function(func, includeSelf) {
|
_eachAncestorReverse: function(func, includeSelf) {
|
||||||
|
13
src/Shape.js
13
src/Shape.js
@ -106,14 +106,13 @@
|
|||||||
* because it performs much better
|
* because it performs much better
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Shape.prototype
|
* @memberof Kinetic.Shape.prototype
|
||||||
* @param {Object} point point can be an object containing
|
* @param {Object} point
|
||||||
* an x and y property, or it can be an array with two elements
|
* @param {Number} point.x
|
||||||
* in which the first element is the x component and the second
|
* @param {Number} point.y
|
||||||
* element is the y component
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
intersects: function() {
|
intersects: function(pos) {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
var stage = this.getStage(),
|
||||||
stage = this.getStage(),
|
|
||||||
bufferHitCanvas = stage.bufferHitCanvas,
|
bufferHitCanvas = stage.bufferHitCanvas,
|
||||||
p;
|
p;
|
||||||
|
|
||||||
|
10
src/Stage.js
10
src/Stage.js
@ -254,11 +254,13 @@
|
|||||||
* method for determining if a point intersects a shape or not
|
* method for determining if a point intersects a shape or not
|
||||||
* @method
|
* @method
|
||||||
* @memberof Kinetic.Stage.prototype
|
* @memberof Kinetic.Stage.prototype
|
||||||
* @param {Kinetic.Shape} shape
|
* @param {Object} pos
|
||||||
|
* @param {Number} pos.x
|
||||||
|
* @param {Number} pos.y
|
||||||
|
* @returns {Kinetic.Shape}
|
||||||
*/
|
*/
|
||||||
getIntersection: function() {
|
getIntersection: function(pos) {
|
||||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
var layers = this.getChildren(),
|
||||||
layers = this.getChildren(),
|
|
||||||
len = layers.length,
|
len = layers.length,
|
||||||
end = len - 1,
|
end = len - 1,
|
||||||
n, shape;
|
n, shape;
|
||||||
|
@ -4,7 +4,7 @@ suite('Container', function() {
|
|||||||
test('clip', function() {
|
test('clip', function() {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Kinetic.Layer({
|
var layer = new Kinetic.Layer({
|
||||||
clip: [0, 0, stage.getWidth() / 2, 100]
|
clip: {x:0, y:0, width:stage.getWidth() / 2, height:100}
|
||||||
});
|
});
|
||||||
var group = new Kinetic.Group();
|
var group = new Kinetic.Group();
|
||||||
var circle = new Kinetic.Circle({
|
var circle = new Kinetic.Circle({
|
||||||
|
@ -68,7 +68,7 @@ suite('Node', function() {
|
|||||||
|
|
||||||
assert.equal(circle.getFill(), 'red');
|
assert.equal(circle.getFill(), 'red');
|
||||||
|
|
||||||
circle.setAttr('position', 5, 6);
|
circle.setAttr('position', {x: 5, y: 6});
|
||||||
|
|
||||||
assert.equal(circle.getX(), 5);
|
assert.equal(circle.getX(), 5);
|
||||||
assert.equal(circle.getY(), 6);
|
assert.equal(circle.getY(), 6);
|
||||||
@ -574,7 +574,7 @@ suite('Node', function() {
|
|||||||
width: 200,
|
width: 200,
|
||||||
height: 50,
|
height: 50,
|
||||||
fill: 'blue',
|
fill: 'blue',
|
||||||
shadowOffset: [10, 10],
|
shadowOffset: {x: 10, y: 10},
|
||||||
});
|
});
|
||||||
|
|
||||||
var circle = new Kinetic.Circle({
|
var circle = new Kinetic.Circle({
|
||||||
@ -608,9 +608,9 @@ suite('Node', function() {
|
|||||||
radiusChanged++;
|
radiusChanged++;
|
||||||
});
|
});
|
||||||
|
|
||||||
circle.setRadius(70, 20);
|
circle.setRadius(70);
|
||||||
|
|
||||||
rect.setSize(210);
|
rect.setSize({width: 210, height: 210});
|
||||||
rect.setShadowOffset({
|
rect.setShadowOffset({
|
||||||
x: 20
|
x: 20
|
||||||
});
|
});
|
||||||
@ -776,7 +776,7 @@ suite('Node', function() {
|
|||||||
assert.equal(rect.getScale().y, 0.5);
|
assert.equal(rect.getScale().y, 0.5);
|
||||||
assert.equal(rect.getRotation(), 20 * Math.PI / 180);
|
assert.equal(rect.getRotation(), 20 * Math.PI / 180);
|
||||||
|
|
||||||
rect.setScale(2, 0.3);
|
rect.setScale({x:2, y:0.3});
|
||||||
assert.equal(rect.getScale().x, 2);
|
assert.equal(rect.getScale().x, 2);
|
||||||
assert.equal(rect.getScale().y, 0.3);
|
assert.equal(rect.getScale().y, 0.3);
|
||||||
|
|
||||||
@ -1131,7 +1131,7 @@ suite('Node', function() {
|
|||||||
assert.equal(rect.getOffset().x, 40);
|
assert.equal(rect.getOffset().x, 40);
|
||||||
assert.equal(rect.getOffset().y, 20);
|
assert.equal(rect.getOffset().y, 20);
|
||||||
|
|
||||||
rect.setOffset(80, 40);
|
rect.setOffset({x:80, y:40});
|
||||||
|
|
||||||
assert.equal(rect.getOffsetX(), 80);
|
assert.equal(rect.getOffsetX(), 80);
|
||||||
assert.equal(rect.getOffsetY(), 40);
|
assert.equal(rect.getOffsetY(), 40);
|
||||||
@ -1203,7 +1203,7 @@ suite('Node', function() {
|
|||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
rect.setShadowOffset([1, 2]);
|
rect.setShadowOffset({x:1, y:2});
|
||||||
assert.equal(rect.getShadowOffset().x, 1);
|
assert.equal(rect.getShadowOffset().x, 1);
|
||||||
assert.equal(rect.getShadowOffset().y, 2);
|
assert.equal(rect.getShadowOffset().y, 2);
|
||||||
// make sure we still have the other properties
|
// make sure we still have the other properties
|
||||||
@ -1218,16 +1218,12 @@ suite('Node', function() {
|
|||||||
assert.equal(rect.getShadowOffset().y, 4);
|
assert.equal(rect.getShadowOffset().y, 4);
|
||||||
|
|
||||||
// test partial setting
|
// test partial setting
|
||||||
rect.setShadowOffset({
|
rect.setShadowOffsetX(5);
|
||||||
x: 5
|
|
||||||
});
|
|
||||||
assert.equal(rect.getShadowOffset().x, 5);
|
assert.equal(rect.getShadowOffset().x, 5);
|
||||||
assert.equal(rect.getShadowOffset().y, 4);
|
assert.equal(rect.getShadowOffset().y, 4);
|
||||||
|
|
||||||
// test partial setting
|
// test partial setting
|
||||||
rect.setShadowOffset({
|
rect.setShadowOffsetY(6);
|
||||||
y: 6
|
|
||||||
});
|
|
||||||
assert.equal(rect.getShadowOffset().x, 5);
|
assert.equal(rect.getShadowOffset().x, 5);
|
||||||
assert.equal(rect.getShadowOffset().y, 6);
|
assert.equal(rect.getShadowOffset().y, 6);
|
||||||
|
|
||||||
@ -1248,11 +1244,11 @@ suite('Node', function() {
|
|||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
rect.setOffset(1, 2);
|
rect.setOffset({x:1, y: 2});
|
||||||
assert.equal(rect.getOffset().x, 1);
|
assert.equal(rect.getOffset().x, 1);
|
||||||
assert.equal(rect.getOffset().y, 2);
|
assert.equal(rect.getOffset().y, 2);
|
||||||
|
|
||||||
rect.setOffset([3, 4]);
|
rect.setOffset({x:3, y:4});
|
||||||
assert.equal(rect.getOffset().x, 3);
|
assert.equal(rect.getOffset().x, 3);
|
||||||
assert.equal(rect.getOffset().y, 4);
|
assert.equal(rect.getOffset().y, 4);
|
||||||
|
|
||||||
@ -1263,15 +1259,11 @@ suite('Node', function() {
|
|||||||
assert.equal(rect.getOffset().x, 5);
|
assert.equal(rect.getOffset().x, 5);
|
||||||
assert.equal(rect.getOffset().y, 6);
|
assert.equal(rect.getOffset().y, 6);
|
||||||
|
|
||||||
rect.setOffset({
|
rect.setOffsetX(7);
|
||||||
x: 7
|
|
||||||
});
|
|
||||||
assert.equal(rect.getOffset().x, 7);
|
assert.equal(rect.getOffset().x, 7);
|
||||||
assert.equal(rect.getOffset().y, 6);
|
assert.equal(rect.getOffset().y, 6);
|
||||||
|
|
||||||
rect.setOffset({
|
rect.setOffsetY(8);
|
||||||
y: 8
|
|
||||||
});
|
|
||||||
assert.equal(rect.getOffset().x, 7);
|
assert.equal(rect.getOffset().x, 7);
|
||||||
assert.equal(rect.getOffset().y, 8);
|
assert.equal(rect.getOffset().y, 8);
|
||||||
|
|
||||||
@ -1292,11 +1284,11 @@ suite('Node', function() {
|
|||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
rect.setPosition(1, 2);
|
rect.setPosition({x:1, y:2});
|
||||||
assert.equal(rect.getPosition().x, 1);
|
assert.equal(rect.getPosition().x, 1);
|
||||||
assert.equal(rect.getPosition().y, 2);
|
assert.equal(rect.getPosition().y, 2);
|
||||||
|
|
||||||
rect.setPosition([3, 4]);
|
rect.setPosition({x:3, y:4});
|
||||||
assert.equal(rect.getPosition().x, 3);
|
assert.equal(rect.getPosition().x, 3);
|
||||||
assert.equal(rect.getPosition().y, 4);
|
assert.equal(rect.getPosition().y, 4);
|
||||||
|
|
||||||
@ -1307,19 +1299,15 @@ suite('Node', function() {
|
|||||||
assert.equal(rect.getPosition().x, 5);
|
assert.equal(rect.getPosition().x, 5);
|
||||||
assert.equal(rect.getPosition().y, 6);
|
assert.equal(rect.getPosition().y, 6);
|
||||||
|
|
||||||
rect.setPosition({
|
rect.setX(7);
|
||||||
x: 7
|
|
||||||
});
|
|
||||||
assert.equal(rect.getPosition().x, 7);
|
assert.equal(rect.getPosition().x, 7);
|
||||||
assert.equal(rect.getPosition().y, 6);
|
assert.equal(rect.getPosition().y, 6);
|
||||||
|
|
||||||
rect.setPosition({
|
rect.setY(8);
|
||||||
y: 8
|
|
||||||
});
|
|
||||||
assert.equal(rect.getPosition().x, 7);
|
assert.equal(rect.getPosition().x, 7);
|
||||||
assert.equal(rect.getPosition().y, 8);
|
assert.equal(rect.getPosition().y, 8);
|
||||||
|
|
||||||
rect.move(10);
|
rect.move({x: 10, y: 10});
|
||||||
assert.equal(rect.getPosition().x, 17);
|
assert.equal(rect.getPosition().x, 17);
|
||||||
assert.equal(rect.getPosition().y, 18);
|
assert.equal(rect.getPosition().y, 18);
|
||||||
|
|
||||||
|
@ -91,10 +91,10 @@ suite('Stage', function() {
|
|||||||
|
|
||||||
assert.equal(stage.getSize().width, 578);
|
assert.equal(stage.getSize().width, 578);
|
||||||
assert.equal(stage.getSize().height, 200);
|
assert.equal(stage.getSize().height, 200);
|
||||||
stage.setSize(1, 2);
|
stage.setSize({width:1, height:2});
|
||||||
assert.equal(stage.getSize().width, 1);
|
assert.equal(stage.getSize().width, 1);
|
||||||
assert.equal(stage.getSize().height, 2);
|
assert.equal(stage.getSize().height, 2);
|
||||||
stage.setSize(3);
|
stage.setSize({width: 3, height: 3});
|
||||||
assert.equal(stage.getSize().width, 3);
|
assert.equal(stage.getSize().width, 3);
|
||||||
assert.equal(stage.getSize().height, 3);
|
assert.equal(stage.getSize().height, 3);
|
||||||
stage.setSize({
|
stage.setSize({
|
||||||
@ -103,27 +103,23 @@ suite('Stage', function() {
|
|||||||
});
|
});
|
||||||
assert.equal(stage.getSize().width, 4);
|
assert.equal(stage.getSize().width, 4);
|
||||||
assert.equal(stage.getSize().height, 5);
|
assert.equal(stage.getSize().height, 5);
|
||||||
stage.setSize({
|
stage.setWidth(6);
|
||||||
width: 6
|
|
||||||
});
|
|
||||||
assert.equal(stage.getSize().width, 6);
|
assert.equal(stage.getSize().width, 6);
|
||||||
assert.equal(stage.getSize().height, 5);
|
assert.equal(stage.getSize().height, 5);
|
||||||
stage.setSize({
|
stage.setHeight(7);
|
||||||
height: 7
|
|
||||||
});
|
|
||||||
assert.equal(stage.getSize().width, 6);
|
assert.equal(stage.getSize().width, 6);
|
||||||
assert.equal(stage.getSize().height, 7);
|
assert.equal(stage.getSize().height, 7);
|
||||||
stage.setSize([8, 9]);
|
stage.setSize({width: 8, height: 9});
|
||||||
assert.equal(stage.getSize().width, 8);
|
assert.equal(stage.getSize().width, 8);
|
||||||
assert.equal(stage.getSize().height, 9);
|
assert.equal(stage.getSize().height, 9);
|
||||||
stage.setSize([1, 1, 10, 11]);
|
stage.setSize({width:10, height:11});
|
||||||
assert.equal(stage.getSize().width, 10);
|
assert.equal(stage.getSize().width, 10);
|
||||||
assert.equal(stage.getSize().height, 11);
|
assert.equal(stage.getSize().height, 11);
|
||||||
|
|
||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
stage.setSize(333, 155);
|
stage.setSize({width:333, height:155});
|
||||||
|
|
||||||
assert.equal(stage.getSize().width, 333);
|
assert.equal(stage.getSize().width, 333);
|
||||||
assert.equal(stage.getSize().height, 155);
|
assert.equal(stage.getSize().height, 155);
|
||||||
@ -169,9 +165,9 @@ suite('Stage', function() {
|
|||||||
layer.add(greenCircle);
|
layer.add(greenCircle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
assert.equal(stage.getIntersection(300, 100).getId(), 'greenCircle', 'shape should be greenCircle');
|
assert.equal(stage.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||||
assert.equal(stage.getIntersection(380, 100).getId(), 'redCircle', 'shape should be redCircle');
|
assert.equal(stage.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle');
|
||||||
assert.equal(stage.getIntersection(100, 100), null, 'shape should be null');
|
assert.equal(stage.getIntersection({x:100, y:100}), null, 'shape should be null');
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -213,10 +209,10 @@ suite('Stage', function() {
|
|||||||
layer.add(greenCircle);
|
layer.add(greenCircle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
assert.equal(stage.getIntersection(370, 93).getId(), 'greenCircle', 'shape should be greenCircle');
|
assert.equal(stage.getIntersection({x:370, y:93}).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||||
// TODO: this passes in the browser but fails in phantomjs. no idea why.
|
// TODO: this passes in the browser but fails in phantomjs. no idea why.
|
||||||
//assert.equal(stage.getIntersection(371, 93).getId(), 'greenCircle', 'shape should be greenCircle');
|
//assert.equal(stage.getIntersection(371, 93).getId(), 'greenCircle', 'shape should be greenCircle');
|
||||||
assert.equal(stage.getIntersection(372, 93).getId(), 'redCircle', 'shape should be redCircle');
|
assert.equal(stage.getIntersection({x:372, y:93}).getId(), 'redCircle', 'shape should be redCircle');
|
||||||
|
|
||||||
//console.log(layer.hitCanvas.context._context.getImageData(1, 1, 1, 1).data)
|
//console.log(layer.hitCanvas.context._context.getImageData(1, 1, 1, 1).data)
|
||||||
|
|
||||||
@ -253,50 +249,50 @@ suite('Stage', function() {
|
|||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
// test individual shapes
|
// test individual shapes
|
||||||
assert.equal(stage.getAllIntersections(266, 114).length, 1, '17) getAllIntersections should return one shape');
|
assert.equal(stage.getAllIntersections({x: 266, y:114}).length, 1, '17) getAllIntersections should return one shape');
|
||||||
assert.equal(stage.getAllIntersections(266, 114)[0].getId(), 'greenCircle', '19) first intersection should be greenCircle');
|
assert.equal(stage.getAllIntersections({x: 266, y:114})[0].getId(), 'greenCircle', '19) first intersection should be greenCircle');
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(414, 115).length, 1, '18) getAllIntersections should return one shape');
|
assert.equal(stage.getAllIntersections({x: 414, y:115}).length, 1, '18) getAllIntersections should return one shape');
|
||||||
assert.equal(stage.getAllIntersections(414, 115)[0].getId(), 'redCircle', '20) first intersection should be redCircle');
|
assert.equal(stage.getAllIntersections({x: 414, y:115})[0].getId(), 'redCircle', '20) first intersection should be redCircle');
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(350, 118).length, 2, '1) getAllIntersections should return two shapes');
|
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '1) getAllIntersections should return two shapes');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '2) first intersection should be redCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '2) first intersection should be redCircle');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '3) second intersection should be greenCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '3) second intersection should be greenCircle');
|
||||||
|
|
||||||
// hide green circle. make sure only red circle is in result set
|
// hide green circle. make sure only red circle is in result set
|
||||||
greenCircle.hide();
|
greenCircle.hide();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(350, 118).length, 1, '4) getAllIntersections should return one shape');
|
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 1, '4) getAllIntersections should return one shape');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '5) first intersection should be redCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '5) first intersection should be redCircle');
|
||||||
|
|
||||||
// show green circle again. make sure both circles are in result set
|
// show green circle again. make sure both circles are in result set
|
||||||
greenCircle.show();
|
greenCircle.show();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(350, 118).length, 2, '6) getAllIntersections should return two shapes');
|
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '6) getAllIntersections should return two shapes');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '7) first intersection should be redCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '7) first intersection should be redCircle');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '8) second intersection should be greenCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '8) second intersection should be greenCircle');
|
||||||
|
|
||||||
// hide red circle. make sure only green circle is in result set
|
// hide red circle. make sure only green circle is in result set
|
||||||
redCircle.hide();
|
redCircle.hide();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(350, 118).length, 1, '9) getAllIntersections should return one shape');
|
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 1, '9) getAllIntersections should return one shape');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'greenCircle', '10) first intersection should be greenCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'greenCircle', '10) first intersection should be greenCircle');
|
||||||
|
|
||||||
// show red circle again. make sure both circles are in result set
|
// show red circle again. make sure both circles are in result set
|
||||||
redCircle.show();
|
redCircle.show();
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
assert.equal(stage.getAllIntersections(350, 118).length, 2, '11) getAllIntersections should return two shapes');
|
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '11) getAllIntersections should return two shapes');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '12) first intersection should be redCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '12) first intersection should be redCircle');
|
||||||
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '13) second intersection should be greenCircle');
|
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '13) second intersection should be greenCircle');
|
||||||
|
|
||||||
// test from layer
|
// test from layer
|
||||||
assert.equal(layer.getAllIntersections(350, 118).length, 2, '14) getAllIntersections should return two shapes');
|
assert.equal(layer.getAllIntersections({x: 350, y:118}).length, 2, '14) getAllIntersections should return two shapes');
|
||||||
assert.equal(layer.getAllIntersections(350, 118)[0].getId(), 'redCircle', '15) first intersection should be redCircle');
|
assert.equal(layer.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '15) first intersection should be redCircle');
|
||||||
assert.equal(layer.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '16) second intersection should be greenCircle');
|
assert.equal(layer.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '16) second intersection should be greenCircle');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -316,7 +312,7 @@ suite('Stage', function() {
|
|||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
stage.setScale(0.5);
|
stage.setScale({x:0.5, y:0.5});
|
||||||
|
|
||||||
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
|
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
|
||||||
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');
|
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');
|
||||||
@ -336,7 +332,7 @@ suite('Stage', function() {
|
|||||||
strokeWidth: 4
|
strokeWidth: 4
|
||||||
});
|
});
|
||||||
|
|
||||||
stage.setScale(0.5);
|
stage.setScale({x:0.5, y:0.5});
|
||||||
|
|
||||||
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
|
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
|
||||||
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');
|
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');
|
||||||
|
@ -15,8 +15,6 @@ suite('Rect', function(){
|
|||||||
stroke: 'blue'
|
stroke: 'blue'
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(rect)
|
|
||||||
|
|
||||||
layer.add(rect);
|
layer.add(rect);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user