persistable sclass GSI extends AbstractHasHi15Color is G2Drawable, IPixelSet { int y1; // starting y coordinate int[] rowStarts; // where in xData each row starts int[] xData; // all x coordinates in a long list (x1, x2, x1, x2, ...) *(int *y1, int[] *rowStarts, int[] *xData) {} public int getHeight() { ret rowStarts.length; } int y2() { ret y1+rowStarts.length; } // bounds are calculated & cached transiently public simplyCached Rect bounds() { int x1 = Int.MAX_VALUE, x2 = 0; for (int i = 0; i < xData.length; i += 2) { x1 = min(x1, xData[i]); x2 = max(x2, xData[i+1]); } ret rectFromPoints(x1, y1, x2, y2()); } public bool contains(Pt p) { ret contains(p.x, p.y); } public bool contains(int x, int y) { if (y < y1 || y >= y2()) false; int i1 = rowStart(y), i2 = rowEnd(y); for (int i = i1; i < i2; i += 2) if (x < xData[i+1]) // found the right entry to check ret x >= xData[i]; false; } int rowStart(int y) { ret rowStarts[y-y1]; } int rowEnd(int y) { ret y == y2()-1 ? rowStarts.length : rowStarts[y-y1+1]; } public void drawOn(Graphics2D g) { g.setColor(color()); int h = height(); for y to h: { int i1 = rowStart(y-y1), i2 = rowEnd(y-y1); for (int i = i1; i < i2; i += 2) { int x1 = xData[i], x2 = xData[i+1]; if (x1 < x2) g.drawLine(x1, y1+y, x2-1, y1+y); } } } }