package tmcm.xLogicCircuits;

import java.awt.Rectangle;

final class FloatRect {
   float x,y,width,height;
   FloatRect() {
      reshape(0,0,0,0);
   }
   FloatRect(float x, float y, float width, float height) {
      reshape(x,y,width,height);
   }
   void reshape(float x, float y, float width, float height) {
      this.x = x;
      this.y = y;
      this.width = Math.max(0,width);
      this.height = Math.max(0,height);
   }
   Rectangle getIntRect() {
      return new Rectangle(Math.round(x),Math.round(y),Math.round(width),Math.round(height));
   }
   boolean inside(float a, float b) {
      return (a >= x && b >= y && a < x+width && b < y+height);
   }
   void add(float a, float b) {
      if (a < x) {
         width += x - a;
         x = a;
      }
      else if (a > x+width)
         width = a - x;
      if (b < y) {
         height += y - b;
         y = b;
      }
      else if (b > y+height)
         height = b - y;
   }
   void add(FloatRect r) {
      add(r.x,r.y);
      add(r.x+r.width, r.y+r.height);
   }
   void grow(float dx, float dy) {
      x -= dx;
      y -= dy;
      width += 2*dx;
      height += 2*dy;
   }
}

