Ejemplo n.º 1
0
 /// <summary>
 /// Adds all the data in the given node and inside the given bounding box to the given data list.
 /// </summary>
 /// <param name="data"></param>
 /// <param name="node"></param>
 /// <param name="box"></param>
 public void AddInsideAtNode(IList <TDataType> data, QuadTreeNode node, BoxF2D box)
 {
     if (box.Overlaps(_bounds))
     { // ok there is an overlap.
         if (_depth > 0)
         {
             if (_minMin != null)
             {
                 _minMin.AddInsideAtNode(data, node, box);
             }
             if (_minMax != null)
             {
                 _minMax.AddInsideAtNode(data, node, box);
             }
             if (_maxMin != null)
             {
                 _maxMin.AddInsideAtNode(data, node, box);
             }
             if (_maxMax != null)
             {
                 _maxMax.AddInsideAtNode(data, node, box);
             }
         }
         else
         {
             foreach (KeyValuePair <TPointType, TDataType> data_pair in _data)
             {
                 if (box.Contains(data_pair.Key))
                 {
                     data.Add(data_pair.Value);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void BoxF2DUnionTest()
        {
            var testDataList = new List <BoxF2D>();

            for (int idx = 0; idx < 10000; idx++)
            {
                double x1 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0);
                double x2 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0);
                double y1 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0);
                double y2 = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(1.0);

                testDataList.Add(new BoxF2D(x1, y1, x2, y2));
            }

            BoxF2D box = testDataList[0];

            foreach (BoxF2D rectangleF2D in testDataList)
            {
                box = box.Union(rectangleF2D);
            }

            foreach (BoxF2D rectangleF2D in testDataList)
            {
                box.Contains(rectangleF2D);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns all data inside the given box.
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        public IEnumerable <DataType> GetInside(BoxF2D box)
        {
            HashSet <DataType> dataset = new HashSet <DataType>();

            foreach (KeyValuePair <PointType, DataType> data in _data)
            {
                if (box.Contains(data.Key))
                {
                    dataset.Add(data.Value);
                }
            }
            return(dataset);
        }
Ejemplo n.º 4
0
        public IEnumerable <DataType> GetInside(BoxF2D box)
        {
            HashSet <DataType> dataTypeSet = new HashSet <DataType>();

            foreach (KeyValuePair <PointType, DataType> keyValuePair in this._data)
            {
                if (box.Contains((PointF2D)keyValuePair.Key))
                {
                    dataTypeSet.Add(keyValuePair.Value);
                }
            }
            return((IEnumerable <DataType>)dataTypeSet);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Fills the collection with data.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="box"></param>
 /// <param name="result"></param>
 private static void Get(Node node, BoxF2D box, HashSet <T> result)
 {
     if (node.Children is List <Node> )
     {
         var children = (node.Children as List <Node>);
         for (int idx = 0; idx < children.Count; idx++)
         {
             if (box.Overlaps(node.Boxes[idx]))
             {
                 if (box.Contains(node.Boxes[idx]))
                 { // add all the data from the child.
                     RTreeMemoryIndex <T> .GetAll(children[idx],
                                                  result);
                 }
                 else
                 { // add the data from the child.
                     RTreeMemoryIndex <T> .Get(children[idx],
                                               box, result);
                 }
             }
         }
     }
     else
     {
         var children = (node.Children as List <T>);
         if (children != null)
         { // the children are of the data type.
             for (int idx = 0; idx < node.Children.Count; idx++)
             {
                 if (node.Boxes[idx].Overlaps(box))
                 {
                     result.Add(children[idx]);
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void AddInsideAtNode(IList <TDataType> data, QuadTree <TPointType, TDataType> .QuadTreeNode node, BoxF2D box)
 {
     if (!box.Overlaps(this._bounds))
     {
         return;
     }
     if (this._depth > 0)
     {
         if (this._minMin != null)
         {
             this._minMin.AddInsideAtNode(data, node, box);
         }
         if (this._minMax != null)
         {
             this._minMax.AddInsideAtNode(data, node, box);
         }
         if (this._maxMin != null)
         {
             this._maxMin.AddInsideAtNode(data, node, box);
         }
         if (this._maxMax == null)
         {
             return;
         }
         this._maxMax.AddInsideAtNode(data, node, box);
     }
     else
     {
         foreach (KeyValuePair <TPointType, TDataType> keyValuePair in this._data)
         {
             if (box.Contains((PointF2D)keyValuePair.Key))
             {
                 data.Add(keyValuePair.Value);
             }
         }
     }
 }
Ejemplo n.º 7
0
 private static void Get(RTreeMemoryIndex <T> .Node node, BoxF2D box, HashSet <T> result)
 {
     if (node.Children is List <RTreeMemoryIndex <T> .Node> )
     {
         List <RTreeMemoryIndex <T> .Node> children = node.Children as List <RTreeMemoryIndex <T> .Node>;
         for (int index = 0; index < children.Count; ++index)
         {
             if (box.Overlaps(node.Boxes[index]))
             {
                 if (box.Contains(node.Boxes[index]))
                 {
                     RTreeMemoryIndex <T> .GetAll(children[index], result);
                 }
                 else
                 {
                     RTreeMemoryIndex <T> .Get(children[index], box, result);
                 }
             }
         }
     }
     else
     {
         List <T> children = node.Children as List <T>;
         if (children == null)
         {
             return;
         }
         for (int index = 0; index < node.Children.Count; ++index)
         {
             if (node.Boxes[index].Overlaps(box))
             {
                 result.Add(children[index]);
             }
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Returns true if this rectangle overlaps with the given box.
        /// </summary>
        /// <param name="box">Box.</param>
        public bool Overlaps(BoxF2D box)
        {
            // Yes, I know this code can be shorter but it would turn into a mess!
            if (box.Contains (this.BottomLeft) || box.Contains (this.BottomRight) ||
                box.Contains (this.TopLeft) || box.Contains (this.TopRight)) {
                return true;
            }
            if (this.Contains (box.Corners [0]) || this.Contains (box.Corners [2]) ||
                this.Contains (box.Corners [3]) || this.Contains (box.Corners [0])) {
                return true;
            }

            List<LineF2D> lines = new List<LineF2D> ();
            lines.Add(new LineF2D(this.BottomLeft, this.BottomRight, true));
            lines.Add(new LineF2D(this.BottomRight, this.TopRight, true));
            lines.Add(new LineF2D(this.TopRight, this.TopLeft, true));
            lines.Add(new LineF2D(this.TopLeft, this.BottomLeft, true));
            foreach (LineF2D line in (box as IEnumerable<LineF2D>)) {
                foreach (LineF2D otherLine in lines) {
                    if (line.Intersects (otherLine)) {
                        return true;
                    }
                }
            }
            return false;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Returns true if the point is inside.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 internal bool IsInsideBox(TPointType point)
 {
     return(_bounds.Contains(point));
 }