/** * 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()); }
/** * Snaps a geographic point to be on the region grid. * * <p>Moves the point given by X and Y to be on the grid of the supplied region. * * @param x the easting of the arbitrary point. * @param y the northing of the arbitrary point. * @param region the active window from which to take the grid. * @return the snapped coordinate. */ public static Coordinate snapToNextHigherInRegionResolution( double x, double y, JGrassRegion region) { double minx = region.getRectangle().getBounds2D().getMinX(); double ewres = region.getWEResolution(); double xsnap = minx + (Math.ceil((x - minx) / ewres) * ewres); double miny = region.getRectangle().getBounds2D().getMinY(); double nsres = region.getNSResolution(); double ysnap = miny + (Math.ceil((y - miny) / nsres) * nsres); return new Coordinate(xsnap, ysnap); }
/** * 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; }
JGrassRegion activeRegion, double x, double y) { double minx = activeRegion.getRectangle().getBounds2D().getMinX(); double ewres = activeRegion.getWEResolution(); double snapx = minx + (Math.round((x - minx) / ewres) * ewres); double miny = activeRegion.getRectangle().getBounds2D().getMinY(); double nsres = activeRegion.getNSResolution(); double snapy = miny + (Math.round((y - miny) / nsres) * nsres);
Rectangle2D applyMargins(int[] margin, Rectangle2D bounds) { if (bounds != null) { double xmin = bounds.getMinX() - margin[3]; double ymin = bounds.getMinY() - margin[0]; double width = bounds.getWidth() + margin[1] + margin[3]; double height = bounds.getHeight() + margin[0] + margin[2]; return new Rectangle2D.Double(xmin, ymin, width, height); } else { return bounds; } }
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; }
/** * Converts the Rectangle2D passed as parameter in a jts Geometry object * * @param r the rectangle to be converted * @return a geometry with the same vertices as the rectangle */ private Geometry rectangleToGeometry(Rectangle2D r) { return createRectangle(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); }
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); }
/** * Returns the explicitly defined bounds for this shape. If no bounds were explicitly set, it * delegates the call to the actual shape. * * @return the Rectangle representing the Shape's bounding box. * @see Shape */ public Rectangle getBounds() { if (bounds != null) return new Rectangle( (int) bounds.getMinX(), (int) bounds.getMinY(), (int) bounds.getWidth(), (int) bounds.getHeight()); return shape.getBounds(); }
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());
/** * Converts the Rectangle2D passed as parameter in a jts Geometry object * * @param r the rectangle to be converted * @return a geometry with the same vertices as the rectangle */ private Geometry rectangleToGeometry(Rectangle2D r) { return createRectangle(r.getMinX(), r.getMinY(), r.getWidth(), r.getHeight()); }
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);
/** Returns {@code true} if the two rectangles are equals up to an epsilon value. */ public static boolean equalsEpsilon(final Rectangle2D rect1, final Rectangle2D rect2) { double dx = 0.5 * Math.abs(rect1.getWidth() + rect2.getWidth()); double dy = 0.5 * Math.abs(rect1.getHeight() + rect2.getHeight()); if (dx > 0) dx *= EPS; else dx = EPS; if (dy > 0) dy *= EPS; else dy = EPS; return equalsEpsilon(rect1.getMinX(), rect2.getMinX(), dx) && equalsEpsilon(rect1.getMinY(), rect2.getMinY(), dy) && equalsEpsilon(rect1.getMaxX(), rect2.getMaxX(), dx) && equalsEpsilon(rect1.getMaxY(), rect2.getMaxY(), dy); }
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); }