@@ -205,13 +205,16 @@ else if (upperIndex > axis.getCoordEdgeLast())
205205 // same contract as findCoordElement(); in addition, -1 is returned when the target is not contained in any interval
206206 private int findCoordElementDiscontiguousInterval (double target , boolean bounded ) {
207207 int idx = findSingleHit (target );
208- // multiple hits = choose closest (definition of closest will be based on axis type)
209- if (idx == MULTIPLE_HITS ) {
210- return findClosestDiscontiguousInterval (target );
211- }
212208 if (bounded && (idx >= axis .getNcoords ())) {
213209 return -1 ;
214210 }
211+ // multiple hits = choose closest (definition of closest will be based on axis type)
212+ // - OR -
213+ // idx will be Ncoords if target not contained within an interval window - however, that
214+ // does not mean target isn't between two discontiguous windows, so find the closest one
215+ if (idx == MULTIPLE_HITS || idx == axis .getNcoords ()) {
216+ return findClosestDiscontiguousInterval (target );
217+ }
215218 return idx ;
216219 }
217220
@@ -272,28 +275,25 @@ private int findClosestDiscontiguousTimeInterval(double target) {
272275 int idxFound = -1 ;
273276
274277 for (int i = 0 ; i < axis .getNcoords (); i ++) {
275- // only check if target is in discontiguous interval i
276- if (intervalContains (target , i )) {
277- // find the end of the time interval
278- double coord = axis .getCoordEdge2 (i );
279- // We want to make sure the interval includes our target point, and that means the end of the interval
280- // must be greater than or equal to the target.
281- if (coord >= target ) {
282- // compute the width (in time) of the interval
283- double width = coord - axis .getCoordEdge1 (i );
284- // we want to identify the interval with the end point closest to our target
285- // why? Because a statistic computed over a time window will only have meaning at the end
286- // of that interval, so the closer we can get to that the better.
287- double diff = Math .abs (coord - target );
288- // Here we minimize the difference between the end of an interval and our target value. If multiple
289- // intervals result in the same difference value, we will pick the one with the smallest non-zero
290- // width interval.
291- boolean tiebreaker = (diff == minDiff ) && (width != 0 ) && (width < useValue );
292- if (diff < minDiff || tiebreaker ) {
293- minDiff = diff ;
294- idxFound = i ;
295- useValue = width ;
296- }
278+ // find the end of the time interval
279+ double coord = axis .getCoordEdge2 (i );
280+ // We want to make sure the interval includes our target point, and that means the end of the interval
281+ // must be greater than or equal to the target.
282+ if (coord >= target ) {
283+ // compute the width (in time) of the interval
284+ double width = coord - axis .getCoordEdge1 (i );
285+ // we want to identify the interval with the end point closest to our target
286+ // why? Because a statistic computed over a time window will only have meaning at the end
287+ // of that interval, so the closer we can get to that the better.
288+ double diff = Math .abs (coord - target );
289+ // Here we minimize the difference between the end of an interval and our target value. If multiple
290+ // intervals result in the same difference value, we will pick the one with the smallest non-zero
291+ // width interval.
292+ boolean tiebreaker = (diff == minDiff ) && (width != 0 ) && (width < useValue );
293+ if (diff < minDiff || tiebreaker ) {
294+ minDiff = diff ;
295+ idxFound = i ;
296+ useValue = width ;
297297 }
298298 }
299299 }
0 commit comments