/** * This method calculates ellipse intersection with line * @param shape Bounds of this shape used to calculate parameters of inscribed into this bounds ellipse. * @param line * @return Intersection point */ private static Point getEllipseIntersection(Shape shape, Line2D.Double line) { double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); double x = shape.getBounds2D().getWidth() / 2 * Math.cos(angle) + shape.getBounds2D().getCenterX(); double y = shape.getBounds2D().getHeight() / 2 * Math.sin(angle) + shape.getBounds2D().getCenterY(); Point p = new Point(); p.setLocation(x, y); return p; }
public static Rectangle2D getAnchor(Graphics2D graphics, Rectangle2D anchor) { if(graphics == null) { return anchor; } AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); if(tx != null && !tx.isIdentity() && tx.createTransformedShape(anchor) != null) { anchor = tx.createTransformedShape(anchor).getBounds2D(); } return anchor; }
public ShapeStroke(Shape shape, float width, float advance, float phase) { this.advance = advance; this.phase = phase; Rectangle2D bounds = shape.getBounds2D(); double scale = width / bounds.getHeight(); t.setToScale(scale, scale); t.translate(-bounds.getCenterX(), -bounds.getCenterY()); this.theShape = t.createTransformedShape(shape); }
double x2 = anchor.getX() + anchor.getWidth(), y2 = anchor.getY() + anchor.getHeight(); double alpha = Math.atan(anchor.getHeight() / anchor.getWidth()); p = new Path(); tailShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY); bounds = tailShape.getBounds2D(); at.translate(x2 - bounds.getWidth() / 2, y2 - bounds.getHeight() / 2); at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2); break; case STEALTH: tailShape = at.createTransformedShape(tailShape);
final Rectangle2D anchorO = tx.createTransformedShape(shapeAnchor).getBounds2D(); anchorT = txs2.createTransformedShape(shapeAnchor).getBounds2D(); final double scaleX2 = safeScale(anchorO.getWidth(), anchorT.getWidth()); final double scaleY2 = safeScale(anchorO.getHeight(), anchorT.getHeight()); txs2.translate(-centerX, -centerY); normalizedShape = txs2.createTransformedShape(shapeAnchor).getBounds2D(); final java.awt.Shape anc = tx.createTransformedShape(normalizedShape); return (anc != null) ? anc.getBounds2D() : normalizedShape;
public static Shape translateShape(final Shape shape, final Point2D newLocation) { final AffineTransform t = new AffineTransform(); t.translate(-shape.getBounds2D().getX(), -shape.getBounds2D().getY()); t.translate(newLocation.getX(), newLocation.getY()); return t.createTransformedShape(shape); }
double x1 = anchor.getX(), y1 = anchor.getY(); double alpha = Math.atan(anchor.getHeight() / anchor.getWidth()); p = new Path(); headShape = new Ellipse2D.Double(0, 0, lineWidth * scaleX, lineWidth * scaleY); bounds = headShape.getBounds2D(); at.translate(x1 - bounds.getWidth() / 2, y1 - bounds.getHeight() / 2); at.rotate(alpha, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2); break; case STEALTH: headShape = at.createTransformedShape(headShape);
/** * Builds a new transformed icon * * @param icon The icon to be rescaled * @param transformation The icon transformation */ public TransformedIcon(Icon icon, AffineTransform at) { this.icon = icon; this.at = at; Rectangle2D bounds = new Rectangle2D.Double(0, 0, icon.getIconWidth(), icon.getIconHeight()); bounds = at.createTransformedShape(bounds).getBounds2D(); this.width = (int) Math.round(bounds.getWidth()); this.height = (int) Math.round(bounds.getHeight()); }
r = bounds.getBounds2D(); r.add(r.getMaxX() + r.getWidth()/2, r.getCenterY()); r.add(r.getMinX() - r.getWidth()/2, r.getCenterY()); r.add(r.getCenterX(), r.getMinY() - r.getHeight()/2); r.add(r.getCenterX(), r.getMaxX() + r.getHeight()/2);
public boolean process(GlyphVector glyphVector, int g, AffineTransform tx, char c) { if (Character.isWhitespace(c)) return false; painter.graphics.draw( tx.createTransformedShape(glyphVector.getGlyphOutline(g)).getBounds2D()); return true; } }
pieBounds.getX() + pieBounds.getWidth() / 2 - annotationRectangle.getWidth() / 2; double yCenter = pieBounds.getY() + pieBounds.getHeight() / 2 + annotationRectangle.getHeight() / 2; double angle = (arcAngle + startAngle) - arcAngle / 2; double xOffset = xCenter + Math.cos(Math.toRadians(angle)) * (pieBounds.getWidth() / 2 * pieStyler.getAnnotationDistance()); double yOffset = yCenter - Math.sin(Math.toRadians(angle)) * (pieBounds.getHeight() / 2 * pieStyler.getAnnotationDistance()); Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); xCenter = pieBounds.getX() + pieBounds.getWidth() / 2; yCenter = pieBounds.getY() + pieBounds.getHeight() / 2;
private BufferedImage adjustImage(BufferedImage gray) throws IOException { AffineTransform at = new AffineTransform(xform); Matrix m = new Matrix(at); at.scale(1.0 / Math.abs(m.getScalingFactorX()), 1.0 / Math.abs(m.getScalingFactorY())); Rectangle originalBounds = new Rectangle(gray.getWidth(), gray.getHeight()); Rectangle2D transformedBounds = at.createTransformedShape(originalBounds).getBounds2D(); at.preConcatenate(AffineTransform.getTranslateInstance(-transformedBounds.getMinX(), -transformedBounds.getMinY())); int width = (int) Math.ceil(transformedBounds.getWidth()); int height = (int) Math.ceil(transformedBounds.getHeight()); BufferedImage transformedGray = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g2 = (Graphics2D) transformedGray.getGraphics(); g2.drawImage(gray, at, null); g2.dispose(); return transformedGray; }
/** * Returns a suggested value for the {@code flatness} argument in {@link * Shape#getPathIterator(AffineTransform,double)} for the specified shape. * * @param shape The shape for which to compute a flatness factor. * @return The suggested flatness factor. */ public static double getFlatness(final Shape shape) { final Rectangle2D bounds = shape.getBounds2D(); final double dx = bounds.getWidth(); final double dy = bounds.getHeight(); return max(0.025 * min(dx, dy), 0.001 * max(dx, dy)); } }
public boolean process(GlyphVector glyphVector, int g, AffineTransform tx, char c) { if (Character.isWhitespace(c)) return false; Rectangle2D labelEnvelope = tx.createTransformedShape(glyphVector.getGlyphOutline(g)).getBounds2D(); index.addLabel(labelItem, labelEnvelope); return true; } }
return; this.bbox = new PDRectangle((float)clipRect.getX(), (float)clipRect.getY(), (float)clipRect.getWidth(), (float)clipRect.getHeight()); Rectangle2D bounds = dpiTransform.createTransformedShape(clip.getBounds2D()).getBounds2D(); pageSize = new PDRectangle(minX / Math.abs(m.getScalingFactorX()), minY / Math.abs(m.getScalingFactorY()), (float) bounds.getWidth() / Math.abs(m.getScalingFactorX()), (float) bounds.getHeight() / Math.abs(m.getScalingFactorY())); int clipWindingRuleOriginal = clipWindingRule; clipWindingRule = -1; g.translate(-clipRect.getX(), -clipRect.getY());
private Shape getShape(String fontFamilyName, char character) { Font font = FontCache.getDefaultInstance().getFont(fontFamilyName); if (font == null) { throw new IllegalArgumentException("Unknown font " + fontFamilyName); } // handle charmap code reporting issues if (!font.canDisplay(character)) { char alternative = (char) (0xF000 | character); if (font.canDisplay(alternative)) { character = alternative; } } // build the shape out of the font GlyphVector textGlyphVector = font.createGlyphVector(FONT_RENDER_CONTEXT, new char[] {(char) character}); Shape s = textGlyphVector.getOutline(); // have the shape be centered in the origin, and sitting in a square of side 1 Rectangle2D bounds = s.getBounds2D(); AffineTransform tx = new AffineTransform(); double max = Math.max(bounds.getWidth(), bounds.getHeight()); // all shapes are defined looking "upwards" (see ShapeMarkFactory or WellKnownMarkFactory) // but the fonts ones are flipped to compensate for the fact the y coords grow from top // to bottom on the screen. We have to flip the symbol so that it conforms to the // other marks convention tx.scale(1 / max, -1 / max); tx.translate(-bounds.getCenterX(), -bounds.getCenterY()); ExplicitBoundsShape shape = new ExplicitBoundsShape(tx.createTransformedShape(s)); shape.setBounds(new Rectangle2D.Double(-0.5, 0.5, 1.0, 1.0)); return shape; }
@Override public Shape getShape(Graphics2D graphics, Expression symbolUrl, Feature feature) throws Exception { RenderableSVG svg = cache.getRenderableSVG(feature, symbolUrl, "image/svg"); if (svg == null) { return null; } Shape shape = getShape(svg.node); final Rectangle2D bounds = shape.getBounds2D(); double maxSize = Math.max(bounds.getWidth(), bounds.getHeight()); // flip and center the shape double scaleToOne = 1 / maxSize; final AffineTransform at = new AffineTransform(scaleToOne, 0, 0, -scaleToOne, -0.5, 0.5); TransformedShape ts = new TransformedShape(shape, at); return ts; }
private void adjustRectangle(Rectangle2D r) { Matrix m = new Matrix(xform); double scaleX = Math.abs(m.getScalingFactorX()); double scaleY = Math.abs(m.getScalingFactorY()); AffineTransform adjustedTransform = new AffineTransform(xform); adjustedTransform.scale(1.0 / scaleX, 1.0 / scaleY); r.setRect(adjustedTransform.createTransformedShape(r).getBounds2D()); }
double boundsWidth = getBounds().getWidth(); double boundsHeight = getBounds().getHeight(); double min = Math.min(boundsWidth, boundsHeight); double width = styler.isCircular() ? min : boundsWidth; double xDiameter = pieBounds.getWidth() / 2; double yDiameter = pieBounds.getHeight() / 2; double xCenter = pieBounds.getX() + xDiameter; double yCenter = pieBounds.getY() + yDiameter; Shape shape = textLayout.getOutline(null); Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); double annotationHeight = annotationBounds.getHeight(); Shape shape = textLayout.getOutline(null); Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); double annotationHeight = annotationBounds.getHeight(); Shape shape = textLayout.getOutline(null); Rectangle2D annotationBounds = shape.getBounds2D(); double annotationWidth = annotationBounds.getWidth(); double annotationHeight = annotationBounds.getHeight();
Graphics2D graphics, Shape shape, Style2D graphicFill, double scale) { Rectangle2D boundsShape = shape.getBounds2D(); final Shape markShape = ms2d.getShape(); double size = ms2d.getSize(); Rectangle2D boundsFill = markShape.getBounds2D(); double aspect = (boundsFill.getHeight() > 0 && boundsFill.getWidth() > 0) ? boundsFill.getWidth() / boundsFill.getHeight() : 1.0; stippleSize = new Rectangle2D.Double(0, 0, size * aspect, size); if (boundsFill.getHeight() > 0) { scaleFactor = size / boundsFill.getHeight(); lineStyle.setContourComposite(ms2d.getContourComposite()); lineStyle.setGraphicStroke(ms2d.getGraphicStroke()); filler.fillRectangle(shape.getBounds2D(), this, clippedGraphics, lineStyle); return; int toX = (int) Math.ceil(boundsShape.getWidth() / stippleSize.getWidth()); int toY = (int) Math.ceil(boundsShape.getHeight() / stippleSize.getHeight()); Rectangle2D boundsClip = clipShape.getBounds2D();