mirror of https://github.com/rusefi/RomRaider.git
Changed code to use true Linear Interpolation rather than even cell distance distribution
This commit is contained in:
parent
bd39e419bf
commit
8aeb766fc4
|
@ -1143,35 +1143,19 @@ public abstract class Table extends JPanel implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void verticalInterpolate() {
|
public void verticalInterpolate() {
|
||||||
horizontalInterpolate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void horizontalInterpolate() {
|
public void horizontalInterpolate() {
|
||||||
int[] coords = { getDataSize(), 0};
|
|
||||||
DataCell[] tableData = getData();
|
|
||||||
|
|
||||||
int y;
|
|
||||||
for (y = 0; y < getDataSize(); y++) {
|
|
||||||
if (tableData[y].isSelected()) {
|
|
||||||
if (y < coords[0])
|
|
||||||
coords[0] = y;
|
|
||||||
if (y > coords[1])
|
|
||||||
coords[1] = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (coords[1] - coords[0] > 1) {
|
|
||||||
double diff = (tableData[coords[0]].getRealValue() - tableData[coords[1]].getRealValue()) / (coords[1] - coords[0]);
|
|
||||||
if (Math.abs(diff) > 0) {
|
|
||||||
for (y = coords[0] + 1; y < coords[1]; y++)
|
|
||||||
data[y].setRealValue(String.valueOf(tableData[y - 1].getRealValue() - diff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void interpolate() {
|
public void interpolate() {
|
||||||
horizontalInterpolate();
|
horizontalInterpolate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double linearInterpolation(double x, double x1, double x2, double y1, double y2) {
|
||||||
|
return (x1 == x2) ? 0.0 : (y1 + (x - x1) * (y2 - y1) / (x2 - x1));
|
||||||
|
}
|
||||||
|
|
||||||
public void validateScaling() {
|
public void validateScaling() {
|
||||||
if (type != Settings.TABLE_SWITCH) {
|
if (type != Settings.TABLE_SWITCH) {
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,30 @@ public class Table2D extends Table {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void horizontalInterpolate() {
|
public void horizontalInterpolate() {
|
||||||
super.horizontalInterpolate();
|
int[] coords = { getDataSize(), 0};
|
||||||
|
DataCell[] tableData = getData();
|
||||||
|
DataCell[] axisData = getAxis().getData();
|
||||||
|
|
||||||
|
for (int i = 0; i < getDataSize(); ++i) {
|
||||||
|
if (tableData[i].isSelected()) {
|
||||||
|
if (i < coords[0])
|
||||||
|
coords[0] = i;
|
||||||
|
if (i > coords[1])
|
||||||
|
coords[1] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (coords[1] - coords[0] > 1) {
|
||||||
|
double x, x1, x2, y1, y2;
|
||||||
|
x1 = axisData[coords[0]].getValue();
|
||||||
|
y1 = tableData[coords[0]].getValue();
|
||||||
|
x2 = axisData[coords[1]].getValue();
|
||||||
|
y2 = tableData[coords[1]].getValue();
|
||||||
|
for (int i = coords[0] + 1; i < coords[1]; ++i) {
|
||||||
|
x = axisData[i].getValue();
|
||||||
|
data[i].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Interpolate x axis in case the x axis in selected.
|
||||||
this.getAxis().horizontalInterpolate();
|
this.getAxis().horizontalInterpolate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -784,29 +784,32 @@ public class Table3D extends Table {
|
||||||
public void verticalInterpolate() {
|
public void verticalInterpolate() {
|
||||||
int[] coords = { getSizeX(), getSizeY(), 0, 0};
|
int[] coords = { getSizeX(), getSizeY(), 0, 0};
|
||||||
DataCell[][] tableData = get3dData();
|
DataCell[][] tableData = get3dData();
|
||||||
|
DataCell[] axisData = getYAxis().getData();
|
||||||
int x, y;
|
int i, j;
|
||||||
for (x = 0; x < getSizeX(); x++) {
|
for (i = 0; i < getSizeX(); ++i) {
|
||||||
for (y = 0; y < getSizeY(); y++) {
|
for (j = 0; j < getSizeY(); ++j) {
|
||||||
if (tableData[x][y].isSelected()) {
|
if (tableData[i][j].isSelected()) {
|
||||||
if (x < coords[0])
|
if (i < coords[0])
|
||||||
coords[0] = x;
|
coords[0] = i;
|
||||||
if (x > coords[2])
|
if (i > coords[2])
|
||||||
coords[2] = x;
|
coords[2] = i;
|
||||||
if (y < coords[1])
|
if (j < coords[1])
|
||||||
coords[1] = y;
|
coords[1] = j;
|
||||||
if (y > coords[3])
|
if (j > coords[3])
|
||||||
coords[3] = y;
|
coords[3] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (coords[3] - coords[1] > 1) {
|
if (coords[3] - coords[1] > 1) {
|
||||||
double diff;
|
double x, x1, x2, y1, y2;
|
||||||
for (y = coords[0]; y <= coords[2]; y++) {
|
x1 = axisData[coords[1]].getValue();
|
||||||
diff = (tableData[y][coords[1]].getRealValue() - tableData[y][coords[3]].getRealValue()) / (coords[3] - coords[1]);
|
x2 = axisData[coords[3]].getValue();
|
||||||
if (Math.abs(diff) > 0) {
|
for (i = coords[0]; i <= coords[2]; ++i) {
|
||||||
for (x = coords[1] + 1; x < coords[3]; x++)
|
y1 = tableData[i][coords[1]].getValue();
|
||||||
tableData[y][x].setRealValue(String.valueOf(tableData[y][x - 1].getRealValue() - diff));
|
y2 = tableData[i][coords[3]].getValue();
|
||||||
|
for (j = coords[1] + 1; j < coords[3]; ++j) {
|
||||||
|
x = axisData[j].getValue();
|
||||||
|
tableData[i][j].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -818,30 +821,33 @@ public class Table3D extends Table {
|
||||||
public void horizontalInterpolate() {
|
public void horizontalInterpolate() {
|
||||||
int[] coords = { getSizeX(), getSizeY(), 0, 0 };
|
int[] coords = { getSizeX(), getSizeY(), 0, 0 };
|
||||||
DataCell[][] tableData = get3dData();
|
DataCell[][] tableData = get3dData();
|
||||||
|
DataCell[] axisData = getXAxis().getData();
|
||||||
int x, y;
|
int i, j;
|
||||||
for (x = 0; x < getSizeX(); x++) {
|
for (i = 0; i < getSizeX(); ++i) {
|
||||||
for (y = 0; y < getSizeY(); y++) {
|
for (j = 0; j < getSizeY(); ++j) {
|
||||||
if (tableData[x][y].isSelected()) {
|
if (tableData[i][j].isSelected()) {
|
||||||
if (x < coords[0])
|
if (i < coords[0])
|
||||||
coords[0] = x;
|
coords[0] = i;
|
||||||
if (x > coords[2])
|
if (i > coords[2])
|
||||||
coords[2] = x;
|
coords[2] = i;
|
||||||
if (y < coords[1])
|
if (j < coords[1])
|
||||||
coords[1] = y;
|
coords[1] = j;
|
||||||
if (y > coords[3])
|
if (j > coords[3])
|
||||||
coords[3] = y;
|
coords[3] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (coords[2] - coords[0] > 1) {
|
if (coords[2] - coords[0] > 1) {
|
||||||
double diff;
|
double x, x1, x2, y1, y2;
|
||||||
for (x = coords[1]; x <= coords[3]; x++) {
|
x1 = axisData[coords[0]].getValue();
|
||||||
diff = (tableData[coords[0]][x].getRealValue() - tableData[coords[2]][x].getRealValue()) / (coords[2] - coords[0]);
|
x2 = axisData[coords[2]].getValue();
|
||||||
if (Math.abs(diff) > 0) {
|
for (i = coords[1]; i <= coords[3]; ++i) {
|
||||||
for (y = coords[0] + 1; y < coords[2]; y++)
|
y1 = tableData[coords[0]][i].getValue();
|
||||||
tableData[y][x].setRealValue(String.valueOf(tableData[y - 1][x].getRealValue() - diff));
|
y2 = tableData[coords[2]][i].getValue();
|
||||||
}
|
for (j = coords[0] + 1; j < coords[2]; ++j) {
|
||||||
|
x = axisData[i].getValue();
|
||||||
|
tableData[j][i].setRealValue(String.valueOf(linearInterpolation(x, x1, x2, y1, y2)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Interpolate x axis in case the x axis in selected.
|
// Interpolate x axis in case the x axis in selected.
|
||||||
|
|
Loading…
Reference in New Issue