Refactored and reformatted code to use less static variables

This commit is contained in:
CrushedPixel
2015-04-23 14:09:54 +02:00
parent f22416be2c
commit 0003f040ed
109 changed files with 9037 additions and 10229 deletions

View File

@@ -2,21 +2,20 @@ package eu.crushedpixel.replaymod.interpolation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
public abstract class BasicSpline {
public void calcNaturalCubic(List valueCollection, Field val, Collection<Cubic> cubicCollection) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
int num = valueCollection.size()-1;
public void calcNaturalCubic(List valueCollection, Field val, Collection<Cubic> cubicCollection) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
int num = valueCollection.size() - 1;
double[] gamma = new double[num+1];
double[] delta = new double[num+1];
double[] D = new double[num+1];
double[] gamma = new double[num + 1];
double[] delta = new double[num + 1];
double[] D = new double[num + 1];
int i;
/*
We solve the equation
int i;
/*
We solve the equation
[2 1 ] [D[0]] [3(x[1] - x[0]) ]
|1 4 1 | |D[1]| |3(x[2] - x[0]) |
| 1 4 1 | | . | = | . |
@@ -27,45 +26,46 @@ public abstract class BasicSpline {
by using row operations to convert the matrix to upper triangular
and then back sustitution. The D[i] are the derivatives at the knots.
*/
gamma[0] = 1.0f / 2.0f;
for(i=1; i< num; i++) {
gamma[i] = 1.0f/(4.0f - gamma[i-1]);
}
gamma[num] = 1.0f/(2.0f - gamma[num-1]);
gamma[0] = 1.0f / 2.0f;
for(i = 1; i < num; i++) {
gamma[i] = 1.0f / (4.0f - gamma[i - 1]);
}
gamma[num] = 1.0f / (2.0f - gamma[num - 1]);
Double p0 = val.getDouble(valueCollection.get(0));
Double p1 = val.getDouble(valueCollection.get(1));
Double p0 = val.getDouble(valueCollection.get(0));
Double p1 = val.getDouble(valueCollection.get(1));
delta[0] = 3.0f * (p1 - p0) * gamma[0];
for(i=1; i< num; i++) {
p0 = val.getDouble(valueCollection.get(i-1));
p1 = val.getDouble(valueCollection.get(i+1));
delta[i] = (3.0f * (p1 - p0) - delta[i - 1]) * gamma[i];
}
p0 = val.getDouble(valueCollection.get(num-1));
p1 = val.getDouble(valueCollection.get(num));
delta[0] = 3.0f * (p1 - p0) * gamma[0];
for(i = 1; i < num; i++) {
p0 = val.getDouble(valueCollection.get(i - 1));
p1 = val.getDouble(valueCollection.get(i + 1));
delta[i] = (3.0f * (p1 - p0) - delta[i - 1]) * gamma[i];
}
delta[num] = (3.0f * (p1 - p0) - delta[num - 1]) * gamma[num];
p0 = val.getDouble(valueCollection.get(num - 1));
p1 = val.getDouble(valueCollection.get(num));
D[num] = delta[num];
for(i=num-1; i >= 0; i--) {
D[i] = delta[i] - gamma[i] * D[i+1];
}
delta[num] = (3.0f * (p1 - p0) - delta[num - 1]) * gamma[num];
//now compute the coefficients of the cubics
cubicCollection.clear();
D[num] = delta[num];
for(i = num - 1; i >= 0; i--) {
D[i] = delta[i] - gamma[i] * D[i + 1];
}
for(i=0; i<num; i++) {
p0 = val.getDouble(valueCollection.get(i));
p1 = val.getDouble(valueCollection.get(i+1));
//now compute the coefficients of the cubics
cubicCollection.clear();
cubicCollection.add(new Cubic(
p0,
D[i],
3*(p1 - p0) - 2*D[i] - D[i+1],
2*(p0 - p1) + D[i] + D[i+1]
)
);
}
}
for(i = 0; i < num; i++) {
p0 = val.getDouble(valueCollection.get(i));
p1 = val.getDouble(valueCollection.get(i + 1));
cubicCollection.add(new Cubic(
p0,
D[i],
3 * (p1 - p0) - 2 * D[i] - D[i + 1],
2 * (p0 - p1) + D[i] + D[i + 1]
)
);
}
}
}