Esempio 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.IsInside(data_pair.Key))
                 {
                     data.Add(data_pair.Value);
                 }
             }
         }
     }
 }
Esempio 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.IsInside(rectangleF2D);
            }
        }
Esempio 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.IsInside(data.Key))
                {
                    dataset.Add(data.Value);
                }
            }
            return(dataset);
        }
Esempio n. 4
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.IsInside(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]);
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Returns true if the point is inside.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 internal bool IsInsideBox(TPointType point)
 {
     return(_bounds.IsInside(point));
 }