/** * Given a coordinate interval, find what grid element matches it. * @param target interval in this coordinate system * @param bounded if true, always return a valid index. otherwise can return < 0 or > n-1 * @return index of grid point containing it, or < 0 or > n-1 if outside grid area */ int findCoordElement(double[] target, boolean bounded) { switch (axis.getSpacing()) { case regularInterval: // can use midpoint return findCoordElementRegular((target[0]+target[1])/2, bounded); case contiguousInterval: // can use midpoint return findCoordElementContiguous((target[0]+target[1])/2, bounded); case discontiguousInterval: // cant use midpoint return findCoordElementDiscontiguousInterval(target, bounded); } throw new IllegalStateException("unknown spacing" + axis.getSpacing()); }
/** * Given a coordinate position, find what grid element contains it. * This means that * <pre> * edge[i] <= target < edge[i+1] (if values are ascending) * edge[i] > target >= edge[i+1] (if values are descending) * </pre> * * @param target position in this coordinate system * @param bounded if true, always return a valid index. otherwise can return < 0 or > n-1 * @return index of grid point containing it, or < 0 or > n-1 if outside grid area */ int findCoordElement(double target, boolean bounded) { switch (axis.getSpacing()) { case regularInterval: case regularPoint: return findCoordElementRegular(target, bounded); case irregularPoint: case contiguousInterval: return findCoordElementContiguous(target, bounded); case discontiguousInterval: return findCoordElementDiscontiguousInterval(target, bounded); } throw new IllegalStateException("unknown spacing" + axis.getSpacing()); }