java.awt.geom.Rectangle2D#createUnion ( )源码实例Demo

下面列出了java.awt.geom.Rectangle2D#createUnion ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: AndroidDesignPreview   文件: Proofer.java
public ProoferClient() {
    try {
        this.robot = new Robot();
    } catch (AWTException e) {
        System.err.println("Error getting robot.");
        e.printStackTrace();
        System.exit(1);
    }

    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screenDevices = environment.getScreenDevices();

    Rectangle2D tempBounds = new Rectangle();
    for (GraphicsDevice screenDevice : screenDevices) {
        tempBounds = tempBounds.createUnion(
                screenDevice.getDefaultConfiguration().getBounds());
    }
    screenBounds = tempBounds.getBounds();
}
 
源代码2 项目: PyramidShader   文件: LineString.java
@Override
public Rectangle2D getBoundingBox() {

    //Returns null if linePoints ArrayList does not have any points
    if (points.size() < 1) {
        return null;
    }

    //Retrieves bounding box of first point of line
    Point firstPoint = getPointN(0);
    //Assign bounding box to variable
    Rectangle2D bb = firstPoint.getBoundingBox();
    //Iterate over remaining points and retrieve bounding boxes
    for (Point point : points) {
        //creates new bounding box that includes previous points and current point
        bb = bb.createUnion(point.getBoundingBox());
    }
    return bb;
}
 
源代码3 项目: openchemlib-js   文件: ChemistryHelper.java
public static Rectangle2D.Double getDiffRect(Rectangle2D rr, Rectangle2D rp)
    {
        if (rr != null && rp != null) {
            Rectangle2D union = rr.createUnion(rp);
            double y = union.getMinY();
            double rx = rr.getMaxX();
            double px = rp.getMinX();
            double ry = union.getMinY();
            double py = union.getMaxY();
            Rectangle2D.Double res = new Rectangle2D.Double(
                rx < px ? rx : px,
                ry < py ? ry : py,
                Math.abs(px - rx),
                Math.abs(py - ry));
//            System.out.println("getDiffRect (1)" + rr);
//            System.out.println("getDiffRect (2)" + rp);
//            System.out.println("getDiffRect (out)" + res);
            return res;
        } else {
            return null;
        }
    }
 
源代码4 项目: openchemlib-js   文件: ChemistryHelper.java
public static Rectangle2D getBoundingRect(ExtendedMolecule[] mols)
{
    if (mols == null || mols.length == 0) {
        return new Rectangle2D.Double(0,0,0,0);
    }

    Rectangle2D r = getBoundingRect(mols[0]);
    for (int i = 1; i < mols.length; i++) {
        Rectangle2D t = getBoundingRect(mols[i]);
        if (t != null) {
            if (r == null)
                r = t;
            else
                r = r.createUnion(getBoundingRect(mols[i]));
        }
    }
    if (r == null)
        r = new Rectangle2D.Double(0,0,0,0);
    return r;
}
 
源代码5 项目: openstock   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码6 项目: maze-harvester   文件: SegmentSorter.java
public Rectangle2D getBounds() {
  Rectangle2D boundingBox = null;
  for (Color color : collector.getColors()) {
    for (Line2D seg : collector.getSegments(color)) {
      Rectangle2D shapeBox = seg.getBounds2D();
      if (boundingBox == null) {
        boundingBox = shapeBox;
      }
      boundingBox = boundingBox.createUnion(shapeBox);
    }
  }
  return boundingBox;
}
 
源代码7 项目: ccu-historian   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码8 项目: pumpernickel   文件: LayoutPaintable.java
/**
 * Creates a LayoutPaintable.
 * 
 * @param width
 *            the width of this entire Paintable. This must be greater than
 *            the rightmost edge of all inner cells.
 * @param height
 *            the height of this entire Paintable. This must be greater than
 *            the bottom-most edge of all inner cells.
 * @param rects
 *            an array of cell bounds. Negative widths and heights are used
 *            to indicate a cell should be flipped horizontally/vertically.
 * @param cells
 *            an array of cells, each element corresponding to the previous
 *            array of destination rectangles.
 * @param scaleProportionally
 *            whether each paintable should be scaled to full fit the cell
 *            bounds, or whether it should be scaled proportionally. It is
 *            recommended this value be true, although this may result in
 *            "dead space" in each cell.
 */
LayoutPaintable(int width, int height, Rectangle2D[] rects,
		Paintable[] cells, boolean scaleProportionally) {
	if (rects.length != cells.length)
		throw new IllegalArgumentException("the number of rects ("
				+ rects.length + ") must equal the number of cells ("
				+ cells.length + ")");

	this.width = width;
	this.height = height;
	this.rects = new Rectangle2D[rects.length];
	this.cells = new Paintable[rects.length];
	this.scaleProportionally = scaleProportionally;
	System.arraycopy(rects, 0, this.rects, 0, rects.length);
	System.arraycopy(cells, 0, this.cells, 0, rects.length);

	Rectangle2D sum = null;
	for (int a = 0; a < rects.length; a++) {
		if (sum == null) {
			sum = new Rectangle2D.Double(rects[a].getX(), rects[a].getY(),
					rects[a].getWidth(), rects[a].getHeight());
		} else {
			sum = sum.createUnion(rects[a]);
		}
	}
	if (sum.getX() + sum.getWidth() > width
			|| sum.getY() + sum.getHeight() > height) {
		for (int a = 0; a < rects.length; a++) {
			System.err.println("rects[" + a + "] = " + rects[a]);
		}
		throw new IllegalArgumentException(
				"the width and height specified ("
						+ width
						+ "x"
						+ height
						+ ") do not enclose the sum of all the cell bounds ( "
						+ sum + " )");
	}
}
 
源代码9 项目: SIMVA-SoS   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码10 项目: gama   文件: Group.java
/**
 * Recalculates the bounding box by taking the union of the bounding boxes of all children. Caches the result.
 */
public void calcBoundingBox() throws SVGException {
	// Rectangle2D retRect = new Rectangle2D.Float();
	Rectangle2D retRect = null;

	for (final Object element : children) {
		final SVGElement ele = (SVGElement) element;

		if (ele instanceof RenderableElement) {
			final RenderableElement rendEle = (RenderableElement) ele;
			final Rectangle2D bounds = rendEle.getBoundingBox();
			if (bounds != null) {
				if (retRect == null) {
					retRect = bounds;
				} else {
					retRect = retRect.createUnion(bounds);
				}
			}
		}
	}

	// If no contents, use degenerate rectangle
	if (retRect == null) {
		retRect = new Rectangle2D.Float();
	}

	boundingBox = boundsToParent(retRect);
}
 
源代码11 项目: ECG-Viewer   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码12 项目: astor   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码13 项目: astor   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is 
 * determined by the bounds of the shape and/or line drawn to represent 
 * the series.
 * 
 * @param g2  the graphics device.
 * 
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码14 项目: opensim-gui   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is 
 * determined by the bounds of the shape and/or line drawn to represent 
 * the series.
 * 
 * @param g2  the graphics device.
 * 
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码15 项目: PyramidShader   文件: GeometryCollection.java
@Override
public Rectangle2D getBoundingBox() {
    if (geometryList.size() < 1) {
        return null;
    }
    Geometry firstGeom = getGeometryN(0);
    Rectangle2D bb = firstGeom.getBoundingBox();

    for (Geometry geometry : geometryList) {
        bb = bb.createUnion(geometry.getBoundingBox());
    }
    return bb;
}
 
源代码16 项目: openchemlib-js   文件: ChemistryHelper.java
public static Rectangle2D getProductsBoundingRect(Reaction r)
{
    if (r == null)
        throw new NullPointerException("Cannot pass null reaction");
    int rn = r.getProducts();
    Rectangle2D rc = null;
    for (int i = 0; i < rn; i++) {
        Rectangle2D rt = getBoundingRect(r.getProduct(i));
        if (rc != null && rt != null)
            rc = rc.createUnion(rt);
        else
            rc = rt;
    }
    return rc;
}
 
源代码17 项目: buffer_bci   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码18 项目: buffer_bci   文件: LegendGraphic.java
/**
 * Performs the layout with no constraint, so the content size is
 * determined by the bounds of the shape and/or line drawn to represent
 * the series.
 *
 * @param g2  the graphics device.
 *
 * @return  The content size.
 */
protected Size2D arrangeNN(Graphics2D g2) {
    Rectangle2D contentSize = new Rectangle2D.Double();
    if (this.line != null) {
        contentSize.setRect(this.line.getBounds2D());
    }
    if (this.shape != null) {
        contentSize = contentSize.createUnion(this.shape.getBounds2D());
    }
    return new Size2D(contentSize.getWidth(), contentSize.getHeight());
}
 
源代码19 项目: pumpernickel   文件: DemoPaintable.java
/**
 * Paint a demo paintable.
 * 
 * @param g
 *            the Graphics2D to paint to.
 * @param width
 *            the width of the painted area
 * @param height
 *            the height of the painted area
 * @param colors
 *            two colors to paint in a checkerboard pattern on the
 *            background
 * @param id
 *            text to paint in dark gray in the center
 */
public static void paint(Graphics2D g, int width, int height,
		Color[] colors, String id) {
	if (colors == null)
		colors = DemoPaintable.colors;

	if (colors.length == 2) {
		g.setColor(colors[0]);
		g.fillRect(0, 0, width / 2, height / 2);
		g.setColor(colors[1]);
		g.fillRect(width / 2, 0, width / 2, height / 2);
		g.setColor(colors[1]);
		g.fillRect(0, height / 2, width / 2, height / 2);
		g.setColor(colors[0]);
		g.fillRect(width / 2, height / 2, width / 2, height / 2);
	} else {
		g.setColor(colors[(id.hashCode() + 0) % colors.length]);
		g.fillRect(0, 0, width / 2, height / 2);
		g.setColor(colors[(id.hashCode() + 1) % colors.length]);
		g.fillRect(width / 2, 0, width / 2, height / 2);
		g.setColor(colors[(id.hashCode() + 2) % colors.length]);
		g.fillRect(0, height / 2, width / 2, height / 2);
		g.setColor(colors[(id.hashCode() + 3) % colors.length]);
		g.fillRect(width / 2, height / 2, width / 2, height / 2);
	}

	// When testing printing, we should allow for
	// double-digit numbers, so let's make sure "MM" can fit
	GlyphVector maxGv = font.createGlyphVector(frc, "MM");
	Shape maxShape = maxGv.getOutline();
	GeneralPath maxPath = new GeneralPath(maxShape);
	Rectangle2D maxR = ShapeBounds.getBounds(maxPath.getPathIterator(null),
			null);

	GlyphVector gv = font.createGlyphVector(frc, id);
	Shape shape = gv.getOutline();
	GeneralPath path = new GeneralPath(shape);
	Rectangle2D r = ShapeBounds.getBounds(path.getPathIterator(null), null);

	maxR = maxR.createUnion(r); // in case we're not testing printing
								// anymore

	AffineTransform magnify = createAffineTransform(maxR,
			new Rectangle2D.Double(0, 0, width, height));
	// don't stretch the text to fill the page:
	// instead stretch it to fill the page proportionally

	double zoom = Math.min(magnify.getScaleX(), magnify.getScaleY());
	zoom = zoom * .8; // add some padding on the sides
	magnify = createAffineTransform(r,
			new Rectangle2D.Double(width / 2 - r.getWidth() / 2 * zoom,
					height / 2 - r.getHeight() / 2 * zoom, r.getWidth()
							* zoom, r.getHeight() * zoom));

	path.transform(magnify);

	g.setColor(Color.darkGray);
	g.fill(path);
}
 
源代码20 项目: importer-exporter   文件: BBoxSelectionPainter.java
private Rectangle2D createGeoRectangle(GeoPosition southWest, GeoPosition northEast) {
	Rectangle2D tmp = new Rectangle2D.Double(southWest.getLatitude(), southWest.getLongitude(), 0, 0);
	tmp = tmp.createUnion(new Rectangle2D.Double(northEast.getLatitude(), northEast.getLongitude(), 0, 0));

	return tmp;
}