public void add(String label, Point2D point) { Rectangle2D.Double bounds = new Rectangle2D.Double(point.getX(), point.getY(), 0.0, 0.0); this.childMap.put(label, bounds); if (this.root == null) { this.root = new Rectangle2D.Double(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight()); } else { this.root.add(point); } }
private void drawTextBox(Graphics2D g2D, String text, int x0, int y0, Color color) { final FontMetrics fontMetrics = g2D.getFontMetrics(); final Rectangle2D textBounds = fontMetrics.getStringBounds(text, g2D); x0 -= textBounds.getWidth() / 2; textBounds.setRect(textBounds.getX() - 1, textBounds.getY(), textBounds.getWidth(), textBounds.getHeight()); Rectangle2D.Double r = new Rectangle2D.Double(x0 + textBounds.getX() - 2.0, y0 + textBounds.getY() - 2.0, textBounds.getWidth() + 4.0, textBounds.getHeight() + 4.0); if (r.getMaxX() > getWidth()) { r.setRect(getWidth() - r.getWidth(), r.getY(), r.getWidth(), r.getHeight()); } if (r.getMinX() < 0) { r.setRect(0, r.getY(), r.getWidth(), r.getHeight()); } if (r.getMaxY() > getHeight()) { r.setRect(r.getX(), getHeight() - r.getHeight(), r.getWidth(), r.getHeight()); } if (r.getMinY() < 0) { r.setRect(r.getX(), 0, r.getWidth(), r.getHeight()); } g2D.setColor(color); g2D.fill(r); g2D.setColor(Color.black); g2D.draw(r); g2D.drawString(text, x0, y0); }
private void drawTextBox(Graphics2D g2D, String text, int x0, int y0, Color color) { final FontMetrics fontMetrics = g2D.getFontMetrics(); final Rectangle2D textBounds = fontMetrics.getStringBounds(text, g2D); x0 -= textBounds.getWidth() / 2; textBounds.setRect(textBounds.getX() - 1, textBounds.getY(), textBounds.getWidth(), textBounds.getHeight()); Rectangle2D.Double r = new Rectangle2D.Double(x0 + textBounds.getX() - 2.0, y0 + textBounds.getY() - 2.0, textBounds.getWidth() + 4.0, textBounds.getHeight() + 4.0); if (r.getMaxX() > getWidth()) { r.setRect(getWidth() - r.getWidth(), r.getY(), r.getWidth(), r.getHeight()); } if (r.getMinX() < 0) { r.setRect(0, r.getY(), r.getWidth(), r.getHeight()); } if (r.getMaxY() > getHeight()) { r.setRect(r.getX(), getHeight() - r.getHeight(), r.getWidth(), r.getHeight()); } if (r.getMinY() < 0) { r.setRect(r.getX(), 0, r.getWidth(), r.getHeight()); } g2D.setColor(color); g2D.fill(r); g2D.setColor(Color.black); g2D.draw(r); g2D.drawString(text, x0, y0); }
final double minX = bounds.getMinX(); final double minY = bounds.getMinY(); final double midX = bounds.getCenterX();
final double minX = bounds.getMinX(); final double minY = bounds.getMinY(); final double midX = bounds.getCenterX();
final double minX = bounds.getMinX(); final double minY = bounds.getMinY(); final double midX = bounds.getCenterX();
void render( PointStyling styling, double x, double y ) { Point2D.Double p = (Point2D.Double) worldToScreen.transform( new Point2D.Double( x, y ), null ); x = p.x; y = p.y; Graphic g = styling.graphic; Rectangle2D.Double rect = rendererContext.fillRenderer.getGraphicBounds( g, x, y, styling.uom ); if ( g.image == null && g.imageURL == null ) { renderMark( g.mark, g.size < 0 ? 6 : round( rendererContext.uomCalculator.considerUOM( g.size, styling.uom ) ), styling.uom, rendererContext, rect.getMinX(), rect.getMinY(), g.rotation ); return; } BufferedImage img = g.image; // try if it's an svg if ( img == null && g.imageURL != null ) { img = rendererContext.svgRenderer.prepareSvg( rect, g ); } if ( img != null ) { // TODO: fix rotation if anchor point is not 0.5,0.5 - see org.deegree.rendering.r2d.Java2DRendererTest.testPointStyling() AffineTransform t = rendererContext.graphics.getTransform(); if ( !isZero( g.rotation ) ) { int rotationPointX = round( rect.x + rect.getWidth() * g.anchorPointX ); int rotationPointY = round( rect.y + rect.getHeight() * g.anchorPointY ); rendererContext.graphics.rotate( toRadians( g.rotation ), rotationPointX, rotationPointY ); } rendererContext.graphics.drawImage( img, round( rect.x ), round( rect.y ), round( rect.width ), round( rect.height ), null ); rendererContext.graphics.setTransform( t ); } }
new Point2D.Double(r.getMinX(), r.getMinY()), new Point2D.Double(r.getMaxX(), r.getMaxY()) );
public static Line2D.Double intersection(Line2D.Double line, Rectangle2D.Double bounds) { //line.x1, line.y1, line.x2, line.y2 Point2D.Double bottom = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMaxY(), bounds.getMaxX(), bounds.getMaxY()); Point2D.Double right = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMaxX(), bounds.getMaxY(), bounds.getMaxX(), bounds.getMinY()); Point2D.Double top = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMinY()); Point2D.Double left = computeSegmentIntersection(line.x1, line.y1, line.x2, line.y2, bounds.getMinX(), bounds.getMinY(), bounds.getMinX(), bounds.getMaxY()); ArrayList<Point2D.Double> pts = new ArrayList<Point2D.Double>(); if (bottom != null) { pts.add(bottom); } if (right != null) { pts.add(right); } if (top != null) { pts.add(top); } if (left != null) { pts.add(left); } if (pts.size() != 2) { return null; } else { return new Line2D.Double(pts.get(0), pts.get(1)); } }
@Override public Rectangle2D getBounds(Map<String,Object> map, MapTransform mt) throws ParameterException, IOException { Rectangle2D.Double bounds = source.updateCacheAndGetBounds(viewBox, map, mt, mimeType); double width = bounds.getWidth(); double height = bounds.getHeight(); AffineTransform at = null; if (transform != null) { at = transform.getGraphicalAffineTransform(false, map, mt, width, height); } // reserve the place for halo if (halo != null) { double r = halo.getHaloRadius(map, mt); width += 2 * r; height += 2 * r; double px = bounds.getMinX()-r; double py = bounds.getMinY()-r; bounds = new Rectangle2D.Double(px, py, width, height); } /* if (at != null) { // take into account AT return at.createTransformedShape(bounds).getBounds2D(); } else { return bounds; }*/ return bounds; }
private Rectangle2D getTextBox(final Graphics2D g2d, final String text, final int x0, final int y0) { final FontMetrics fontMetrics = g2d.getFontMetrics(); final Rectangle2D textBounds = fontMetrics.getStringBounds(text, g2d); Rectangle2D.Double r = new Rectangle2D.Double(x0 + textBounds.getX() - 2.0, y0 + textBounds.getY() - 2.0, textBounds.getWidth() + 4.0, textBounds.getHeight() + 4.0); if (r.getMaxX() > getWidth()) { r.setRect(getWidth() - r.getWidth(), r.getY(), r.getWidth(), r.getHeight()); } if (r.getMinX() < 0) { r.setRect(0, r.getY(), r.getWidth(), r.getHeight()); } if (r.getMaxY() > getHeight()) { r.setRect(r.getX(), getHeight() - r.getHeight(), r.getWidth(), r.getHeight()); } if (r.getMinY() < 0) { r.setRect(r.getX(), 0, r.getWidth(), r.getHeight()); } return r; }
@Override public void updateOverlay(final EllipseFigure figure, final OverlayView view) { super.updateOverlay(figure, view); final EllipseOverlay overlay = downcastOverlay(view.getData()); final Rectangle2D.Double bounds = figure.getBounds(); final double x = bounds.getMinX(); final double y = bounds.getMinY(); final double w = bounds.getWidth(); final double h = bounds.getHeight(); overlay.setOrigin(x + w / 2, 0); overlay.setOrigin(y + h / 2, 1); overlay.setRadius(w / 2, 0); overlay.setRadius(h / 2, 1); overlay.update(); toolService.reportRectangle(x, y, w, h); }
@Override public void updateOverlay(final RectangleFigure figure, final OverlayView view) { super.updateOverlay(figure, view); final RectangleOverlay overlay = downcastOverlay(view.getData()); final Rectangle2D.Double bounds = figure.getBounds(); final double x = bounds.getMinX(); final double y = bounds.getMinY(); final double w = bounds.getWidth(); final double h = bounds.getHeight(); overlay.setOrigin(x, 0); overlay.setOrigin(y, 1); overlay.setExtent(w, 0); overlay.setExtent(h, 1); overlay.update(); toolService.reportRectangle(x, y, w, h); }
public void moveTo(Double pos) { if (pos == null) { return; } //Get the bounds of the entire union Rectangle2D.Double bounds = this.getBounds(); //Calculate the translation that the entire union needs to undergo Point2D.Double offset = new Point2D.Double( pos.x - bounds.getMinX(), pos.y - bounds.getMinY() ); //Translating all subelements by that delta for (SVGPrimitive p : elements) { p.translate(offset); } this.bounds = null; }
public void moveTo(Double pos) { if (pos == null) { return; } //Get the bounds of the entire union Rectangle2D.Double bounds = this.getBounds(); //Calculate the translation that the entire union needs to undergo Point2D.Double offset = new Point2D.Double( pos.x - bounds.getMinX(), pos.y - bounds.getMinY() ); //Translating all subelements by that delta for (SVGPrimitive p : elements) { p.translate(offset); } this.bounds = null; }
@Test public void testCorrectBoundsIfNecessary_correction_negative_x() { final Rectangle2D.Double toCorrect = new Rectangle2D.Double(-185.499991, -90.0, 360.0, 180.0); RegionSelectableWorldMapPane.correctBoundsIfNecessary(toCorrect); assertEquals(-180.0, toCorrect.getMinX(), 1e-8); assertEquals(174.50000899999895, toCorrect.getMaxX(), 1e-8); assertEquals(-90.0, toCorrect.getMinY(), 1e-8); assertEquals(90.0, toCorrect.getMaxY(), 1e-8); assertTrue(toCorrect.getMinX() + toCorrect.getWidth() <= 180.0); assertTrue(toCorrect.getMinY() + toCorrect.getHeight() <= 90.0); } }
@Test public void testCorrectBoundsIfNecessary_noCorrection() { final Rectangle2D.Double toCorrect = new Rectangle2D.Double(-175.0, -85.0, 140.0, 110.0); RegionSelectableWorldMapPane.correctBoundsIfNecessary(toCorrect); assertEquals(-175.0, toCorrect.getMinX(), 1e-8); assertEquals(-85.0, toCorrect.getMinY(), 1e-8); assertEquals(-175.0 + 140.0, toCorrect.getMaxX(), 1e-8); assertEquals(-85.0 + 110.0, toCorrect.getMaxY(), 1e-8); }
@Test public void testCorrectBoundsIfNecessary_correction_positive_x() { final Rectangle2D.Double toCorrect = new Rectangle2D.Double(-175.499991, -90.0, 360.0, 180.0); RegionSelectableWorldMapPane.correctBoundsIfNecessary(toCorrect); assertEquals(-175.499991, toCorrect.getMinX(), 1e-8); assertEquals(180.0, toCorrect.getMaxX(), 1e-8); assertEquals(-90.0, toCorrect.getMinY(), 1e-8); assertEquals(90.0, toCorrect.getMaxY(), 1e-8); assertTrue(toCorrect.getMinX() + toCorrect.getWidth() <= 180.0); assertTrue(toCorrect.getMinY() + toCorrect.getHeight() <= 90.0); }