public EllipseClustersIntoAsymmetricGrid() { sorter = new QuickSortComparator<>(new Comparator<Edge>() { @Override public int compare(Edge o1, Edge o2) { if (o1.angle < o2.angle) return -1; else if (o1.angle > o2.angle) return 1; else return 0; } }); }
@Test public void testSortingRandom_indexes() { for( int a = 0; a < 20; a++ ) { Double[] normal = createRandom(rand,20); Double[] original = normal.clone(); Double[] withIndexes = normal.clone(); int[] indexes = new int[ normal.length ]; QuickSortComparator<Double> sorter = new QuickSortComparator<Double>(comparator); sorter.sort(normal,normal.length); sorter.sort(withIndexes,normal.length,indexes); for( int i = 0; i < normal.length; i++ ) { // make sure the original hasn't been modified assertEquals(original[i],withIndexes[i],1e-8); // see if it produced the same results as the normal one assertEquals(normal[i],withIndexes[indexes[i]],1e-8); } } }
/** * Adds edges to node info and computes their orientation */ void addEdgesToInfo(List<Node> cluster) { for (int i = 0; i < cluster.size(); i++) { Node n = cluster.get(i); NodeInfo infoA = listInfo.get(i); EllipseRotated_F64 a = infoA.ellipse; // create the edges and order them based on their direction for (int j = 0; j < n.connections.size(); j++) { NodeInfo infoB = listInfo.get( indexOf(cluster, n.connections.get(j))); EllipseRotated_F64 b = infoB.ellipse; Edge edge = infoA.edges.grow(); edge.target = infoB; edge.angle = Math.atan2( b.center.y - a.center.y , b.center.x - a.center.x ); } sorter.sort(infoA.edges.data, infoA.edges.size); } }
@Test public void testSortingRandom() { Double[] ret = createRandom(rand, 200); double preTotal = sum(ret); QuickSortComparator<Double> sorter = new QuickSortComparator<Double>(comparator); sorter.sort(ret, ret.length); double postTotal = sum(ret); // make sure it didn't modify the list, in an unexpected way assertEquals(preTotal,postTotal,1e-8); double prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }