export default class FillArea {
  color: number;
  left: number;
  top: number;
  right: number;
  bottom: number;
  count: number = 1;
  isColored: boolean = false; //todo delete
  lastColor: number = 0; //最终颜色
  lastCssColor: string = null;
  cssColor: any;

  /**
   * Fill area of the specified color.
   */
  constructor(color, x, y) {
    this.color = color;
    this.left = this.right = x;
    this.top = this.bottom = y;
    this.lastColor = 0;  //最终的颜色
  }

  get colorRgba(): string { return FillArea.getRgbaColor(this.color) }

  static getRgbaColor(colorInt) {
    let a = new Uint32Array(1);
    a[0] = colorInt;
    let b = new Uint8Array(a.buffer);
    return `rgba(${b[0]},${b[1]},${b[2]},${b[3] / 255})`;
  }

  setColored(color, cssColor) {
    this.lastColor = color;
    this.cssColor = cssColor;
    this.isColored = true;
  }

  /**
   * Add point to the fill area
   */
  addPoint(x, y) {
    if (x < this.left) this.left = x;
    if (x > this.right) this.right = x;
    if (y < this.top) this.top = y;
    if (y > this.bottom) this.bottom = y;
    this.count++;
  }

  /**
   * Width of the fill area
   */
  width() {
    return (this.right - this.left + 1);
  }


  /**
   * Height of the fill area.
   */
  height() {
    return (this.bottom - this.top + 1);
  }


}
