Example #1
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 #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
 /**
  * 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);
 }