From 411b337efebc983a4e8af381f59fb5b5c2cbefd0 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Mon, 2 Dec 2013 21:32:46 -0800 Subject: [PATCH] layer tests are now passing --- src/Context.js | 16 +++++++++------- src/Layer.js | 12 ++++++++---- test/unit/Layer-test.js | 10 +++++----- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Context.js b/src/Context.js index 75d38091..29e5124a 100644 --- a/src/Context.js +++ b/src/Context.js @@ -188,16 +188,18 @@ * clear canvas * @method * @memberof Kinetic.Context.prototype + * @param {Object} [bounds] + * @param {Number} [bounds.x] + * @param {Number} [bounds.y] + * @param {Number} [bounds.width] + * @param {Number} [bounds.height] */ - clear: function() { - var args = [].slice.call(arguments), - canvas = this.getCanvas(), + clear: function(bounds) { + var canvas = this.getCanvas(), pos, size; - if (args.length) { - pos = Kinetic.Util._getXY(args); - size = Kinetic.Util._getSize(args); - this.clearRect(pos.x || 0, pos.y || 0, size.width, size.height); + if (bounds) { + this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0); } else { this.clearRect(0, 0, canvas.getWidth(), canvas.getHeight()); diff --git a/src/Layer.js b/src/Layer.js index 453d504c..f788d9bc 100644 --- a/src/Layer.js +++ b/src/Layer.js @@ -153,17 +153,21 @@ * clear scene and hit canvas contexts tied to the layer * @method * @memberof Kinetic.Node.prototype - * @param {Array|Object} [bounds] + * @param {Object} [bounds] + * @param {Number} [bounds.x] + * @param {Number} [bounds.y] + * @param {Number} [bounds.width] + * @param {Number} [bounds.height] * @example * layer.clear();
* layer.clear(0, 0, 100, 100); */ - clear: function() { + clear: function(bounds) { var context = this.getContext(), hitContext = this.getHitCanvas().getContext(); - context.clear.apply(context, arguments); - hitContext.clear.apply(hitContext, arguments); + context.clear(bounds); + hitContext.clear(bounds); return this; }, // extend Node.prototype.setVisible diff --git a/test/unit/Layer-test.js b/test/unit/Layer-test.js index 264069ef..bc76d63d 100644 --- a/test/unit/Layer-test.js +++ b/test/unit/Layer-test.js @@ -88,7 +88,7 @@ suite('Layer', function() { layer.add(circle); stage.add(layer); - layer.clear(100, 100, 100, 100); + layer.clear({x:100, y:100, width: 100, height:100}); var trace = layer.getContext().getTrace(); //console.log(trace); @@ -130,9 +130,9 @@ suite('Layer', function() { layer.add(greenCircle); stage.add(layer); - assert.equal(layer.getIntersection(300, 100).getId(), 'greenCircle', 'shape should be greenCircle'); - assert.equal(layer.getIntersection(380, 100).getId(), 'redCircle', 'shape should be redCircle'); - assert.equal(layer.getIntersection(100, 100), null, 'shape should be null'); + assert.equal(layer.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle'); + assert.equal(layer.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle'); + assert.equal(layer.getIntersection({x:100, y:100}), null, 'shape should be null'); }); @@ -186,7 +186,7 @@ suite('Layer', function() { stage.add(layer); for(var n = 0; n < 20; n++) { - circle.move(10, 0); + circle.move({x:10, y:0}); layer.draw(); }