/** * Fills the given {@link RectF} with the path bounds. * * @param bounds the RectF to be filled. */ public void fillBounds(RectF bounds) { Rectangle2D rect = mPath.getBounds2D(); bounds.left = (float) rect.getMinX(); bounds.right = (float) rect.getMaxX(); bounds.top = (float) rect.getMinY(); bounds.bottom = (float) rect.getMaxY(); }
@Override public void paint(Graphics g) { super.paint(g); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); g.setColor(Color.BLACK); g.drawRect(0, 0, width - 1, height - 1); g.drawRect(1, 1, width - 3, height - 3); // g.setColor(Color.RED); // final String status = done + "/" + total; // g.drawString(status, width / 2, height / 2); g.drawImage(logo, width - logo.getWidth() - 4, height - logo.getHeight() - 4, null); drawProgessBar(g, done.intValue(), total.intValue()); final int nbErrors = errors.get(); if (nbErrors > 0) { g.setColor(Color.RED); final String message = "" + nbErrors + (nbErrors > 1 ? " diagrams" : " diagram") + " contains errors"; g.drawString(message, 10, 20); } g.setColor(link); final String urllink = "http://plantuml.com"; final Rectangle2D rect = getUsed(g, urllink); g.drawString(urllink, 10, (int) (height - rect.getMaxY())); limY = (int) (height - rect.getMaxY() + rect.getMinY()); limX = (int) (10 + rect.getMaxX()); }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() call in * constructors"). */ private static MathTransform getMathTransform( final Rectangle gridRange, final Rectangle2D userRange) { final double scaleX = userRange.getWidth() / gridRange.getWidth(); final double scaleY = userRange.getHeight() / gridRange.getHeight(); final double transX = userRange.getMinX() - gridRange.x * scaleX; final double transY = userRange.getMaxY() + gridRange.y * scaleY; final AffineTransform tr = new AffineTransform(scaleX, 0, 0, -scaleY, transX, transY); tr.translate(0.5, 0.5); // Maps to pixel center return ProjectiveTransform.create(tr); }
public Rectangle2D drawMoleculeID(IAtomContainer atomContainer, Graphics2D g) { String id = atomContainer.getID(); if (id == null) { return null; } Rectangle2D moleculeBounds = GeometryTools.getRectangle2D((IAtomContainer) atomContainer); double labelCenterX = moleculeBounds.getCenterX(); double labelCenterY = moleculeBounds.getMaxY() + this.params.labelYGap; Point2f textPoint = this.getTextPoint(g, id, labelCenterX, labelCenterY); g.setFont(this.moleculeIDFont); g.setColor(Color.BLACK); g.drawString(id, textPoint.x, textPoint.y); Rectangle2D textBounds = this.getTextBounds(g, id); return new Rectangle2D.Double(labelCenterX - textBounds.getWidth() / 2.0, labelCenterY - textBounds.getHeight() / 2.0, textBounds.getWidth(), textBounds.getHeight()); } }
/** * Calculate vertical bounds common to all rendered glyphs. * * @param tableData * @param glyphIndex the table index that has glyphs. * @return an array with two elements: min lower bound (but max 0), and max upper bound (but min * 0). */ double[] getYBounds(Object[][] tableData, int glyphIndex) { double minY = 0; double maxY = 0; for (Object[] aTableData : tableData) { GeneralPath path = (GeneralPath) aTableData[glyphIndex]; Rectangle2D bounds2D = path.getBounds2D(); if (bounds2D.isEmpty()) { continue; } minY = Math.min(minY, bounds2D.getMinY()); maxY = Math.max(maxY, bounds2D.getMaxY()); } return new double[]{minY, maxY}; } }
private static Rectangle2D union(Rectangle2D src1, Rectangle2D src2) { 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()); Rectangle2D result = new Rectangle2D.Double(); result.setFrameFromDiagonal(x1, y1, x2, y2); return result; }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors"). */ private static MathTransform getMathTransform(final Rectangle gridRange, final Rectangle2D userRange) { final double scaleX = userRange.getWidth() / gridRange.getWidth(); final double scaleY = userRange.getHeight() / gridRange.getHeight(); final double transX = userRange.getMinX() - gridRange.x*scaleX; final double transY = userRange.getMaxY() + gridRange.y*scaleY; final AffineTransform tr = new AffineTransform(scaleX, 0, 0, -scaleY, transX, transY); tr.translate(0.5, 0.5); // Maps to pixel center return ProjectiveTransform.create(tr); }
/** * @return minimal bounds of this element */ @Override public Rectangle2D getMinimalBounds() { Rectangle2D selfMinimalBounds = super.getMinimalBounds(); double maxX = selfMinimalBounds.getWidth(); double maxY = selfMinimalBounds.getHeight(); for (Content content: getContents()) { Rectangle2D rect = content.getMinimalBounds(); maxX = Math.max(maxX, rect.getMaxX()); maxY = Math.max(maxY, rect.getMaxY()); } return new Rectangle2D.Double(getX(),getY(),maxX,maxY); }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors"). */ private static MathTransform getMathTransform(final Rectangle gridRange, final Rectangle2D userRange) { final double scaleX = userRange.getWidth() / gridRange.getWidth(); final double scaleY = userRange.getHeight() / gridRange.getHeight(); final double transX = userRange.getMinX() - gridRange.x*scaleX; final double transY = userRange.getMaxY() + gridRange.y*scaleY; final AffineTransform tr = new AffineTransform(scaleX, 0, 0, -scaleY, transX, transY); tr.translate(0.5, 0.5); // Maps to pixel center return ProjectiveTransform.create(tr); }
@Test public void testResize() throws Exception { TextOutline outline = new TextOutline("Cl", font); AtomSymbol symbol = new AtomSymbol(outline, Collections.<TextOutline> emptyList()); AtomSymbol transformed = symbol.resize(2, 2); Rectangle2D orgBounds = outline.getBounds(); Rectangle2D newBounds = transformed.getOutlines().get(0).getBounds2D(); assertThat(newBounds.getX(), closeTo(orgBounds.getX() - orgBounds.getWidth() / 2, 0.01)); assertThat(newBounds.getY(), closeTo(orgBounds.getY() - orgBounds.getHeight() / 2, 0.01)); assertThat(newBounds.getMaxX(), closeTo(orgBounds.getMaxX() + orgBounds.getWidth() / 2, 0.01)); assertThat(newBounds.getMaxY(), closeTo(orgBounds.getMaxY() + orgBounds.getHeight() / 2, 0.01)); }
static Point2D intersection(Rectangle2D rect, Point2D pt1, Point2D pt2) { Point2D p; p = intersection(new Point2D.Double(rect.getMinX(), rect.getMinY()), new Point2D.Double(rect.getMaxX(), rect.getMinY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMinX(), rect.getMaxY()), new Point2D.Double(rect.getMaxX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMinX(), rect.getMinY()), new Point2D.Double(rect.getMinX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } p = intersection(new Point2D.Double(rect.getMaxX(), rect.getMinY()), new Point2D.Double(rect.getMaxX(), rect.getMaxY()), pt1, pt2); if (p != null) { return p; } return null; }
final Rectangle getImageSourceArea() { Assert.notNull(image); Assert.notNull(imageDataBounds); final ValueAxis xAxis = getDomainAxis(); final ValueAxis yAxis = getRangeAxis(); final double scaleX = image.getWidth() / imageDataBounds.getWidth(); final double scaleY = image.getHeight() / imageDataBounds.getHeight(); final int x = crop(scaleX * (xAxis.getLowerBound() - imageDataBounds.getMinX()), 0, image.getWidth() - 1); final int y = crop(scaleY * (imageDataBounds.getMaxY() - yAxis.getUpperBound()), 0, image.getHeight() - 1); final int w = crop(scaleX * (xAxis.getUpperBound() - xAxis.getLowerBound()), 1, image.getWidth()); final int h = crop(scaleY * (yAxis.getUpperBound() - yAxis.getLowerBound()), 1, image.getHeight()); return new Rectangle(x, y, w, h); }
public LineRectIntersection(Line2D line, Rectangle2D rect) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); final Point2D inter1 = new LineSegmentIntersection(new Line2D.Double(p1, p2), line).getIntersection(); final Point2D inter2 = new LineSegmentIntersection(new Line2D.Double(p2, p3), line).getIntersection(); final Point2D inter3 = new LineSegmentIntersection(new Line2D.Double(p3, p4), line).getIntersection(); final Point2D inter4 = new LineSegmentIntersection(new Line2D.Double(p4, p1), line).getIntersection(); final Point2D o = line.getP1(); inter = getCloser(o, inter1, inter2, inter3, inter4); }
final Rectangle getImageSourceArea() { Assert.notNull(image); Assert.notNull(imageDataBounds); final ValueAxis xAxis = getDomainAxis(); final ValueAxis yAxis = getRangeAxis(); final double scaleX = image.getWidth() / imageDataBounds.getWidth(); final double scaleY = image.getHeight() / imageDataBounds.getHeight(); final int x = crop(scaleX * (xAxis.getLowerBound() - imageDataBounds.getMinX()), 0, image.getWidth() - 1); final int y = crop(scaleY * (imageDataBounds.getMaxY() - yAxis.getUpperBound()), 0, image.getHeight() - 1); final int w = crop(scaleX * (xAxis.getUpperBound() - xAxis.getLowerBound()), 1, image.getWidth()); final int h = crop(scaleY * (yAxis.getUpperBound() - yAxis.getLowerBound()), 1, image.getHeight()); return new Rectangle(x, y, w, h); }
Point2D inter = null; if (in.getX() > rect.getMinX() && in.getX() < rect.getMaxX()) { if (in.getY() < rect.getMinY()) { inter = new Point2D.Double(in.getX(), rect.getMinY()); } else if (in.getY() > rect.getMaxY()) { inter = new Point2D.Double(in.getX(), rect.getMaxY()); } else { throw new IllegalArgumentException(); } else if (in.getY() > rect.getMinY() && in.getY() < rect.getMaxY()) { if (in.getX() < rect.getMinX()) { inter = new Point2D.Double(rect.getMinX(), in.getY()); } else if (in.getX() > rect.getMaxX()) { inter = new Point2D.Double(rect.getMaxX(), in.getY()); } else { throw new IllegalArgumentException(); final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
final double ww = bounds.getMaxX() - bounds.getMinX(); final double hh = bounds.getMaxY() - bounds.getMinY(); final Graphics2D gg = destination.createGraphics(); gg.scale(dpiFactor, dpiFactor); gg.translate(deltaShadow - bounds.getMinX(), deltaShadow - bounds.getMinY()); final boolean isLine = shape instanceof Line2D.Double; if (isLine) { final AffineTransform at = g2d.getTransform(); g2d.scale(1 / dpiFactor, 1 / dpiFactor); g2d.drawImage(destination, (int) (bounds.getMinX() * dpiFactor), (int) (bounds.getMinY() * dpiFactor), null); g2d.setTransform(at);
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { // Log.println("rect x=" + rect.getX() + " y=" + rect.getY() + " w=" + rect.getWidth() + " h=" // + rect.getHeight()); // Log.println("tangeante (" + tangeante.getX1() + "," + tangeante.getY1() + ") (" + tangeante.getX2() // + "," + tangeante.getY2() + ")"); final DotPath result = new DotPath(); // final Point2D inter = BezierUtils.intersect((Line2D.Double) // tangeante, rect); Point2D inter = new LineRectIntersection(tangeante, rect).getIntersection(); // Log.println("inter=" + inter); if (inter == null) { final Point2D p1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); final Point2D p2 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); final Point2D p3 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); final Point2D p4 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); inter = LineRectIntersection.getCloser(tangeante.getP1(), p1, p2, p3, p4); } final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante.getX1(), tangeante.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }