Ejemplo n.º 1
0
        public ClusterLeaf <T> GetLeaf(double locationX, double locationY)
        {
            // find the right child cluster
            int index = GetLocationIndex(locationX, locationY);

            if (childClusters[index] == null)
            {
                int    xf          = ((locationX - X) > (childClusterSize)) ? 1 : 0;
                int    yf          = ((locationY - Y) > (childClusterSize)) ? 1 : 0;
                double newClusterX = X + ((childClusterSize) * xf);
                double newClusterY = Y + ((childClusterSize) * yf);

                if (childClusterSize > MinZoom)
                {
                    childClusters[index] = new ClusterHierarchy <T>(this, childClusterSize, newClusterX, newClusterY);
                }
                else
                {
                    childClusters[index] = new ClusterLeaf <T>(this, childClusterSize, newClusterX, newClusterY);
                }
            }
            if (childClusters[index] is ClusterHierarchy <T> )
            {
                return(((ClusterHierarchy <T>)childClusters[index]).GetLeaf(locationX, locationY));
            }
            else if (childClusters[index] is ClusterLeaf <T> )
            {
                return((ClusterLeaf <T>)childClusters[index]);
            }
            else
            {
                // something went wrong
                return(null);
            }
        }
Ejemplo n.º 2
0
        // this is for debugging purposes only - it creates the clusters upfront
        public void CreateDebugHierarchy()
        {
            for (long xf = 0; xf < 2; xf++)
            {
                for (long yf = 0; yf < 2; yf++)
                {
                    double newClusterX = X + (childClusterSize * xf);
                    double newClusterY = Y + (childClusterSize * yf);

                    if (childClusterSize > MinZoom)
                    {
                        var h = new ClusterHierarchy <T>(this, childClusterSize, newClusterX, newClusterY);
                        childClusters[xf + (yf * 2)] = h;
                        h.CreateDebugHierarchy();
                    }
                    else
                    {
                        childClusters[xf + (yf * 2)] = new ClusterLeaf <T>(this, childClusterSize, newClusterX, newClusterY);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public List <ClusterLeaf <T> > GetLeafs()
        {
            List <ClusterLeaf <T> > leafs = new List <ClusterLeaf <T> >();

            for (int i = 0; i < NR_OF_CLUSTERS; i++)
            {
                if (childClusters[i] != null)
                {
                    if (childClusters[i] is ClusterHierarchy <T> )
                    {
                        ClusterHierarchy <T> h = childClusters[i] as ClusterHierarchy <T>;

                        leafs.AddRange(h.GetLeafs());
                    }
                    else if (childClusters[i] is ClusterLeaf <T> )
                    {
                        leafs.Add((ClusterLeaf <T>)childClusters[i]);
                    }
                }
            }
            return(leafs);
        }