import java.awt.*;
import java.awt.geom.*;
import java.awt.geom.Rectangle2D;
class Rec extends Rectangle2D.Double
 {
  static M parent;
  static Te te;
  //double x=0,y=0,w=20,h=20;
  double w=20,h=20;
  int xi,yi,wi,hi;
  int estate=0;
  Rec rec;
  dP blo,bl,cp,s;
  boolean m=false;
  Dimension dim;
  Rectangle rect;
  K fk= new K((double)1,(double)0,(double)0,(double)255);
  K pk= new K((double)270,(double)1,(double)1,(double)200);
  public Rec() { com(); }
  public Rec(Rec rec)
   {
    x=rec.x;
    y=rec.y;
    w=rec.w;
    h=rec.h;
    com();
   }
  public Rec(Rectangle r)
   {
    x=r.x;
    y=r.y;
    w=r.width;
    h=r.height;
   }
  public void com()
   {
    setRect(x,y,w,h);
    cp=new dP(x+w/2,y+h/2);
    bl=new dP(x,y);
    xi=(int)Math.rint(x);
    yi=(int)Math.rint(y);
    wi=(int)Math.rint(w);
    hi=(int)Math.rint(h);
    s=new dP(w,h);
    dim=new Dimension(wi,hi);
    rect=new Rectangle(xi,yi,wi,hi);
   }
  public Rec(Point pa,Point pb)
   {
    x=pa.x;
    y=pa.y;
    w=pb.x;
    h=pb.y;
    com();
   }
  public Rec(dP dpa,dP dpb)
   {
    x=dpa.x;
    y=dpa.y;
    w=dpb.x;
    h=dpb.y;
    com();
   }
  public Rec(dP dp,double ww,double hh)
   {
    x=dp.x;
    y=dp.y;
    w=ww;
    h=hh;
    com();
   }
  public Rec(dP dp,double ww,double hh,K pk,K fk)
   {
    x=dp.x;
    y=dp.y;
    w=ww;
    h=hh;
    this.pk=pk;
    this.fk=fk;
    com();
   }
  public Rec(double xx,double yy,dP dp)
   {
    x=xx;
    y=yy;
    w=dp.x;
    h=dp.y;
    com();
   }
  public Rec(double xx,double yy,Dimension dim)
   {
    this.dim=dim;
    x=xx;
    y=yy;
    w=dim.width;
    h=dim.height;
    com();
   }
  public Rec(double xx,double yy,double ww,double hh)
   {
    x=xx;
    y=yy;
    w=ww;
    h=hh;
    com();
   }
  public Rec(double xx,double yy,double ww,double hh,K pk,K fk)
   {
    x=xx;
    y=yy;
    w=ww;
    h=hh;
    this.pk=pk;
    this.fk=fk;
    com();
   }
  public void scale(double scx,double scy)
   {
    x*=scx;
    y*=scy;
    w*=scx;
    h*=scy;
    com();
   }
  void dblo()
   {
    if(!m) return;
    dP dp=(dP)Te.dPh.get("lc0md");
    te.lc.rRec(this,te.lc.offsg,false,pk);
    x=dp.x-blo.x;
    y=dp.y-blo.y;
    com();
    te.lc.rRec(this,te.lc.offsg,false,pk);
   }
  boolean cont(dP dp) { return contains(dp.p2d); }
  boolean cont(double x,double y) { return contains(new Point2D.Double(x,y)); }
  void cblo() 
   {
    dP dp=(dP)Te.dPh.get("lc0mp");
    if(contains(dp))
     {
      blo=dp.sub(bl); 
      m=true;
     }
   }
  Rec ablo(dP dp)
   {
    x=dp.x-blo.x;
    y=dp.y-blo.y;
    com();
    return this;
   }
  Rec bla(dP dp)
   {
    x+=dp.x;
    y+=dp.y;
    com();
    return this;
   }
  Rec bls(dP dp)
   {
    x-=dp.x;
    y-=dp.y;
    com();
    return this;
   }
  Rec bl(dP bl)
   {
    this.bl=bl;
    x=bl.x;
    y=bl.y;
    com();
    return this;
   }
  Rec bli(dP bl) { return new Rec(bl.x,bl.y,w,h,pk,fk); }
  Rec setdim(Dimension d)
   {
    w=d.width;
    h=d.height;
    com();
    return this;
   }
  Rec setdim(dP dp)
   {
    w=dp.x;
    h=dp.y;
    com();
    return this;
   }
  Rec seth(double hh)
   {
    h=hh;
    com();
    return this;
   }
  Rec setw(double ww)
   {
    w=ww;
    com();
    return this;
   }
  Rec sets(dP a)
   {
    w=a.x;
    h=a.y;
    com();
    return this;
   }
  Rec setp(dP a)
   {
    x=a.x;
    y=a.y;
    com();
    return this;
   }
  Rec sety(double yy)
   {
    y=yy;
    com();
    return this;
   }
  Rec setx(double xx)
   {
    x=xx;
    com();
    return this;
   }
  Rec swapk()
   {
    K k=fk;
    fk=pk;
    pk=k;
    com();
    return this;
   }
  Rec setfk(K k)
   {
    fk=new K(k);
    com();
    return this;
   }
  Rec setpk(K k)
   {
    pk=new K(k);
    com();
    return this;
   }
  Rec addx(double xx)
   {
    x=bl.x+xx;
    com();
    return this;
   }
  Rec addbl(dP dp)
   {
    x=bl.x+dp.x;
    y=bl.y+dp.y;
    com();
    return this;
   }
  Rec setbl(dP dp)
   {
    x=dp.x;
    y=dp.y;
    com();
    return this;
   }
  Rec settr(dP dp)
   {
    w=dp.x-x;
    h=dp.y-y;
    com();
    return this;
   }
  Rec setcp(dP cp)
   {
    this.cp=cp;
    x=cp.x-w/2;
    y=cp.y-h/2;
    com();
    return this;
   }
  public void dofin()
   {
    try { finalize(); }
    catch (Throwable e) {}
   }
  boolean rne(Rec reca)
   {
    if(reca.x == x && reca.y == y && reca.w == w && reca.h == h) return false;
    x=reca.x;
    y=reca.y;
    w=reca.w;
    h=reca.h;
    com();
    return true;
   }
  void fill3Dpk(Graphics g) { fill3D(g,pk); }
  void fill3Dfk(Graphics g) { fill3D(g,fk); }
  void fill3D(Graphics g,K k) { fill3D(g,k.c); }
  void fill3D(Graphics g,Color c)
   {
    Color ori=g.getColor();
    g.setColor(c);
    g.fill3DRect(xi,yi,wi,hi,true);
    g.setColor(ori);
   }
  void ed(String name)
   {
    tta1(name+".x "+Te.Svo(bl.x));
    tta1(name+".y "+Te.Svo(bl.y));
    tta1(name+".w "+Te.Svo(w));
    tta1(name+".h "+Te.Svo(h));
    tta1(name+".bl "+Te.Svo(bl));
    tta1(name+".cp "+Te.Svo(cp));
    tta1(name+".pk "+Te.Svo(pk));
    tta1(name+".fk "+Te.Svo(fk));
   }
  static void tta1(String s) { parent.tta1(s); }
  public Rec snap(double d)
   {
    x=d*Math.rint(x/d);
    y=d*Math.rint(y/d);
    w=d*Math.rint(w/d);
    h=d*Math.rint(h/d);
    com();
    return this;
   }
 }
