public static List<LineParametric2D_F32> pruneRelativeIntensity( List<LineParametric2D_F32> lines , float intensity[] , float fraction ) { int indexSort[] = new int[ intensity.length ]; QuickSort_F32 sort = new QuickSort_F32(); sort.sort(intensity, lines.size(), indexSort); float threshold = intensity[ indexSort[ lines.size()-1] ]*fraction; List<LineParametric2D_F32> ret = new ArrayList<>(); for( int i = 0; i < lines.size(); i++ ) { if( intensity[i] >= threshold ) { ret.add( lines.get(i)); } } return ret; }
QuickSort_F32 sort = new QuickSort_F32(); sort.sort(intensity, lines.size(), indexSort);
@Test public void testSortingRandom() { float[] ret = createRandom(rand,200); float preTotal = UtilDouble.sum(ret); QuickSort_F32 sorter = new QuickSort_F32(); sorter.sort(ret,ret.length); float postTotal = UtilDouble.sum(ret); // make sure it didn't modify the list, in an unexpected way assertEquals(preTotal,postTotal,1e-2); float prev = ret[0]; for( int i = 1; i < ret.length; i++ ) { if( ret[i] < prev ) fail("Not ascending"); prev = ret[i]; } }
@Test public void testSortingRandom_indexes() { for( int a = 0; a < 20; a++ ) { float[] normal = createRandom(rand,20); float[] original = normal.clone(); float[] withIndexes = normal.clone(); int[] indexes = new int[ normal.length ]; QuickSort_F32 sorter = new QuickSort_F32(); sorter.sort(normal,normal.length); sorter.sort(withIndexes,0,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-4); // see if it produced the same results as the normal one assertEquals(normal[i],withIndexes[indexes[i]],1e-4); } } }