This commit is contained in:
Eric Rowell
2013-08-25 00:34:49 -07:00
parent e8c27254ef
commit ae66350d7f
3 changed files with 40 additions and 2 deletions

View File

@@ -94,6 +94,8 @@
_getCache: function(attr, privateGetter){
var cache = this.cache[attr];
// if not cached, we need to set it using the private getter method.
if (cache === undefined) {
this.cache[attr] = privateGetter.call(this);
@@ -530,10 +532,15 @@
* @memberof Kinetic.Node.prototype
*/
getAbsolutePosition: function() {
var absoluteTransform = this.getAbsoluteTransform(),
var absoluteMatrix = this.getAbsoluteTransform().getMatrix(),
absoluteTransform = new Kinetic.Transform(),
o = this.getOffset();
// clone the matrix array
absoluteTransform.m = absoluteMatrix.slice();
absoluteTransform.translate(o.x, o.y);
return absoluteTransform.getTranslation();
},
/**

View File

@@ -655,7 +655,7 @@
}
return retObj;
},
// deep clone
// deep object clone
_clone: function(obj) {
var retObj = {};
for(var key in obj) {

View File

@@ -1467,6 +1467,37 @@ Test.Modules.NODE = {
test(Math.round(rect.getAbsolutePosition().x) === 41, 'rect absolute position x should be about 41');
test(Math.round(rect.getAbsolutePosition().y) === 92, 'rect absolute position y should be about 92');
},
'test consecutive getAbsolutePositions()s when shape has offset': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 200,
y: 20,
width: 100,
height: 50,
fill: 'red',
stroke: 'black',
strokeWidth: 4,
draggable: true,
offset: 30
//rotationDeg: 60
//rotationDeg: Math.PI / 3
});
layer.add(rect);
stage.add(layer);
test(rect.getAbsolutePosition().x === 200 && rect.getAbsolutePosition().y === 20, 'absolute position should be 200, 20');
test(rect.getAbsolutePosition().x === 200 && rect.getAbsolutePosition().y === 20, 'absolute position should be 200, 20');
test(rect.getAbsolutePosition().x === 200 && rect.getAbsolutePosition().y === 20, 'absolute position should be 200, 20');
test(rect.getAbsolutePosition().x === 200 && rect.getAbsolutePosition().y === 20, 'absolute position should be 200, 20');
test(rect.getAbsolutePosition().x === 200 && rect.getAbsolutePosition().y === 20, 'absolute position should be 200, 20');
},
'test getPosition and getAbsolutePosition for transformed parent with center offset': function(containerId) {
var side = 100;
var diagonal = Math.sqrt(side * side * 2);