Refine search
/** * 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 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); }
static public Point2D.Double getCenter(Positionable p) { return new Point2D.Double(toRectangle(p).getCenterX(), toRectangle(p).getCenterY()); }
@SuppressWarnings("WeakerAccess") protected Paint createRadialGradientPaint(GradientPaint fill, Graphics2D graphics) { Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); final Point2D pCenter = new Point2D.Double(anchor.getCenterX(), anchor.getCenterY()); final float radius = (float)Math.max(anchor.getWidth(), anchor.getHeight()); return safeFractions((f,c)->new RadialGradientPaint(pCenter,radius,f,c), fill); }
@SuppressWarnings("WeakerAccess") protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) { // TODO: we need to find the two points for gradient - the problem is, which point at the outline // do you take? My solution would be to apply the gradient rotation to the shape in reverse // and then scan the shape for the largest possible horizontal distance double angle = fill.getGradientAngle(); if (!fill.isRotatedWithShape()) { angle -= shape.getRotation(); } Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY()); double diagonal = Math.sqrt(Math.pow(anchor.getWidth(),2) + Math.pow(anchor.getHeight(),2)); final Point2D p1 = at.transform(new Point2D.Double(anchor.getCenterX() - diagonal / 2, anchor.getCenterY()), null); final Point2D p2 = at.transform(new Point2D.Double(anchor.getMaxX(), anchor.getCenterY()), null); // snapToAnchor(p1, anchor); // snapToAnchor(p2, anchor); // gradient paint on the same point throws an exception ... and doesn't make sense return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill); }
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(line.getX1(), line.getY1(), line.getX1(), line.getY1(), inter.getX(), inter.getY(), inter.getX(), inter.getY()); return result.addAfter(curv); }
double scaleX = bounds.getWidth()/shapeBounds.getWidth(); double scaleY = bounds.getHeight()/shapeBounds.getHeight(); tx.translate(bounds.getCenterX(), bounds.getCenterY()); tx.scale(scaleX, scaleY); tx.translate(-shapeBounds.getCenterX(), -shapeBounds.getCenterY());
if (rotation != 0.) { double centerX = anchor.getCenterX(); double centerY = anchor.getCenterY();
case _hc: return anchor.getCenterX(); case _h: case _vc: return anchor.getCenterY(); case _w:
final double centerX = anchorO.getCenterX(); final double centerY = anchorO.getCenterY(); final AffineTransform txs2 = new AffineTransform(); double centerX = shapeAnchor.getCenterX(); double centerY = shapeAnchor.getCenterY(); final AffineTransform txs2 = new AffineTransform(); txs2.translate(centerX, centerY);
public DotPath getRacordIn(Rectangle2D rect, Line2D tangeante) { final DotPath result = new DotPath(); final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY()); final Line2D.Double line = new Line2D.Double(tangeante.getP1(), center); final Point2D inter = BezierUtils.intersect(line, rect); final CubicCurve2D.Double curv = new CubicCurve2D.Double(tangeante.getX1(), tangeante.getY1(), tangeante .getX2(), tangeante.getY2(), tangeante.getX2(), tangeante.getY2(), inter.getX(), inter.getY()); return result.addAfter(curv); }
GraphicInfo graphicInfoLast = graphicInfoList.get(graphicInfoList.size() - 1); if (shapeFirst != null) { graphicInfoFirst.setX(shapeFirst.getBounds2D().getCenterX()); graphicInfoFirst.setY(shapeFirst.getBounds2D().getCenterY()); graphicInfoLast.setX(shapeLast.getBounds2D().getCenterX()); graphicInfoLast.setY(shapeLast.getBounds2D().getCenterY());
final double cx = anchor.getCenterX(); final double cy = anchor.getCenterY(); graphics.translate(cx, cy); graphics.rotate(Math.toRadians(textRot)); if (textDir == TextDirection.VERTICAL || textDir == TextDirection.VERTICAL_270) { final double deg = (textDir == TextDirection.VERTICAL) ? 90 : 270; final double cx = anchor.getCenterX(); final double cy = anchor.getCenterY(); graphics.translate(cx, cy); graphics.rotate(Math.toRadians(deg));
final Point2D center = new Point2D.Double(rect.getCenterX(), rect.getCenterY());
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);
at.translate(bounds.getX()+bounds.getCenterX(), bounds.getY()+bounds.getCenterY()); at.scale(1./Units.EMU_PER_POINT, 1./Units.EMU_PER_POINT); at.translate(-xfrm2d.getCenterX(), -xfrm2d.getCenterY()); return new Path2D.Double(at.createTransformedShape(path));
RectangleStroke(Shape pShapes[]) { mShapes = new Shape[pShapes.length]; for (int i = 0; i < mShapes.length; i++) { Rectangle2D bounds = pShapes[i].getBounds2D(); mTransform.setToTranslation(-bounds.getCenterX(), -bounds.getCenterY()); mShapes[i] = mTransform.createTransformedShape(pShapes[i]); } }
public static Path2D enlargeSlightlyInPlace(Path2D path2d) { AffineTransform aLittleLarger = new AffineTransform(); double centerX = path2d.getBounds2D().getCenterX(); double centerY = path2d.getBounds2D().getCenterY(); aLittleLarger.translate(centerX, centerY); aLittleLarger.scale(1.01, 1.01); aLittleLarger.translate(-centerX, -centerY); path2d.transform(aLittleLarger); return path2d; }
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; }
/** * If, for any reason, a font size of 0 is provided to the renderer, resulting bounds will * become empty and this will ruin most geometric computations dealing with spacing and * orientations. Enlarge the envelope a tiny bit * * @param bounds */ void normalizeBounds(Rectangle2D bounds) { if (bounds == null) { bounds = new Rectangle2D.Float(-1, -1, 2, 2); } else if (bounds.isEmpty()) { bounds.setRect(bounds.getCenterX() - 1, bounds.getCenterY() - 1, 2, 2); } }