Ejemplo n.º 1
0
        /// <summary>
        /// Select a list of <typeparamref name="T"/> which area intersect with the specified one.
        /// </summary>
        /// <param name="area">
        /// A <see cref="GeoTreeArea"/> which delimits the <typeparamref name="T"/> instances to be selected.
        /// </param>
        /// <returns>
        /// It returns a <see cref="ICollection{T}"/> containing all <typeparamref name="T"/> instances intersecting
        /// with <paramref name="area"/>.
        /// </returns>
        public ICollection <T> Select(GeoTreeArea area)
        {
            Dictionary <Guid, T> selectedNodes = new Dictionary <Guid, T>();

            _Root.Select(area, selectedNodes);

            return(selectedNodes.Values);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Select a list of <typeparamref name="T"/> which area intersect with the specified one.
 /// </summary>
 /// <param name="area">
 /// A <see cref="GeoTreeArea"/> which delimits the <typeparamref name="T"/> instances to be selected.
 /// </param>
 /// <param name="selectedNodes">
 /// A <see cref="Dictionary{Guid,T}"/> that collectes the selected nodes.
 /// </param>
 public virtual void Select(GeoTreeArea area, Dictionary <Guid, T> selectedNodes)
 {
     foreach (GeoTreePartition spacePartition in mPartition)
     {
         if ((spacePartition != null) && (spacePartition.Area.Intersect(area)))
         {
             spacePartition.Select(area, selectedNodes);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Determine whether a <see cref="GeoTreeArea"/> is included in this GeoTreeArea.
        /// </summary>
        /// <param name="otherArea">
        /// The <see cref="GeoTreeArea"/> to be tested for inclusion.
        /// </param>
        /// <returns>
        /// It returns a boolean value indicating whether <paramref name="otherArea"/> is included in this GeoTreeArea.
        /// </returns>
        public bool Include(GeoTreeArea otherArea)
        {
            Vertex2d otherSize2 = otherArea.Size / 2.0;
            Vertex2d otherMin = otherArea.Centre - otherSize2, otherMax = otherArea.Centre + otherSize2;

            Vertex2d size2 = Size / 2.0;
            Vertex2d min = Centre - size2, max = Centre + size2;

            return(otherMin >= min && otherMax <= max);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Construct a GeoTree node, defining the underlying area.
            /// </summary>
            /// <param name="tree">
            /// The <see cref="GeoTree{T}"/> which this Node belongs to.
            /// </param>
            /// <param name="area">
            /// A <see cref="GeoTreeArea"/>
            /// </param>
            public GeoTreePartition(GeoTree <T> tree, GeoTreeArea area)
            {
                if (tree == null)
                {
                    throw new ArgumentNullException("tree");
                }

                Tree = tree;
                Area = area;

                mPartition[0] = CreatePartitionLL();
                mPartition[1] = CreatePartitionLR();
                mPartition[2] = CreatePartitionUL();
                mPartition[3] = CreatePartitionUR();
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Method used for creating partition nodes lazily.
 /// </summary>
 /// <param name="area">
 /// The <see cref="Vertex2d"/> convered by the returned Node.
 /// </param>
 /// <returns>
 /// It returns the <see cref="GeoTreePartition"/> covering the area <paramref name="area"/>.
 /// </returns>
 private GeoTreePartition CreatePartitionNode(GeoTreeArea area)
 {
     if (Depth < Tree.MaxDepth - 1)
     {
         return(Tree.CreateNode(area));
     }
     else if (Depth == Tree.MaxDepth - 1)
     {
         return(Tree.CreateLeafNode(area));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 6
0
            /// <summary>
            /// Select a list of <typeparamref name="T"/> which area intersect with the specified one.
            /// </summary>
            /// <param name="area">
            /// A <see cref="GeoTreeArea"/> which delimits the <typeparamref name="T"/> instances to be selected.
            /// </param>
            /// <param name="selectedNodes">
            /// A <see cref="Dictionary{Guid,T}"/> that collectes the selected nodes.
            /// </param>
            public override void Select(GeoTreeArea area, Dictionary <Guid, T> selectedNodes)
            {
                Debug.Assert(Area.Intersect(area));

                foreach (T item in Items)
                {
                    // Node may not intersect with the area requested
                    if (item.Area.Intersect(area) == false)
                    {
                        continue;
                    }
                    // Node may belongs to multiple leaf nodes
                    if (selectedNodes.ContainsKey(item.Id) == false)
                    {
                        selectedNodes.Add(item.Id, item);
                    }
                }
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Determine whether a <see cref="GeoTreeArea"/> intersect with this GeoTreeArea.
        /// </summary>
        /// <param name="otherArea">
        /// The <see cref="GeoTreeArea"/> to be tested for intersection.
        /// </param>
        /// <returns>
        /// It returns a boolean value indicating whether <paramref name="otherArea"/> intersect with this GeoTreeArea.
        /// </returns>
        public bool Intersect(GeoTreeArea otherArea)
        {
            Vertex2d otherSize2 = otherArea.Size / 2.0;
            Vertex2d otherMin = otherArea.Centre - otherSize2, otherMax = otherArea.Centre + otherSize2;

            Vertex2d size2 = Size / 2.0;
            Vertex2d min = Centre - size2, max = Centre + size2;

            if ((otherMin.x > max.x) || (otherMax.x < min.x))
            {
                return(false);
            }
            if ((otherMin.y > max.y) || (otherMax.y < min.y))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Computes the <see cref="GeoTreeArea"/> resulting from the intersection of a GeoTreeArea with this GeoTreeArea.
        /// </summary>
        /// <param name="otherArea">
        /// The <see cref="GeoTreeArea"/> to be intersected with this GeoTreeArea.
        /// </param>
        /// <returns>
        /// It returns a <see cref="GeoTreeArea"/> that is the intersection of this GeoTreeArea with <paramref name="otherArea"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="otherArea"/> is null.
        /// </exception>
        public GeoTreeArea GetIntersection(GeoTreeArea otherArea)
        {
            if (otherArea == null)
            {
                throw new ArgumentNullException("otherArea");
            }

            // No intersection?
            if (Intersect(otherArea) == false)
            {
                return(new GeoTreeArea(Vertex2d.Zero, Vertex2d.Zero));
            }

            Vertex2d otherSize2 = otherArea.Size / 2.0;
            Vertex2d otherMin = otherArea.Centre - otherSize2, otherMax = otherArea.Centre + otherSize2;

            Vertex2d size2 = Size / 2.0;
            Vertex2d min = Centre - size2, max = Centre + size2;

            Vertex2d iMin = new Vertex2d(Math.Max(min.x, otherMin.x), Math.Max(min.y, otherMin.y));
            Vertex2d iMax = new Vertex2d(Math.Min(max.x, otherMax.x), Math.Min(max.y, otherMax.y));

            return(new GeoTreeArea((iMin + iMax) / 2.0, iMax - iMin));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Create a GeoTree leaf node.
 /// </summary>
 /// <returns>
 /// It returns a <see cref="LeafNode"/> belonging to this GeoTree.
 /// </returns>
 protected virtual LeafNode CreateLeafNode(GeoTreeArea area)
 {
     return(new LeafNode(this, area));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Construct a GeoTree node, defining the underlying area.
 /// </summary>
 /// <param name="tree">
 /// The <see cref="GeoTree{T}"/> which this Node belongs to.
 /// </param>
 /// <param name="area">
 /// A <see cref="GeoTreeArea"/>
 /// </param>
 public LeafNode(GeoTree <T> tree, GeoTreeArea area)
     : base(tree, area)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Create a GeoTree node.
 /// </summary>
 /// <param name="area">
 /// The <see cref="Vertex2d"/> that specify the geographic coverage for the returned node.
 /// </param>
 /// <returns>
 /// It returns a <see cref="GeoTreePartition"/> belonging to this GeoTree.
 /// </returns>
 protected virtual GeoTreePartition CreateNode(GeoTreeArea area)
 {
     return(new GeoTreePartition(this, area));
 }