Bail if too many partitions, and remove any bboxes that are entirely enclosed by...
authorRichard Fairhurst <richard@systemeD.net>
Tue, 27 Dec 2011 21:07:51 +0000 (21:07 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Tue, 27 Dec 2011 21:07:51 +0000 (21:07 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/halcyon/connection/bboxes/Box.as
net/systemeD/halcyon/connection/bboxes/FetchSet.as

index 4a7e12b..e3a1c58 100644 (file)
@@ -81,7 +81,7 @@ package net.systemeD.halcyon.connection {
 
                /** maximum number of /map calls to request for each pan/zoom */
                protected const MAX_BBOXES:uint=3;
-               protected var fetchSet:FetchSet = new FetchSet(MAX_BBOXES);
+               protected var fetchSet:FetchSet = new FetchSet();
 
         // store the data we download
         private var negativeID:Number = -1;
@@ -400,7 +400,7 @@ package net.systemeD.halcyon.connection {
                public function purgeIfFull(left:Number,right:Number,top:Number,bottom:Number):void {
                        if (waycount<=MAXWAYS) return;
                        purgeOutside(left,right,top,bottom);
-                       fetchSet=new FetchSet(MAX_BBOXES);
+                       fetchSet=new FetchSet();
                        fetchSet.add(new Box().fromBbox(left,bottom,right,top));
                }
 
index d07ef96..8f1172b 100644 (file)
@@ -42,7 +42,12 @@ package net.systemeD.halcyon.connection {
                                                                top:Number,bottom:Number):void {
             purgeIfFull(left,right,top,bottom);
                        var requestBox:Box=new Box().fromBbox(left,bottom,right,top);
-                       var boxes:Array=fetchSet.getBoxes(requestBox,MAX_BBOXES);
+                       var boxes:Array;
+                       try {
+                               boxes=fetchSet.getBoxes(requestBox,MAX_BBOXES);
+                       } catch(err:Error) {
+                               boxes=[requestBox];
+                       }
                        for each (var box:Box in boxes) {
                                // enlarge bbox by given margin on each edge
                                var xmargin:Number=(box.right-box.left)*MARGIN;
index ed9443a..e4b1d99 100755 (executable)
@@ -90,6 +90,13 @@ package net.systemeD.halcyon.connection.bboxes {
                                        ((y.equals(other.y)) && ((x._min == other.x._max) || (x._max == other.x._min))));
                }
 
+               // Does this box enclose another one entirely?
+               
+               public function encloses(other:Box):Boolean {
+                       return (x.contains(other.x._min) && x.contains(other.x._max) && 
+                               y.contains(other.y._min) && y.contains(other.x._max));
+               }
+
                // Merge as many boxes as possible without increasing the total area of the set of boxes. This is done by
                // identifying edges along which boxes are adjacent. Note that the input set must be disjoint.
                //
index a43c511..29dc77b 100644 (file)
@@ -4,7 +4,7 @@ package net.systemeD.halcyon.connection.bboxes {
 
                private var existing:Array;
 
-               function FetchSet(max:int):void {
+               function FetchSet():void {
                        existing=[];
                }
 
@@ -16,10 +16,18 @@ package net.systemeD.halcyon.connection.bboxes {
                
                public function add(bbox:Box):void {
                        existing.push(bbox);
+                       existing=existing.filter(function(item:Box,i:uint,arr:Array):Boolean {
+                               return !bbox.encloses(item);
+                       });
+               }
+
+               public function get size():int {
+                       return existing.length;
                }
 
                private function partitions(set:Array, yield:Function):void {
                        if (set.length==0) { yield([]); return; }
+                       if (set.length>6) { throw new Error("Too complex"); }
                        var z:Number=Math.pow(2,set.length)/2;
                        for (var i:uint=0; i<z; i++) {
                                var parts:Array= [ [], [] ];
@@ -83,6 +91,10 @@ package net.systemeD.halcyon.connection.bboxes {
                                return box;
                        });
                }
+               
+               public function toString():String {
+                       return "["+existing.join(",")+"]";
+               }
 
        }
 }