package Challenge;

import java.awt.Color;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;


/**
 * <p>Represents a block.<p>
 *
 * @author Marty Vona
 **/
public class ConstructionObject {

  /**
   * <p>Zero-based index of this block.</p>
   **/
  public final int index;

  /**
   * <p>center x coord of this block in world frame.</p>
   **/
  public final double x;

  /**
   * <p>center y coord of this block in world frame.</p>
   **/
  public final double y;

  /**
   * <p>Height of this block.</p>
   **/
  public final double height; 

  /**
   * <p>The projection of this block on the xy plane.</p>
   **/
  public final Rectangle2D.Double footprint;

  /**
   * <p>The color of this block.</p>
   **/
  public final Color color;

  /**
   * <p>block width in meters.</p>
   **/
  public static final double WIDTH = 0.05;

  /**
   * <p>block length in meters.</p>
   **/
  public static final double LENGTH = 0.05;

  /**
   * <p>Construct a new block.</p>
   *
   * @param index zero-based index of this block
   * @param x center x coord of this block in world frame
   * @param y center y coord of this block in world frame
   * @param height of this block in meters
   * @param h Hue color component of this block
   * @param s Saturation color component of this block
   * @param b Brightness color component of this block
   **/
  public ConstructionObject(int index,
                            double x, double y,
                            double height,
                            String color) {

    this.index = index;

    this.x = x;
    this.y = y;

    this.height = height;

    if (color.toLowerCase().compareTo("red") == 0) {
    	this.color = Color.red;
    }
    else if (color.toLowerCase().compareTo("green") == 0) {
    	this.color = Color.green;
    }
    else if (color.toLowerCase().compareTo("yellow") == 0) {
    	this.color = Color.yellow;
    }
    else { // string is "blue"
    	this.color = Color.blue;
    }

    footprint =
      new Rectangle2D.Double(x-WIDTH/2.0, y-LENGTH/2.0, WIDTH, LENGTH);
  }

  /**
   * <p>Covers {@link #toStringBuffer}, internally conses a StringBuffer.</p>
   **/
  public String toString() {
    StringBuffer sb = new StringBuffer();
    toStringBuffer(sb);
    return sb.toString();
  }
  
  /**
   * <p>Append a human-readable string representation of this construction
   * object to a StringBuffer.</p>
   *
   * @param sb the StringBuffer
   **/
  public void toStringBuffer(StringBuffer sb) {
    sb.append(Integer.toString(index));
    sb.append(" @ (");
    sb.append(Double.toString(x));
    sb.append(", ");
    sb.append(Double.toString(y));
    sb.append("), hsb color = (");
    sb.append("), height = ");
    sb.append(Double.toString(height));
  }
}

