From 59a1736b3eea62e03352efd582e54eb64d19a9d2 Mon Sep 17 00:00:00 2001 From: mourner Date: Mon, 13 Sep 2010 14:58:03 +0300 Subject: [PATCH] Point fixes --- spec/suites/geometry/PointSpec.js | 20 +++++++++++++++++--- src/geometry/Point.js | 6 +++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/spec/suites/geometry/PointSpec.js b/spec/suites/geometry/PointSpec.js index acdac15b..b1dcdd05 100644 --- a/spec/suites/geometry/PointSpec.js +++ b/spec/suites/geometry/PointSpec.js @@ -15,9 +15,23 @@ describe("Point", function() { }); }); - describe('#subtract', noSpecs); + describe('#subtract', function() { + it('should subtract the given point from this one', function() { + var a = new L.Point(50, 30), + b = new L.Point(20, 10); + expect(a.subtract(b)).toEqual(new L.Point(30, 20)); + }); + }); - describe('#add', noSpecs); + describe('#add', function() { + it('should add the given point to this one', function() { + expect(new L.Point(50, 30).add(new L.Point(20, 10))).toEqual(new L.Point(70, 40)); + }); + }); - describe('#divideBy', noSpecs); + describe('#divideBy', function() { + it('should divide this point by the given amount', function() { + expect(new L.Point(50, 30).divideBy(5)).toEqual(new L.Point(10, 6)); + }); + }); }); \ No newline at end of file diff --git a/src/geometry/Point.js b/src/geometry/Point.js index 26e004e9..ddd4793d 100644 --- a/src/geometry/Point.js +++ b/src/geometry/Point.js @@ -9,14 +9,14 @@ L.Point = function(/*Number*/ x, /*Number*/ y, /*Boolean*/ round) { L.Point.prototype = { add: function(point) { - return L.Point(this.x + point.x, this.y + point.y); + return new L.Point(this.x + point.x, this.y + point.y); }, subtract: function(point) { - return L.Point(this.x - point.x, this.y - point.y); + return new L.Point(this.x - point.x, this.y - point.y); }, divideBy: function(num, round) { - return L.Point(this.x/2, this.y/2, round); + return new L.Point(this.x/num, this.y/num, round); } }; \ No newline at end of file