1 | if (dataset.getDomainOrder() == DomainOrder.ASCENDING) {↵ | | 1 | if (dataset.getDomainOrder() == DomainOrder.ASCENDING) {↵
|
2 | // for data in ascending order by x-value, we are (broadly) looking↵ | | |
|
3 | // for the index of the highest x-value that is less that xLow↵ | | |
|
4 | int low = 0;↵ | | 2 | int low = 0;↵
|
5 | int high = itemCount - 1;↵ | | 3 | int high = itemCount - 1;↵
|
6 | int mid = (low + high) / 2;↵ | | 4 | int mid = (low + high + 1) / 2;↵
|
7 | double lowValue = dataset.getXValue(series, low);↵ | | 5 | double lowValue = dataset.getXValue(series, low);↵
|
8 | if (lowValue >= xLow) {↵ | | 6 | if (lowValue > xHigh) {↵
|
9 | // special case where the lowest x-value is >= xLow↵ | | |
|
10 | return low;↵ | | 7 | return low;↵
|
11 | }↵ | | 8 | }↵
|
12 | double highValue = dataset.getXValue(series, high);↵ | | 9 | double highValue = dataset.getXValue(series, high);↵
|
13 | if (highValue < xLow) {↵ | | 10 | if (highValue <= x↵
|
14 | // special case where the highest x-value is < xLow↵ | | 11 | High) {↵
|
15 | return high;↵ | | 12 | return high;↵
|
16 | }↵ | | 13 | }↵
|
17 | while (high - low > 1) {↵ | | 14 | while (high - low > 1) {↵
|
18 | double midV = dataset.getXValue(series, mid);↵ | | 15 | double midV = dataset.getXValue(series, mid);↵
|
19 | if (midV >= xLow) {↵ | | 16 | if (midV <= xHigh) {↵
|
20 | high = mid;↵ | | 17 | low = mid;↵
|
21 | }↵ | | 18 | }↵
|
22 | else {↵ | | 19 | else {↵
|
23 | low = mid;↵ | | 20 | high = mid;↵
|
24 | }↵ | | 21 | }↵
|
25 | mid = (low + high) / 2;↵ | | 22 | mid = (low + high + 1) / 2;↵
|
26 | }↵ | | 23 | }↵
|
27 | return mid;↵ | | 24 | return mid;↵
|
28 | }↵ | | 25 | }↵
|
29 | else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵ | | 26 | else if (dataset.getDomainOrder() == DomainOrder.DESCENDING) {↵
|
30 | // when the x-values are sorted in descending order, the lower↵ | | 27 | // when the x-values are descending↵
|
31 | // bound is found by calculating relative to the xHigh value↵ | | 28 | , the upper bound is found by↵
|
| | | 29 | // comparing against xLow↵
|
32 | int low = 0;↵ | | 30 | int low = 0;↵
|
33 | int high = itemCount - 1;↵ | | 31 | int high = itemCount - 1;↵
|
34 | int mid = (low + high) / 2;↵ | | 32 | int mid = (low + high) / 2;↵
|
35 | double lowValue = dataset.getXValue(series, low);↵ | | 33 | double lowValue = dataset.getXValue(series, low);↵
|
36 | if (lowValue <= xHigh) {↵ | | 34 | if (lowValue < xLow) {↵
|
37 | return low;↵ | | 35 | return low;↵
|
38 | }↵ | | 36 | }↵
|
39 | double highValue = dataset.getXValue(series, high);↵ | | 37 | double highValue = dataset.getXValue(series, high);↵
|
40 | if (highValue > xHigh) {↵ | | 38 | if (highValue >= xLow) {↵
|
41 | return high;↵ | | 39 | return high;↵
|
42 | }↵ | | 40 | }↵
|
43 | while (high - low > 1) {↵ | | 41 | while (high - low > 1) {↵
|
44 | double midV = dataset.getXValue(series, mid);↵ | | 42 | double midV = dataset.getXValue(series, mid);↵
|
45 | if (midV > xHigh) {↵ | | 43 | if (midV >= xLow) {↵
|
46 | low = mid;↵ | | 44 | low = mid;↵
|
47 | }↵ | | 45 | }↵
|
48 | else {↵ | | 46 | else {↵
|
49 | high = mid;↵ | | 47 | high = mid;↵
|
50 | }↵ | | 48 | }↵
|
51 | mid = (low + high) / 2;↵ | | 49 | mid = (low + high) / 2;↵
|
52 | }↵ | | 50 | }↵
|
53 | return mid;↵ | | 51 | return mid;↵
|
54 | }↵ | | 52 | }↵
|
55 | else {↵ | | 53 | else {↵
|
56 | // we don't know anything about the ordering of the x-values,↵ | | 54 | // we don't know anything about the ordering of the x-values,↵
|
57 | // but we can still skip any initial values that fall outside the↵ | | 55 | // but we can still skip any trailing values that fall outside the↵
|
58 | // range...↵ | | 56 | // range...↵
|
59 | int index = 0;↵ | | 57 | int index = itemCount - 1;↵
|
60 | // skip any items that don't need including...↵ | | 58 | // skip any items that don't need including...↵
|
61 | while (index < itemCount && dataset.getXValue(series, index) ↵ | | 59 | while (index >= 0 && dataset.getXValue(series, index) ↵
|
62 | < xLow) {↵ | | 60 | > xHigh) {↵
|
63 | index++;↵ | | 61 | index--;↵
|
64 | }↵ | | 62 | }↵
|
65 | return Math.max(0, index - 1);↵ | | 63 | return Math.min(itemCount - 1, index + 1);↵
|
66 | } | | 64 | }
|