Subato

equals auf GeometricObject

package name.panitz.oose;


public class GeometricObject {
  Vertex corner;
  double width;
  double height;
  Vertex velocity;

  public GeometricObject(Vertex corner, double width, double height, Vertex velocity) {
    super();
    this.corner = corner;
    this.width = width;
    this.height = height;
    this.velocity = velocity;
  }
  double size(){
    return width*height;
  }

  public void move() {
    corner.x += velocity.x;
    corner.y += velocity.y;
  }
  @Override
  public String toString() {
    return corner+" "+width+" "+height;
  }

  boolean isLargerThan(GeometricObject that){
    return size()>that.size();
  }
  boolean isAbove(GeometricObject that){
    return corner.y+height<that.corner.y;
  }
  boolean isUnderneath(GeometricObject that){
    return that.isAbove(this);
  }
  boolean isLeftOf(GeometricObject that){
    return corner.x+width<that.corner.x;
  }
  boolean isRightOf(GeometricObject that){
    return that.isLeftOf(this);
  }
  boolean touches(GeometricObject that){
    return !(isLeftOf(that)||isRightOf(that)
        ||isAbove(that)||isUnderneath(that));
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    GeometricObject other = (GeometricObject) obj;
    if (corner == null) {
      if (other.corner != null)
        return false;
    } else if (!corner.equals(other.corner))
      return false;
    if (Math.abs(height-other.height)>1)
      return false;
    if (Math.abs(width-other.width)>1)
      return false;
    return true;
  } 
}