List of usage examples for java.awt.geom Rectangle2D union
public static void union(Rectangle2D src1, Rectangle2D src2, Rectangle2D dest)
From source file:Main.java
/** * Get the full screen size recognizing multiple monitor. * // w ww . j a v a 2 s . c om * @return full screen size */ public static Dimension getFullScreenSize() { Rectangle2D result = new Rectangle2D.Double(); GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice gd : localGE.getScreenDevices()) { for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) { Rectangle2D.union(result, graphicsConfiguration.getBounds(), result); } } return new Dimension((int) result.getWidth(), (int) result.getHeight()); }
From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java
/** * This creates a new box that represents the area shared by two boxes. * /* ww w .j av a 2s .c om*/ * @param A * a box to intersect * @param B * a box to intersect * @return a new bbox consisting solely of the shared region. */ public static BoundingBox intersection(BoundingBox A, BoundingBox B) { BoundingBox solution = new BoundingBox(); //If we know this is going nowhere, bail if (!A.rect.intersects(B.rect)) return solution; solution.rect = null; // The hard case -- two composed Bounding Boxes if (A.composed && B.composed) { solution.pieces = new LinkedList(); solution.composed = true; Iterator iterA = A.pieces.iterator(); while (iterA.hasNext()) { BoundingBox aBox = (BoundingBox) iterA.next(); Iterator iterB = B.pieces.iterator(); while (iterB.hasNext()) { BoundingBox bBox = (BoundingBox) iterB.next(); assert !aBox.composed && !bBox.composed : "BoundingBox wasn't flattened."; if (aBox.intersects(bBox)) { BoundingBox newBox = new BoundingBox((Rectangle) aBox.rect.createIntersection(bBox.rect)); if (solution.rect == null) { solution.rect = (Rectangle) newBox.rect.clone(); } else { Rectangle2D.union(solution.rect, newBox.rect, solution.rect); } solution.pieces.add(newBox); } } } solution.simplify(); } else if (A.composed || B.composed) { // Now handle the case where one is composed. BoundingBox uncomposedBox = (A.composed ? B : A); BoundingBox composedBox = (A.composed ? A : B); solution.pieces = new LinkedList(); solution.composed = true; Iterator iter = composedBox.pieces.iterator(); while (iter.hasNext()) { BoundingBox child = (BoundingBox) iter.next(); assert !child.composed : "BoundingBox wasn't flattened."; if (child.rect.intersects(uncomposedBox.rect.x, uncomposedBox.rect.y, uncomposedBox.rect.width, uncomposedBox.rect.height)) { BoundingBox newBox = new BoundingBox( (Rectangle) child.rect.createIntersection(uncomposedBox.rect)); if (solution.rect == null) { solution.rect = (Rectangle) newBox.rect.clone(); } else { Rectangle2D.union(solution.rect, newBox.rect, solution.rect); } solution.pieces.add(newBox); } } solution.simplify(); } else { // The easy case. if (A.rect.intersects(B.rect.x, B.rect.y, B.rect.width, B.rect.height)) { solution.rect = (Rectangle) A.rect.createIntersection(B.rect); solution.initPoly(); } else { solution.rect = new Rectangle(); } } return solution; }
From source file:org.caleydo.view.domino.internal.Block.java
private Shape getOutlineShape() { if (this.nodeCount() == 1) return nodes().iterator().next().getRectangleBounds(); if (linearBlocks.size() == 1) { LinearBlock b = linearBlocks.get(0); Rect r1 = b.getNode(true).getRectBounds(); Rect r2 = b.getNode(false).getRectBounds(); Rectangle2D.Float r = new Rectangle2D.Float(); Rectangle2D.union(r1.asRectangle2D(), r2.asRectangle2D(), r); return r; }/* ww w . j a v a 2 s. c o m*/ Collection<Vec2f> outline = getOutline(); Polygon r = new Polygon(); for (Vec2f p : outline) r.addPoint((int) p.x(), (int) p.y()); return r; }
From source file:org.zanata.util.TestEventForScreenshotListener.java
private Rectangle getScreenRectangle() { // http://stackoverflow.com/a/13380999/14379 Rectangle2D result = new Rectangle2D.Double(); GraphicsEnvironment localGE = GraphicsEnvironment.getLocalGraphicsEnvironment(); for (GraphicsDevice gd : localGE.getScreenDevices()) { for (GraphicsConfiguration graphicsConfiguration : gd.getConfigurations()) { Rectangle2D.union(result, graphicsConfiguration.getBounds(), result); }/*w ww .ja va2s . c o m*/ } return new Rectangle((int) result.getWidth(), (int) result.getHeight()); }