[the-board] [ui] Refactor and fix code to check if page area is taken



commit f30482bf1641d3080dc36ff9a7b12bb6d5aaa534
Author: Lucas Rocha <lucasr gnome org>
Date:   Thu Jan 13 01:27:04 2011 +0000

    [ui] Refactor and fix code to check if page area is taken
    
    Now it returns a list of things intersecting with the given area. Method
    renamed to getThingsInArea() for clarity.

 src/js/ui/page.js |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/src/js/ui/page.js b/src/js/ui/page.js
index df0acd0..ba07b3b 100644
--- a/src/js/ui/page.js
+++ b/src/js/ui/page.js
@@ -130,24 +130,23 @@ Page.prototype = {
         this.emit("loaded-changed");
     },
 
-    _positionIsTaken : function(x, y, actor) {
-        return (x >= actor.x && x <= actor.x + actor.width &&
-                y >= actor.y && y <= actor.y + actor.height);
-    },
+    _getThingsInArea : function(x1, y1, x2, y2) {
+        let thingsInArea = [];
 
-    _areaIsTaken : function(x1, y1, x2, y2) {
         for (let i = 0; i < this._things.length; ++i) {
-            let actor = this._things[i].actor;
+            let thing = this._things[i];
 
-            if (this._positionIsTaken(x1, y1, actor) ||
-                this._positionIsTaken(x1, y2, actor) ||
-                this._positionIsTaken(x2, y1, actor) ||
-                this._positionIsTaken(x2, y2, actor)) {
-                return true;
+            if (x1 > thing.actor.x + thing.actor.width ||
+                x2 < thing.actor.x ||
+                y1 > thing.actor.y + thing.actor.height ||
+                y2 < thing.actor.y) {
+                continue;
             }
+
+            thingsInArea.push(thing);
         }
 
-        return false;
+        return thingsInArea;
     },
 
     _findPositionForNewThing : function(thing) {
@@ -177,7 +176,7 @@ Page.prototype = {
                     continue;
                 }
 
-                if (!this._areaIsTaken(x1, y1, x2, y2)) {
+                if (this._getThingsInArea(x1, y1, x2, y2).length == 0) {
                     return [x1, y1];
                 }
             }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]