
import java.awt.*;

/** Beinhaltet einen Kreis */
public class TRectangle extends TShapeGraphic implements java.io.Serializable {
  /** Erzeugt einen Kreis 
  @param radius Der Radius
  @param x Horizontale Koordinate der linken, oberen Ecke
  @param y Vertikale Koordinate der linken, oberen Ecke
  @param filled TRUE wenn die Figur gefüllt werden soll
  */
  public TRectangle( double x, double y, double width, double height, boolean filled, Color color ) {
    // den vererbten Konstruktor aufrufen
    super();
    // Die Felder setzen
    this.width = width;
    this.height = height;
    this.x = x; this.y = y;
    this.filled = filled;
    Pen().color = color;
  }

  /** Liefert TRUE wenn die übergebene Koordinate innerhalb des gezeichneten Bereiches liegt */
  public boolean isInside( double x, double y, double tolerance ) {
    boolean result = false;

    // Die Werte sortieren
    double _x, _y, _width, _height;
    _x = this.x;
    _width = this.width;
    _y = this.y;
    _height = this.height;
    if (_height < 0) { _height = -1 * _height; _y = _y - _height + 1; }
    if (_width < 0) { _width = -1 * _width; _x = _x - _width + 1; }

    // Wenn der Punkt total außerhalb liegt, sofort beenden
    if( (x < _x-tolerance) || (x > _x + _width + tolerance) || (y < _y - tolerance) || (y >_y + _height + tolerance)) {
      return false;
    }

    result = isHigher(x,_x,tolerance) && isLower(x, _x+_width,tolerance) && isHigher(y,_y,tolerance) && isLower(y, _y+_height,tolerance);
  
    return result;
  }

  /** Der x- und y-Radius */
  public double width, height;
  /** Die linke, obre Ecke */
  public double x, y;
  /** Gefüllt oder nicht gefüllt */
  public boolean filled;
}
