From b5b1e50ccf174c0fd234037bdb699a5099cd4476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 11 Jul 2011 12:21:24 +0200 Subject: [PATCH] Improve detection of passed Rectangles or Points in Rectangle#contains() --- src/basic/Rectangle.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/basic/Rectangle.js b/src/basic/Rectangle.js index 6d5f519a..a7b884ba 100644 --- a/src/basic/Rectangle.js +++ b/src/basic/Rectangle.js @@ -454,10 +454,13 @@ var Rectangle = this.Rectangle = Base.extend(/** @lends Rectangle# */{ * } * } */ - contains: function(rect) { - // TODO: improve handling of passed Rectangle or Point - return rect.width !== undefined - ? this._containsRectangle(rect) + contains: function(arg) { + // Detect rectangles either by checking for 'width' on the passed object + // or by looking at the amount of elements in the arguments list, + // or the passed array: + return arg && arg.width !== undefined + || (Array.isArray(arg) ? arg : arguments).length == 4 + ? this._containsRectangle(Rectangle.read(arguments)) : this._containsPoint(Point.read(arguments)); },