}
long bucket = (long) ((inx.get(0) - offset) / scale);
double nextx = (bucket + 1) * scale + offset;
int i = 0;
double oldy = Double.NaN;
RangeSet r = new RangeSet();
long bucketSize = 0;
double firsty = Double.NaN;
while(true) {
double x = inx.get(i);
double y = iny.get(i);
if(x >= nextx) {
double bucketx = bucket * scale + offset;
flushBucket(output, bucketx, firsty, r, oldy, bucketSize);
r.clear();
bucket = (int) ((x - offset) / scale);
nextx = (bucket + 1) * scale + offset;
bucketSize = 0;
firsty = y;
if(!Double.isNaN(y)) {
r.add(y, y);
}
} else {
if(bucketSize == 0) {
firsty = y;
}
if(!Double.isNaN(y)) {
if(Double.isNaN(oldy)) {
r.add(y, y);
} else {
double min, max;
if(oldy > y) {
max = oldy;
min = y;
} else {
max = y;
min = oldy;
}
r.add(min, max);
}
}
}
oldy = y;
i++;