Ejemplo n.º 1
0
        /// <summary>
        /// Splite a node into four quadrants.
        /// </summary>
        /// <param name="bounds"></param>
        /// <returns></returns>
        private void Split()
        {
            var l0 = UV.ByCoordinates(Bounds.Min.U, Bounds.Min.V);
            var l1 = UV.ByCoordinates(Bounds.Min.U, Bounds.Min.V + Bounds.Height / 2);
            var l2 = UV.ByCoordinates(Bounds.Min.U, Bounds.Max.V);

            var c0 = UV.ByCoordinates(Bounds.Min.U + Bounds.Width / 2, Bounds.Min.V);
            var c1 = UV.ByCoordinates(Bounds.Min.U + Bounds.Width / 2, Bounds.Min.V + Bounds.Height / 2);
            var c2 = UV.ByCoordinates(Bounds.Min.U + Bounds.Width / 2, Bounds.Max.V);

            var r0 = UV.ByCoordinates(Bounds.Max.U, Bounds.Min.V);
            var r1 = UV.ByCoordinates(Bounds.Max.U, Bounds.Min.V + Bounds.Height / 2);
            var r2 = UV.ByCoordinates(Bounds.Max.U, Bounds.Max.V);

            NW = new Node(l1, c2);
            NE = new Node(c1, r2);
            SW = new Node(l0, c1);
            SE = new Node(c0, r1);

            NW.Parent = this;
            NE.Parent = this;
            SW.Parent = this;
            SE.Parent = this;
        }
Ejemplo n.º 2
0
        public bool TryFind(UV uv, out Node node)
        {
            if (!Contains(uv))
            {
                node = null;
                return false;
            }

            if (IsLeafNode)
            {
                if (Point.IsAlmostEqualTo(uv))
                {
                    node = this;
                    return true;
                }
                else
                {
                    node = null;
                    return false;
                }
            }

            if (NW.Contains(uv))
            {
                if (NW.TryFind(uv, out node))
                {
                    return true;
                }
            }

            else if (NE.Contains(uv))
            {
                if (NE.TryFind(uv, out node))
                {
                    return true;
                }
            }


            else if (SW.Contains(uv))
            {
                if (SW.TryFind(uv, out node))
                {
                    return true;
                }
            }

            else if (SE.Contains(uv))
            {
                if (SE.TryFind(uv, out node))
                {
                    return true;
                } 
            }

            node = null;
            return false;
        }
Ejemplo n.º 3
0
 private Quadtree(IEnumerable<UV> uvs)
 {
     Root = new Node(UV.ByCoordinates(), UV.ByCoordinates(1, 1));
     uvs.ToList().ForEach(uv => Root.Insert(uv));
 }