// The important values are y1 and data
sclass SimpleScanlineImage {
  // core value (mandatory): first row occupied
  int y1;
  
  // core value (mandatory): x coordinates per row
  // x_left is inclusive, x_right is exclusive
  //
  // Order in array:
  //   x_left at y1, x_right at y1,
  //   x_left at y1+1, x_right at y1+1, ,,,
  int[] data;

  // color is optional 
  Color color = Color.red;
  
  // bounds can be calculated quickly from core values
  simplyCached Rect bounds() {
    int x1 = Int.MAX_VALUE, x2 = 0;
    for (int i = 0; i < l(data); i += 2) {
      x1 = min(x1, data[i]);
      x2 = max(x2, data[i+1]);
    }
    ret rectFromPoints(x1, y1, x2, y2());
  }
  
  int y2() { ret y1+l(data)/2; }
  
  bool contains(Pt p) { ret contains(p.x, p.y); }
  bool contains(int x, int y) {
    if (y < y1) false;
    int i = (y-y1)*2;
    if (i >= l(data)) false;
    ret x >= data[i] && x < data[i+1];
  }
}