Exemple #1
0
 /**
  * Stick the nearest edge of this rectangle to limitRect, if it doesn't overlap.
  *
  * @param r the "sticky" rectangle
  * @return a rectangle with the same dimensions as this, stuck to limitRect.
  */
 public BezRectangle stick(BezRectangle r) {
   int outcode = overlapOutcode(r);
   switch (outcode) {
     case 1:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.left - this.width, r.top - this.height, this.width, this.height);
       }
     case 2:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.left - this.width, this.top, this.width, this.height);
       }
     case 3:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.left - this.width, r.bottom, this.width, this.height);
       }
     case 4:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, this.left, r.top - this.height, this.width, this.height);
       }
     case 5:
       {
         // rectangles overlap
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, this.left, this.top, this.width, this.height);
       }
     case 6:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, this.left, r.bottom, this.width, this.height);
       }
     case 7:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.right, r.top - this.height, this.width, this.height);
       }
     case 8:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.right, this.top, this.width, this.height);
       }
     case 9:
       {
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, r.right, r.bottom, this.width, this.height);
       }
     default:
       {
         // rectangles overlap
         return BezRectangle.makeLeftTopWidthHeight(
             this.parent, this.left, this.top, this.width, this.height);
       }
   }
 }
Exemple #2
0
 /**
  * @param vt1 a LineVertex for interpolation
  * @param r1 a source rectangle for mapping
  * @param r2 a destination rectangle for mapping
  * @return a LineVertex mapped to the destination rectangle
  */
 public static Vertex2DINF map(Vertex2DINF vt1, BezRectangle r1, BezRectangle r2) {
   double x0 = vt1.x();
   double vlo = r1.getLeft();
   double vhi = r1.getRight();
   double dlo = r2.getLeft();
   double dhi = r2.getRight();
   double x1 = BezRectangle.map(x0, vlo, vhi, dlo, dhi);
   double y0 = vt1.y();
   vlo = r1.getTop();
   vhi = r1.getBottom();
   dlo = r2.getTop();
   dhi = r2.getBottom();
   double y1 = BezRectangle.map(y0, vlo, vhi, dlo, dhi);
   return new LineVertex((float) x1, (float) y1);
 }
Exemple #3
0
 /**
  * Wrap supplied rectangle in the smallest rectangle that contains it and this rectangle; Both
  * rectangles should be aligned.
  *
  * @param r
  * @return a new rectangle that contains both this and the supplied rectangle.
  */
 public BezRectangle wrap(BezRectangle r) {
   return BezRectangle.makeLeftTopRightBottom(
       this.parent,
       Math.min(this.left, r.left),
       Math.min(this.top, r.top),
       Math.max(this.right, r.right),
       Math.max(this.bottom, r.bottom));
 }
Exemple #4
0
 /** @return a BezRectangle with coordinates rounded to the nearest integer value */
 public BezRectangle roundCoordinates() {
   return BezRectangle.makeLeftTopWidthHeight(
       this.parent,
       (float) Math.round(this.left),
       (float) Math.round(this.top),
       (float) Math.round(this.width),
       (float) Math.round(this.height));
 }
Exemple #5
0
 /**
  * Returns a rectangle inset by the specified values. Negative values will outset the new
  * rectangle with respect to this rectangle. Works with aligned rectangles.
  *
  * @param insetWidth
  * @param insetHeight
  * @return a new BezRectangle inset (or outset) from the original.
  */
 public BezRectangle inset(float insetWidth, float insetHeight) {
   insetWidth = Math.min(insetWidth, this.width / 2);
   insetHeight = Math.min(insetHeight, this.height / 2);
   return BezRectangle.makeLeftTopWidthHeight(
       this.parent,
       this.left + insetWidth,
       this.top + insetHeight,
       width - 2 * insetWidth,
       height - 2 * insetHeight);
 }
Exemple #6
0
 /**
  * Clip the supplied rectangle to this rectangle; both rectangles should be aligned to x and y
  * axes.
  *
  * @param r rectangle to clip
  * @return a new rectangle clipped to the bounds of this rectangle.
  */
 public BezRectangle pin(BezRectangle r) {
   // Pin top and left of r to this rectangle
   float result_left = Math.min(Math.max(this.left, r.left), this.right);
   float result_top = Math.min(Math.max(this.top, r.top), this.bottom);
   // Slide other rectangle inside this (if possible)
   float max_width = width - result_left;
   if (r.width > max_width) result_left = Math.max(this.right - r.width, this.left);
   float max_height = height - result_top;
   if (r.height > max_height) result_top = Math.max(this.bottom - r.height, this.top);
   // Clip the resulting rectangle to this rectangle's width and height
   float result_width = Math.min(r.width, this.width - result_left);
   float result_height = Math.min(r.height, this.height - result_top);
   // Return resulting rectangle
   return BezRectangle.makeLeftTopWidthHeight(
       this.parent, result_left, result_top, result_width, result_height);
 }
Exemple #7
0
 public static BezRectangle makeRectangle(BezRectangle r) {
   BezRectangle newRectangle =
       new BezRectangle(r.parent, r.getLeft(), r.getTop(), r.width, r.height);
   newRectangle.setHasStroke(r.hasStroke());
   newRectangle.setStrokeColor(r.strokeColor());
   newRectangle.setStrokeOpacity(r.strokeOpacity());
   newRectangle.setWeight(r.weight());
   newRectangle.setHasFill(r.hasFill());
   newRectangle.setFillColor(r.fillColor());
   newRectangle.setFillOpacity(r.fillOpacity());
   return newRectangle;
 }
Exemple #8
0
 /**
  * @param x x-coordinate of point to test
  * @param y y-coordinate of point to test
  * @param r rectangle to test
  * @return {@code true} if r contains the specified point
  */
 public static boolean containsPoint(float x, float y, BezRectangle r) {
   return (x >= r.getLeft() && x <= r.getRight() && y >= r.getTop() && y <= r.getBottom());
 }
Exemple #9
0
 /**
  * Determines if this rectangle overlaps a specified rectangle
  *
  * @param r the rectangle to check against this one
  * @return {@code true} if this rectangle overlaps r, {@code false} otherwise
  */
 public boolean overlaps(BezRectangle r) {
   return (r.getBottom() >= this.top
       && r.getTop() <= this.bottom
       && r.getRight() >= this.left
       && r.getLeft() <= this.right);
 }
Exemple #10
0
 /**
  * Determines if one rectangle overlaps another rectangle
  *
  * @param one one rectangle to check for overlap
  * @param another another rectangle to check for overlap
  * @return {@code true} if one rectangle overlaps another, {@code false} otherwise
  */
 public static boolean overlaps(BezRectangle one, BezRectangle another) {
   return (another.getBottom() >= one.getTop()
       && another.getTop() <= one.getBottom()
       && another.getRight() >= one.getLeft()
       && another.getLeft() <= one.getRight());
 }