public boolean isAscending() { loadValuesIfNeeded(); switch (spacing) { case regularInterval: case regularPoint: return getResolution() > 0; case irregularPoint: return values[0] <= values[ncoords - 1]; case contiguousInterval: return values[0] <= values[ncoords]; case discontiguousInterval: return values[0] <= values[2 * ncoords - 1]; } throw new IllegalStateException("unknown spacing" + spacing); }
public double getCoordEdge1(int index) { if (index < 0 || index >= getNcoords()) throw new IllegalArgumentException("Index out of range=" + index); loadValuesIfNeeded(); switch (spacing) { case regularPoint: return startValue + (index - .5) * getResolution(); case regularInterval: return startValue + index * getResolution(); case irregularPoint: if (index > 0) return (values[index - 1] + values[index]) / 2; else return values[0] - (values[1] - values[0]) / 2; case contiguousInterval: return values[index]; case discontiguousInterval: return values[2 * index]; } throw new IllegalStateException("Unknown spacing=" + spacing); }
public double getCoordEdge2(int index) { if (index < 0 || index >= getNcoords()) throw new IllegalArgumentException("Index out of range=" + index); loadValuesIfNeeded(); switch (spacing) { case regularPoint: if (index < 0 || index >= ncoords) throw new IllegalArgumentException("Index out of range " + index); return startValue + (index + .5) * getResolution(); case regularInterval: return startValue + (index+1) * getResolution(); case irregularPoint: if (index < ncoords - 1) return (values[index] + values[index + 1]) / 2; else return values[index] + (values[index] - values[index - 1]) / 2; case contiguousInterval: return values[index + 1]; case discontiguousInterval: return values[2 * index + 1]; } throw new IllegalStateException("Unknown spacing=" + spacing); }
public double getCoordMidpoint(int index) { if (index < 0 || index >= getNcoords()) throw new IllegalArgumentException("Index out of range=" + index); loadValuesIfNeeded(); switch (spacing) { case regularPoint: return startValue + index * getResolution(); case irregularPoint: return values[index]; case regularInterval: return startValue + (index + .5) * getResolution(); case contiguousInterval: case discontiguousInterval: return (getCoordEdge1(index) + getCoordEdge2(index)) / 2; } throw new IllegalStateException("Unknown spacing=" + spacing); }
int search(double want) { if (axis.getNcoords() == 1) { return Misc.nearlyEquals(want, axis.getStartValue()) ? 0 : -1; } if (axis.isRegular()) { double fval = (want - axis.getStartValue()) / axis.getResolution(); double ival = Math.rint(fval); return Misc.nearlyEquals(fval, ival) ? (int) ival : (int) -ival - 1; // LOOK } // otherwise do a binary search return Arrays.binarySearch(axis.getValues(), want); } }
private int findCoordElementRegular(double coordValue, boolean bounded) { int n = axis.getNcoords(); if (n == 1 && bounded) return 0; double distance = coordValue - axis.getCoordEdge1(0); double exactNumSteps = distance / axis.getResolution(); //int index = (int) Math.round(exactNumSteps); // ties round to +Inf int index = (int) exactNumSteps; // truncate down if (bounded && index < 0) return 0; if (bounded && index >= n) return n - 1; // check that found point is within interval if (index >= 0 && index < n) { double lower = axis.getCoordEdge1(index); double upper = axis.getCoordEdge2(index); if (axis.isAscending()) { assert lower <= coordValue : lower + " should be le " + coordValue; assert upper >= coordValue : upper + " should be ge " + coordValue; } else { assert lower >= coordValue : lower + " should be ge " + coordValue; assert upper <= coordValue : upper + " should be le " + coordValue; } } return index; }
double xInc = xaxis.getResolution() * scaler; double yInc = Math.abs(yaxis.getResolution()) * scaler;
case regularInterval: case regularPoint: resolution = range.stride() * axis.getResolution(); break;
Assert2.assertNearlyEquals(10.5, xaxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(300.5, xaxis.getEndValue()); // LOOK is that ok? BB = 10-300: its just catching the edge Assert2.assertNearlyEquals(1.0, xaxis.getResolution()); Assert2.assertNearlyEquals(79.5, yaxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(-.5, yaxis.getEndValue()); // LOOK is that ok? BB = 0-80: its just catching the edge Assert2.assertNearlyEquals(-1.0, yaxis.getResolution());
Assert.assertEquals(CoverageCoordAxis.Spacing.regularPoint, runtimeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, runtimeAxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(6.0, runtimeAxis.getResolution());
Assert.assertEquals(CoverageCoordAxis.Spacing.irregularPoint, runtimeAxis.getSpacing()); Assert2.assertNearlyEquals(0.0, runtimeAxis.getCoordMidpoint(0)); Assert2.assertNearlyEquals(6.0, runtimeAxis.getResolution());