Example #1
0
 /**
  * Adds a <code>Rectangle2D</code> object to this <code>Rectangle2D</code>. The resulting <code>
  * Rectangle2D</code> is the union of the two <code>Rectangle2D</code> objects.
  *
  * @param r the <code>Rectangle2D</code> to add to this <code>Rectangle2D</code>.
  * @since 1.2
  */
 public void add(Rectangle2D r) {
   double x1 = Math.min(getMinX(), r.getMinX());
   double x2 = Math.max(getMaxX(), r.getMaxX());
   double y1 = Math.min(getMinY(), r.getMinY());
   double y2 = Math.max(getMaxY(), r.getMaxY());
   setRect(x1, y1, x2 - x1, y2 - y1);
 }
Example #2
0
 /**
  * Intersects the pair of specified source <code>Rectangle2D</code> objects and puts the result
  * into the specified destination <code>Rectangle2D</code> object. One of the source rectangles
  * can also be the destination to avoid creating a third Rectangle2D object, but in this case the
  * original points of this source rectangle will be overwritten by this method.
  *
  * @param src1 the first of a pair of <code>Rectangle2D</code> objects to be intersected with each
  *     other
  * @param src2 the second of a pair of <code>Rectangle2D</code> objects to be intersected with
  *     each other
  * @param dest the <code>Rectangle2D</code> that holds the results of the intersection of <code>
  *     src1</code> and <code>src2</code>
  * @since 1.2
  */
 public static void intersect(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) {
   double x1 = Math.max(src1.getMinX(), src2.getMinX());
   double y1 = Math.max(src1.getMinY(), src2.getMinY());
   double x2 = Math.min(src1.getMaxX(), src2.getMaxX());
   double y2 = Math.min(src1.getMaxY(), src2.getMaxY());
   dest.setFrame(x1, y1, x2 - x1, y2 - y1);
 }
Example #3
0
 /**
  * Unions the pair of source <code>Rectangle2D</code> objects and puts the result into the
  * specified destination <code>Rectangle2D</code> object. One of the source rectangles can also be
  * the destination to avoid creating a third Rectangle2D object, but in this case the original
  * points of this source rectangle will be overwritten by this method.
  *
  * @param src1 the first of a pair of <code>Rectangle2D</code> objects to be combined with each
  *     other
  * @param src2 the second of a pair of <code>Rectangle2D</code> objects to be combined with each
  *     other
  * @param dest the <code>Rectangle2D</code> that holds the results of the union of <code>src1
  *     </code> and <code>src2</code>
  * @since 1.2
  */
 public static void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest) {
   double x1 = Math.min(src1.getMinX(), src2.getMinX());
   double y1 = Math.min(src1.getMinY(), src2.getMinY());
   double x2 = Math.max(src1.getMaxX(), src2.getMaxX());
   double y2 = Math.max(src1.getMaxY(), src2.getMaxY());
   dest.setFrameFromDiagonal(x1, y1, x2, y2);
 }
Example #4
0
 /**
  * Determines whether or not the specified <code>Object</code> is equal to this <code>Rectangle2D
  * </code>. The specified <code>Object</code> is equal to this <code>Rectangle2D</code> if it is
  * an instance of <code>Rectangle2D</code> and if its location and size are the same as this
  * <code>Rectangle2D</code>.
  *
  * @param obj an <code>Object</code> to be compared with this <code>Rectangle2D</code>.
  * @return <code>true</code> if <code>obj</code> is an instance of <code>Rectangle2D</code> and
  *     has the same values; <code>false</code> otherwise.
  * @since 1.2
  */
 public boolean equals(Object obj) {
   if (obj == this) {
     return true;
   }
   if (obj instanceof Rectangle2D) {
     Rectangle2D r2d = (Rectangle2D) obj;
     return ((getX() == r2d.getX())
         && (getY() == r2d.getY())
         && (getWidth() == r2d.getWidth())
         && (getHeight() == r2d.getHeight()));
   }
   return false;
 }
Example #5
0
 /**
  * {@inheritDoc}
  *
  * @since 1.2
  */
 public Rectangle2D createUnion(Rectangle2D r) {
   Rectangle2D dest;
   if (r instanceof Float) {
     dest = new Rectangle2D.Float();
   } else {
     dest = new Rectangle2D.Double();
   }
   Rectangle2D.union(this, r, dest);
   return dest;
 }
Example #6
0
 /**
  * Sets this <code>Rectangle2D</code> to be the same as the specified <code>Rectangle2D</code>.
  *
  * @param r the specified <code>Rectangle2D</code>
  * @since 1.2
  */
 public void setRect(Rectangle2D r) {
   setRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
 }
Example #7
0
 /**
  * {@inheritDoc}
  *
  * @since 1.2
  */
 public Rectangle2D createUnion(Rectangle2D r) {
   Rectangle2D dest = new Rectangle2D.Double();
   Rectangle2D.union(this, r, dest);
   return dest;
 }
Example #8
0
 /**
  * {@inheritDoc}
  *
  * @since 1.2
  */
 public Rectangle2D createIntersection(Rectangle2D r) {
   Rectangle2D dest = new Rectangle2D.Double();
   Rectangle2D.intersect(this, r, dest);
   return dest;
 }
Example #9
0
 /**
  * {@inheritDoc}
  *
  * @since 1.2
  */
 public void setRect(Rectangle2D r) {
   this.x = r.getX();
   this.y = r.getY();
   this.width = r.getWidth();
   this.height = r.getHeight();
 }