private Optional<CoverageCoordAxisBuilder> subsetValues(double minValue, double maxValue, int stride) { if (axis.getSpacing() == CoverageCoordAxis.Spacing.discontiguousInterval) return subsetValuesDiscontinuous(minValue, maxValue, stride); double lower = axis.isAscending() ? Math.min(minValue, maxValue) : Math.max(minValue, maxValue); double upper = axis.isAscending() ? Math.max(minValue, maxValue) : Math.min(minValue, maxValue); int minIndex = findCoordElement(lower, false); int maxIndex = findCoordElement(upper, false); if (minIndex >= axis.getNcoords()) return Optional.empty(String.format("no points in subset: lower %f > end %f", lower, axis.getEndValue())); if (maxIndex < 0) return Optional.empty(String.format("no points in subset: upper %f < start %f", upper, axis.getStartValue())); if (minIndex < 0) minIndex = 0; if (maxIndex >= axis.getNcoords()) maxIndex = axis.getNcoords() - 1; int count = maxIndex - minIndex + 1; if (count <= 0) throw new IllegalArgumentException("no points in subset"); try { return Optional.of(subsetByIndex(new Range(minIndex, maxIndex, stride))); } catch (InvalidRangeException e) { return Optional.empty(e.getMessage()); } }
public Optional<RangeIterator> makeRange(double minValue, double maxValue, int stride) { //if (axis.getSpacing() == CoverageCoordAxis.Spacing.discontiguousInterval) // return subsetValuesDiscontinuous(minValue, maxValue, stride); double lower = axis.isAscending() ? Math.min(minValue, maxValue) : Math.max(minValue, maxValue); double upper = axis.isAscending() ? Math.max(minValue, maxValue) : Math.min(minValue, maxValue); int minIndex = findCoordElement(lower, false); int maxIndex = findCoordElement(upper, false); if (minIndex >= axis.getNcoords()) return Optional.empty(String.format("no points in subset: lower %f > end %f", lower, axis.getEndValue())); if (maxIndex < 0) return Optional.empty(String.format("no points in subset: upper %f < start %f", upper, axis.getStartValue())); if (minIndex < 0) minIndex = 0; if (maxIndex >= axis.getNcoords()) maxIndex = axis.getNcoords() - 1; int count = maxIndex - minIndex + 1; if (count <= 0) return Optional.empty("no points in subset"); try { return Optional.of(new Range(minIndex, maxIndex, stride)); } catch (InvalidRangeException e) { return Optional.empty(e.getMessage()); } }
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; }
if (axis.isAscending()) {