public static Area enlargeSlightlyInPlace(Area area, float scale) { AffineTransform aLittleLarger = new AffineTransform(); double centerX = area.getBounds2D().getCenterX(); double centerY = area.getBounds2D().getCenterY(); aLittleLarger.translate(centerX, centerY); aLittleLarger.scale(scale, scale); aLittleLarger.translate(-centerX, -centerY); area.transform(aLittleLarger); return area; }
public Display(String title, int width, int height, Area area) { this(title, width, height); double scaleX = (width * 0.9) / area.getBounds().getWidth(); double scaleY = (height * 0.9) / area.getBounds().getHeight(); double scale = Math.min(scaleX, scaleY); AffineTransform affineTransform = new AffineTransform(); affineTransform.translate(width / 2, height / 2); affineTransform.scale(scale, scale); affineTransform.translate(-area.getBounds2D().getCenterX(), -area.getBounds2D().getCenterY()); area.transform(affineTransform); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.fill(area); this.bufferedImage = image; }
Rectangle2D clipRect = clip.getBounds2D(); if (clipRect.isEmpty()) Rectangle2D bounds = dpiTransform.createTransformedShape(clip.getBounds2D()).getBounds2D();
public Rectangle2D getBounds2D() { return new Area(this).getBounds2D(); }
private double intersectAndGetOverlapWidth(Glyphs gv, int i) { return getIntesection(gv, i).getBounds2D().getWidth(); }
/** * Report the bounding box of the staff area. * * @return the lazily computed bounding box */ public Rectangle2D getAreaBounds () { return getArea().getBounds2D(); }
public Point2D getCenterPoint() { if (centerPoint == null) { Area path = getPath(); Rectangle2D bounds = path.getBounds2D(); centerPoint = new Point2D.Double(bounds.getX() + bounds.getWidth() / 2.0, bounds.getY() + bounds.getHeight() / 2.0); } return centerPoint; }
@Override public Rectangle2D getBounds(AffineTransform transform) { return getArea(transform).getBounds2D(); }
@Override public Rectangle2D getBounds2DX() { return new Rectangle2DD(super.getBounds2D()); }
/** * Ugly version to find a random point which stand within the area * @param area * @return */ private Point2D.Double findMarkPosition(Area area) { Rectangle2D bounds2D = area.getBounds2D(); for (int i = 0; i < MAX_ATTEMPT; i++) { double x = rand.nextDouble() * bounds2D.getWidth() + bounds2D.getMinX(); double y = rand.nextDouble() * bounds2D.getHeight() + bounds2D.getMinY(); if (area.contains(x, y)) { return new Point2D.Double(x, y); } } return null; }
protected Collection<java.awt.geom.Point2D> getIntersections(java.awt.geom.Line2D line, Area shape) { Area intersectionArea = new Area(getLineShape(line)); intersectionArea.intersect(shape); if (!intersectionArea.isEmpty()) { Rectangle2D bounds2D = intersectionArea.getBounds2D(); HashSet<java.awt.geom.Point2D> intersections = new HashSet<>(1); intersections.add(new java.awt.geom.Point2D.Double(bounds2D.getX(), bounds2D.getY())); return intersections; } return Collections.EMPTY_SET; }
/** * Returns the minimal y coordinate at which the specified * Rectangle2D.Double can be located so that is has x-coordinate 'x' and * does not intersect with the specified Area. */ private double getMinimalYCoordinate(Rectangle2D.Double boundingBox, double x, Area area) { double middle; // initialize interval bounds double low = 0.0; double high = area.getBounds2D().getMaxY(); // narrow the interval bounds until the optimal point is found // (a kind of binary search) while (high - low > 1.0) { middle = (low + high) / 2.0; if (area.intersects(x, middle, boundingBox.width, boundingBox.height)) { low = middle; } else { high = middle; } } return Math.floor(high); // "floor" works better than "ceil", although "ceil" is // conceptually the best choice. The problem lies in the "> // 1.0", which sometimes results in graphs getting a minimal y // coordinate which appear to be 1 pixel too much. }
public boolean intersects(JLabel testa, JLabel testb){ Area areaA = new Area(testa.getBounds()); Area areaB = new Area(testb.getBounds()); return areaA.intersects(areaB.getBounds2D()); }
@Override public Rectangle2D getBoundingBox() { if (this.getArea() == null) { return super.getBoundingBox(); } return this.getArea().getBounds2D(); }
public void paintComponent(Graphics g) { if (started) { int width = getWidth(); double maxY = 0.0; Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(hints); g2.setColor(new Color(255, 255, 255, (int) (alphaLevel * shield))); g2.fillRect(0, 0, getWidth(), getHeight()); for (int i = 0; i < ticker.length; i++) { int channel = 224 - 128 / (i + 1); g2.setColor(new Color(channel, channel, channel, alphaLevel)); g2.fill(ticker[i]); Rectangle2D bounds = ticker[i].getBounds2D(); if (bounds.getMaxY() > maxY) maxY = bounds.getMaxY(); } if (text != null && text.length() > 0) { FontRenderContext context = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, getFont(), context); Rectangle2D bounds = layout.getBounds(); g2.setColor(getForeground()); layout.draw(g2, (float) (width - bounds.getWidth()) / 2, (float) (maxY + layout.getLeading() + 2 * layout.getAscent())); } } }
public static PathShape combineROIs(PathShape shape1, PathShape shape2, CombineOp op, double flatness) { // Check we can combine if (!ROIHelpers.sameImagePlane(shape1, shape2)) throw new IllegalArgumentException("Cannot combine - shapes " + shape1 + " and " + shape2 + " do not share the same image plane"); Area area1 = getArea(shape1); Area area2 = getArea(shape2); // Do a quick check to see if a combination might be avoided if (op == CombineOp.INTERSECT) { if (area1.contains(area2.getBounds2D())) return shape2; if (area2.contains(area1.getBounds2D())) return shape1; } else if (op == CombineOp.ADD) { if (area1.contains(area2.getBounds2D())) return shape1; if (area2.contains(area1.getBounds2D())) return shape2; } combineAreas(area1, area2, op); // I realise the following looks redundant... however direct use of the areas with the // brush tool led to strange artefacts appearing & disappearing... performing an additional // conversion seems to help // area1 = new Area(new Path2D.Float(area1)); // Return simplest ROI that works - prefer a rectangle or polygon over an area return getShapeROI(area1, shape1.getC(), shape1.getZ(), shape1.getT(), flatness); }
/** * This outlines the area visible to the token under the cursor, clipped to * the current fog-of-war. This is appropriate for the player view, but the * GM sees everything. */ private void renderPlayerVisionOverlay(Graphics2D g, PlayerView view) { Graphics2D g2 = (Graphics2D) g.create(); if (zone.hasFog()) { Area clip = new Area(new Rectangle(getSize().width, getSize().height)); Area viewArea = new Area(exposedFogArea); List<Token> tokens = view.getTokens(); if (tokens != null && !tokens.isEmpty()) { for (Token tok : tokens) { ExposedAreaMetaData exposedMeta = zone.getExposedAreaMetaData(tok.getExposedAreaGUID()); viewArea.add(exposedMeta.getExposedAreaHistory()); } } if (!viewArea.isEmpty()) { clip.intersect(new Area(viewArea.getBounds2D())); } // Note: the viewArea doesn't need to be transform()'d because exposedFogArea has been already. g2.setClip(clip); } renderVisionOverlay(g2, view); g2.dispose(); }
ticker[i].transform(toCenter); g2.fill(ticker[i]); Rectangle2D bounds = ticker[i].getBounds2D(); if (bounds.getMaxY() > maxY) maxY = bounds.getMaxY();
height))); if (!a2.isEmpty()) { r = a2.getBounds2D(); newBound = new Bound( r.getMaxX(),
Rectangle2D bounds = area.getBounds2D(); return new RectangleROI(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), c, z, t);