package curve;

import curve.*;

public class DoubleRect {
  double x,y,width,height;

  public DoubleRect() {
    x=0;y=0;
    width=0;height=0;
  };

  public DoubleRect(
  double ax,double ay,double awidth,double aheight) {
    x=ax;y=ay;
    width=awidth;height=aheight;
  };

  //Extends this rectangle to enclose another rectangle
  public void extendTo(DoubleRect newRect) {
    double xMax,yMax;
    if(newRect!=null) {
      xMax=x+width;
      yMax=y+height;
      if(newRect.x<x) x=newRect.x;
      if(newRect.y<y) y=newRect.y;
      if(newRect.x+newRect.width>xMax) xMax=newRect.x+newRect.width;
      if(newRect.y+newRect.height>yMax) yMax=newRect.y+newRect.height;
      width=xMax-x;
      height=yMax-y;
    }
  };

  public String toString() {
    String s;
    s="("+new PrintableDouble(x).asStringSF(2);
    s+=","+new PrintableDouble(y).asStringSF(2);
    s+=","+new PrintableDouble(width).asStringSF(2);
    s+=","+new PrintableDouble(height).asStringSF(2)+")";
    return s;
  };
};