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); } }
// 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); } } } }
public int CompareTo(ClusterLeaf <T> other) { return((int)(other.GetNrOfLocations() - this.GetNrOfLocations())); }
public override LocationInstance <T> AddLocation(double locationX, double locationY, T locationInfo) { ClusterLeaf <T> leaf = GetLeaf(locationX, locationY); return(leaf.AddLocation(locationX, locationY, locationInfo)); }