// // Circle clustering using a square spiral technique // int spacing = 50; // // Trigger threads to cluster all Nodes in background // void clusterAllObjects() { println("clusterAllObjects started."); Node[] objectsToCluster = new Node[1]; //Create a new object array to store all objects to be clustered objectsToCluster[0] = new Node(" "); //Initialize the first object println("node tables size is " + nodeCount); for (int i = 0; i < nodeCount; i++) { //Grab visible objects and throw them in the array if (nodes[i].visible) { objectsToCluster = (Node[]) append(objectsToCluster, nodes[i]); //Add this Node to the array of objectsToCluster } } println("number of visible nodes is " + objectsToCluster.length); if (objectsToCluster.length > 1) { //If any were found, then cluster them Arrays.sort(objectsToCluster, Collections.reverseOrder()); //Sort objects within array by size clusterObjects(objectsToCluster); //Cluster objects } } // // Cluster all objects passed to function // void clusterObjects(Node[] objs) { println("starting cluster function"); for(int i = 0; i < objs.length; i++) { //First reset all positions to 0,0 objs[i].resetObject(); } //Then resolve collisions --- test current object (i) against all prior objects (j) //i starts at 1, though, in order to skip over the first object, which will just remain at 0,0 for(int i = 1; i < objs.length; i++) { boolean collisionsOccurring = true; int collisionTally = 0; while(collisionsOccurring) { for(int j = 0; j < i; j++) { //Test i vs. all prior j's if(isCollision(objs[i], objs[j])) { collisionTally++; //If there is a collision, then increment the tally. } } if(collisionTally > 0) { //If any collisions happened, objs[i].moveInSpiral(); //then move object i to a new position collisionTally = 0; //and start the loop over again. } else { //But if no collsions happened, collisionsOccurring = false; //then this loop is done, and we can move on to the next object i. } } } } // // Checks for collisions between any two (circular) objects // boolean isCollision(Node object1, Node object2) { float minDistance = object1.radius + object2.radius + spacing; float actualDistance = dist(object1.destx, object1.desty, object2.destx, object2.desty); boolean isCollision; if (actualDistance < minDistance) { isCollision = true; } else { isCollision = false; } return isCollision; }