public bool RemoveAnnotation(IMKAnnotation annotation, FBQuadTreeNode fromNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(fromNode.BoundingBox, annotation.Coordinate))
            {
                return(false);
            }

            if (fromNode.Annotations.Contains(annotation))
            {
                fromNode.Annotations.Remove(annotation);
                fromNode.Count--;
                return(true);
            }

            if (RemoveAnnotation(annotation, fromNode.NorthEast))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.NorthWest))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.SouthEast))
            {
                return(true);
            }
            if (RemoveAnnotation(annotation, fromNode.SouthWest))
            {
                return(true);
            }

            return(false);
        }
        public void EnumerateAnnotationsInBox(FBBoundingBox box, FBQuadTreeNode withNode, AnnotationEnumDelegate enumFunc)
        {
            if (!FBUtils.FBBoundingBoxIntersectsBoundingBox(withNode.BoundingBox, box))
            {
                return;
            }

            List <IMKAnnotation> tempArray = new List <IMKAnnotation>(withNode.Annotations);

            foreach (IMKAnnotation annotation in tempArray)
            {
                if (FBUtils.FBBoundingBoxContainsCoordinate(box, annotation.Coordinate))
                {
                    enumFunc(annotation);
                }
            }

            if (withNode.IsLeaf())
            {
                return;
            }

            EnumerateAnnotationsInBox(box, withNode.NorthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.NorthWest, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthWest, enumFunc);
        }
 private void Init()
 {
     Count       = 0;
     NorthEast   = null;
     NorthWest   = null;
     SouthEast   = null;
     SouthWest   = null;
     Annotations = new List <IMKAnnotation>(FBConsts.kNodeCapacity);
 }
 private void Init()
 {
     Count = 0;
     NorthEast = null;
     NorthWest = null;
     SouthEast = null;
     SouthWest = null;
     Annotations = new List<IMKAnnotation>(FBConsts.kNodeCapacity);
 }
        public void Subdivide()
        {
            NorthEast = new FBQuadTreeNode();
            NorthWest = new FBQuadTreeNode();
            SouthEast = new FBQuadTreeNode();
            SouthWest = new FBQuadTreeNode();

            FBBoundingBox box  = BoundingBox;
            double        xMid = (box.xf + box.x0) / 2.0;
            double        yMid = (box.yf + box.y0) / 2.0;

            NorthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, box.y0, box.xf, yMid);
            NorthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, box.y0, xMid, yMid);
            SouthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, yMid, box.xf, box.yf);
            SouthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, yMid, xMid, box.yf);
        }
        public void Subdivide()
        {
            NorthEast = new FBQuadTreeNode();
            NorthWest = new FBQuadTreeNode();
            SouthEast = new FBQuadTreeNode();
            SouthWest = new FBQuadTreeNode();

            FBBoundingBox box = BoundingBox;
            double xMid = (box.xf + box.x0) / 2.0;
            double yMid = (box.yf + box.y0) / 2.0;

            NorthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, box.y0, box.xf, yMid);
            NorthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, box.y0, xMid, yMid);
            SouthEast.BoundingBox = FBUtils.FBBoundingBoxMake(xMid, yMid, box.xf, box.yf);
            SouthWest.BoundingBox = FBUtils.FBBoundingBoxMake(box.x0, yMid, xMid, box.yf);
        }
        public bool RemoveAnnotation(IMKAnnotation annotation, FBQuadTreeNode fromNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(fromNode.BoundingBox, annotation.Coordinate)) {
                return false;
            }

            if (fromNode.Annotations.Contains(annotation)) 
            {
                fromNode.Annotations.Remove(annotation);
                fromNode.Count--;
                return true;
            }

            if (RemoveAnnotation(annotation, fromNode.NorthEast)) return true;
            if (RemoveAnnotation(annotation, fromNode.NorthWest)) return true;
            if (RemoveAnnotation(annotation, fromNode.SouthEast)) return true;
            if (RemoveAnnotation(annotation, fromNode.SouthWest)) return true;

            return false;
        }
        public bool InsertAnnotation(IMKAnnotation annotation, FBQuadTreeNode toNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(toNode.BoundingBox, annotation.Coordinate))
            {
                return(false);
            }

            if (toNode.Count < FBConsts.kNodeCapacity)
            {
                toNode.Annotations.Add(annotation);
                toNode.Count++;
                return(true);
            }

            if (toNode.IsLeaf())
            {
                toNode.Subdivide();
            }

            if (InsertAnnotation(annotation, toNode.NorthEast))
            {
                return(true);
            }
            if (InsertAnnotation(annotation, toNode.NorthWest))
            {
                return(true);
            }
            if (InsertAnnotation(annotation, toNode.SouthEast))
            {
                return(true);
            }
            if (InsertAnnotation(annotation, toNode.SouthWest))
            {
                return(true);
            }

            return(false);
        }
        public bool InsertAnnotation(IMKAnnotation annotation, FBQuadTreeNode toNode)
        {
            if (!FBUtils.FBBoundingBoxContainsCoordinate(toNode.BoundingBox, annotation.Coordinate)) {
                return false;
            }

            if (toNode.Count < FBConsts.kNodeCapacity) {
                toNode.Annotations.Add(annotation);
                toNode.Count++;
                return true;
            }

            if (toNode.IsLeaf()) {
                toNode.Subdivide();
            }

            if (InsertAnnotation(annotation, toNode.NorthEast)) return true;
            if (InsertAnnotation(annotation, toNode.NorthWest)) return true;
            if (InsertAnnotation(annotation, toNode.SouthEast)) return true;
            if (InsertAnnotation(annotation, toNode.SouthWest)) return true;

            return false;
        }
Example #10
0
        public void EnumerateAnnotationsInBox(FBBoundingBox box, FBQuadTreeNode withNode, AnnotationEnumDelegate enumFunc)
        {
            if (!FBUtils.FBBoundingBoxIntersectsBoundingBox(withNode.BoundingBox, box)) {
                return;
            }

            List<IMKAnnotation> tempArray = new List<IMKAnnotation>(withNode.Annotations);

            foreach (IMKAnnotation annotation in tempArray) {
                if (FBUtils.FBBoundingBoxContainsCoordinate(box, annotation.Coordinate)) {
                    enumFunc(annotation);
                }
            }

            if (withNode.IsLeaf()) {
                return;
            }

            EnumerateAnnotationsInBox(box, withNode.NorthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.NorthWest, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthEast, enumFunc);
            EnumerateAnnotationsInBox(box, withNode.SouthWest, enumFunc);
        }
Example #11
0
 public FBQuadTree()
 {
     _rootNode = new FBQuadTreeNode(FBUtils.FBBoundingBoxForMapRect(new MKMapRect().World));
 }
 public FBQuadTree()
 {
     _rootNode = new FBQuadTreeNode(FBUtils.FBBoundingBoxForMapRect(new MKMapRect().World));
 }