package com.haxademic.core.data;

import com.haxademic.core.app.P;
import com.haxademic.core.math.MathUtil;
import com.haxademic.core.math.easing.Penner;

public class ArrayUtil {

	public static void fillArrayWithUniqueIndexes(int[] arr, int maxIndex) {
		for (int i = 0; i < arr.length; i++) {
			arr[i] = MathUtil.randRange(0, maxIndex);
			while(valueExistsInArr(arr, arr[i], i)) arr[i] = MathUtil.randRange(0, maxIndex);
		}
	}
	
	public static boolean valueExistsInArr(int[] arr, int val, int curIndex) {
		for (int i = 0; i < curIndex; i++) {
			if(arr[i] == val) return true;
		}
		return false;
	}
	
	public static void crossfadeEnds(float[] array, float fadeSize /* 0.1 */) {
	    // number of elements to fade on either end
	    int numToFade = Math.round(array.length * fadeSize);
	    // average of start/end values
	    float endAvg = (array[array.length - 1] + array[0]) / 2f;
	    for(int i = 0; i <= numToFade; i++) {
	    	// lerp strength increases
	    	float lerpStrength = (float) i / numToFade;
	    	// indices go from inland towards the edges, increasingly fading towards the ends average
	    	int endIndex = array.length - numToFade - 1 + i;
	    	float linearValEnd = P.lerp(endAvg, array[array.length - numToFade - 1], Penner.easeInOutSine(1-lerpStrength));
	    	array[endIndex] = P.lerp(array[endIndex], linearValEnd, Penner.easeInOutSine(lerpStrength));
	    	int startIndex = numToFade - i;
	    	float linearVal = P.lerp(endAvg, array[numToFade], Penner.easeInOutSine(lerpStrength));
	    	array[i] = P.lerp(array[i], linearVal, Penner.easeInOutSine(1-lerpStrength));
//	    	P.out(lerpStrength);
	    }
	}

}

@@ -422,25 +422,24 @@
 ex);%0A%09%09%7D%0A%09%7D%0A
-%09
 %0A%09public sta
@@ -599,17 +599,242 @@
 lse;%0A%09%7D%0A
-%09
+%0A%09public static int indexOfInt(int arr%5B%5D, int t) %7B%0A%09%09if (arr == null) return -1;%0A%09%09int len = arr.length;%0A%09%09int i = 0;%0A%09%09while (i %3C len) %7B%0A%09%09%09if (arr%5Bi%5D == t) %7B%0A%09%09%09%09return i;%0A%09%09%09%7D else %7B%0A%09%09%09%09i = i + 1;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return -1;%0A%09%7D%0A
 %0A%09public
@@ -904,20 +904,17 @@
  */) %7B%0A%09
-    
+%09
 // numbe
@@ -950,20 +950,17 @@
 er end%0A%09
-    
+%09
 int numT
@@ -1005,20 +1005,17 @@
 Size);%0A%09
-    
+%09
 // avera
@@ -1038,20 +1038,17 @@
 values%0A%09
-    
+%09
 float en
@@ -1098,20 +1098,17 @@
  / 2f;%0A%09
-    
+%09
 for(int 
@@ -1138,20 +1138,17 @@
 i++) %7B%0A%09
-    
+%09
 %09// lerp
@@ -1168,20 +1168,17 @@
 reases%0A%09
-    
+%09
 %09float l
@@ -1215,20 +1215,17 @@
 oFade;%0A%09
-    
+%09
 %09// indi
@@ -1308,20 +1308,17 @@
 verage%0A%09
-    
+%09
 %09int end
@@ -1356,28 +1356,25 @@
 e - 1 + i;%0A%09
-    
+%09
 %09float linea
@@ -1471,28 +1471,25 @@
 trength));%0A%09
-    
+%09
 %09array%5BendIn
@@ -1571,20 +1571,17 @@
 gth));%0A%09
-    
+%09
 %09int sta
@@ -1606,20 +1606,17 @@
 e - i;%0A%09
-    
+%09
 %09float l
@@ -1697,20 +1697,17 @@
 gth));%0A%09
-    
+%09
 %09array%5Bi
@@ -1777,16 +1777,19 @@
 ngth));%0A
+%09%09%09
 //%09    %09
@@ -1810,20 +1810,17 @@
 ngth);%0A%09
-    
+%09
 %7D%0A%09%7D%0A%0A%7D%0A

Update ArrayUtil.java