more unit tests working, more refactoring

This commit is contained in:
Eric Rowell
2013-12-02 21:25:20 -08:00
parent 86686eb590
commit a57d6c6106
10 changed files with 124 additions and 136 deletions

View File

@@ -218,19 +218,18 @@
* @method
* @memberof Kinetic.Container.prototype
* @param {Object} pos
* @param {Number} pos.x
* @param {Number} pos.y
* @returns {Array} array of shapes
*/
getAllIntersections: function() {
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
getAllIntersections: function(pos) {
var arr = [];
var shapes = this.find('Shape');
var len = shapes.length;
for(var n = 0; n < len; n++) {
var shape = shapes[n];
this.find('Shape').each(function(shape) {
if(shape.isVisible() && shape.intersects(pos)) {
arr.push(shape);
}
}
});
return arr;
},
@@ -297,19 +296,16 @@
Kinetic.Container.prototype.get = Kinetic.Container.prototype.find;
// add getters setters
Kinetic.Factory.addBoxGetterSetter(Kinetic.Container, 'clip');
Kinetic.Factory.addGetterSetter(Kinetic.Container, 'clip');
/**
* set clip
* @method
* @name setClip
* @memberof Kinetic.Container.prototype
* @param {Object|Array}
* @param {Object} clip {x:x, y:y, width:width, height:height}
* @example
* // set clip x, y, width and height with an array<br>
* image.setClip([20, 20, 100, 100]);<br><br>
*
* // set clip x, y, width and height with an object<br>
* // set clip x, y, width and height<br>
* image.setClip({<br>
* x: 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
* @name getClip
* @method
* @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
* @method
* @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
* @method
* @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
* @method
* @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
* @method
* @memberof Kinetic.Container.prototype
* @returns {Number}
*/
})();

View File

@@ -226,8 +226,8 @@
this.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
},
_clip: function(container) {
var clipX = container.getClipX() || 0,
clipY = container.getClipY() || 0,
var clipX = container.getClipX(),
clipY = container.getClipY(),
clipWidth = container.getClipWidth(),
clipHeight = container.getClipHeight();

View File

@@ -44,11 +44,13 @@
* method for determining if a point intersects a shape or not
* @method
* @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() {
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
obj, i, intersectionOffset, shape;
getIntersection: function(pos) {
var obj, i, intersectionOffset, shape;
if(this.isVisible()) {
for (i=0; i<INTERSECTION_OFFSETS_LEN; i++) {

View File

@@ -633,7 +633,7 @@
y += changeY;
}
this.setPosition(x, y);
this.setPosition({x:x, y:y});
return this;
},
_eachAncestorReverse: function(func, includeSelf) {

View File

@@ -106,14 +106,13 @@
* because it performs much better
* @method
* @memberof Kinetic.Shape.prototype
* @param {Object} point point can be an object containing
* an x and y property, or it can be an array with two elements
* in which the first element is the x component and the second
* element is the y component
* @param {Object} point
* @param {Number} point.x
* @param {Number} point.y
* @returns {Boolean}
*/
intersects: function() {
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
stage = this.getStage(),
intersects: function(pos) {
var stage = this.getStage(),
bufferHitCanvas = stage.bufferHitCanvas,
p;

View File

@@ -254,11 +254,13 @@
* method for determining if a point intersects a shape or not
* @method
* @memberof Kinetic.Stage.prototype
* @param {Kinetic.Shape} shape
* @param {Object} pos
* @param {Number} pos.x
* @param {Number} pos.y
* @returns {Kinetic.Shape}
*/
getIntersection: function() {
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
layers = this.getChildren(),
getIntersection: function(pos) {
var layers = this.getChildren(),
len = layers.length,
end = len - 1,
n, shape;