From f0ca6b7b8fb6d542d0f268573aaf168df3347421 Mon Sep 17 00:00:00 2001 From: Kienz Date: Mon, 20 May 2013 18:41:16 +0200 Subject: [PATCH] Remove fabric.Group.containsPoint => uses now fabric.Object.containsPoint Update group unit test - containsPoint checks now scaled group and group with padding Fix text unit test (complexity, toString) --- src/group.class.js | 18 ------------------ test/unit/group.js | 14 ++++++++++++++ test/unit/text.js | 3 ++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/group.class.js b/src/group.class.js index b06ba15e..e09e945b 100644 --- a/src/group.class.js +++ b/src/group.class.js @@ -384,24 +384,6 @@ this.top = (minY + height / 2) || 0; }, - /** - * Checks if point is contained within the group - * @param {fabric.Point} point point with `x` and `y` properties - * @return {Boolean} true if point is contained within group - */ - containsPoint: function(point) { - - var halfWidth = this.get('width') / 2, - halfHeight = this.get('height') / 2, - centerX = this.get('left'), - centerY = this.get('top'); - - return centerX - halfWidth < point.x && - centerX + halfWidth > point.x && - centerY - halfHeight < point.y && - centerY + halfHeight > point.y; - }, - /* _TO_SVG_START_ */ /** * Returns svg representation of an instance diff --git a/test/unit/group.js b/test/unit/group.js index 1f8f1d4c..fe9d9942 100644 --- a/test/unit/group.js +++ b/test/unit/group.js @@ -295,6 +295,20 @@ ok(group.containsPoint({ x: 50, y: 120 })); ok(group.containsPoint({ x: 100, y: 100 })); ok(!group.containsPoint({ x: 0, y: 0 })); + + group.scale(2); + ok(group.containsPoint({ x: 50, y: 120 })); + ok(group.containsPoint({ x: 100, y: 160 })); + ok(!group.containsPoint({ x: 0, y: 0 })); + ok(!group.containsPoint({ x: 100, y: 170 })); + + group.scale(1); + group.padding = 30; + group.setCoords(); + ok(group.containsPoint({ x: 50, y: 120 })); + ok(group.containsPoint({ x: 100, y: 170 })); + ok(!group.containsPoint({ x: 0, y: 0 })); + ok(!group.containsPoint({ x: 100, y: 172 })); }); test('forEachObject', function() { diff --git a/test/unit/text.js b/test/unit/text.js index b28952d2..6cd9c37f 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -66,7 +66,7 @@ test('toString', function() { var text = createTextObject(); ok(typeof text.toString == 'function'); - equal(text.toString(), '#'); + equal(text.toString(), '#'); }); test('toObject', function() { @@ -78,6 +78,7 @@ test('complexity', function(){ var text = createTextObject(); ok(typeof text.complexity == 'function'); + equal(text.complexity(), 1); }); test('set', function() {