S3DEditor/src/Ksort.java
2018-11-14 19:14:46 +02:00

50 lines
1.8 KiB
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// сортировка Шелла с предустановленными значениями длин промежутков самая быстрая при паре тысяч полигонов, а нам она нужны только при отрисовке малого количества полигонов
import java.util.Vector;
public class Ksort {
private static final int[] d = {1, 4, 10, 23, 57, 145, 356, 911, 1968, 4711, 11969, 27901, 84801, 213331, 543749, 1355339, 3501671, 8810089, 21521774, 58548857, 157840433, 410151271, 1131376761, 2147483647};
public static void sort(Vector e) {
Face temp=null;
int i=0, j=0, k=0, m = 0,s=e.size();
while(d[m] < s) ++m;
while(--m >= 0) {
k = d[m];
for(i=k; i<s; i++) { // k-сортировка
j = i;
temp = (Face)e.elementAt(i);
int tmpsz=temp.getS();
while( (j >= k) && (((Face)e.elementAt(j-k)).getS() > tmpsz) ) {
e.setElementAt(e.elementAt(j - k),j);
j -= k;
}
e.setElementAt(temp,j);
}
}
}
public static void sort(Face[] e) {
Face temp=null;
int i=0, j=0, k=0, m = 0,s=e.length,tmpsz;
while(d[m] < s) ++m;
while(--m >= 0) {
k = d[m];
for(i=k; i<s; i++) { // k-сортировка
j = i;
temp = e[i];
if(temp==null)temp=new Triangle(new Vertex(),new Vertex(),new Vertex(),0);
tmpsz=temp.getS();
while( (j >= k) && ((e[j-k]).getS() > tmpsz) ) {
e[j]=e[j - k];
j -= k;
}
e[j]=temp;
}
}
}
}