@Override public int currentSegment(float[] coords) { if (isDone()) { throw new NoSuchElementException("roundrect iterator out of bounds"); } int nc = 0; double ctrls[] = ctrlpts[index]; for (int i = 0; i < ctrls.length; i += 4) { coords[nc++] = (float) (x + ctrls[i] * width + ctrls[i + 1] / 2d); coords[nc++] = (float) (y + ctrls[i + 2] * height + ctrls[i + 3] / 2d); } if (at != null) { at.transform(coords, 0, coords, 0, nc / 2); } return types[index]; }
public void rotate(double theta) { final AffineTransform rotate = AffineTransform.getRotateInstance(theta); for (Point2D.Double pt : all) { rotate.transform(pt, pt); } }
@Override public int currentSegment(double[] coords) { if (isDone()) { throw new NoSuchElementException("roundrect iterator out of bounds"); } int nc = 0; double ctrls[] = ctrlpts[index]; for (int i = 0; i < ctrls.length; i += 4) { coords[nc++] = x + ctrls[i] * width + ctrls[i + 1] / 2d; coords[nc++] = y + ctrls[i + 2] * height + ctrls[i + 3] / 2d; } if (at != null) { at.transform(coords, 0, coords, 0, nc / 2); } return types[index]; } };
public Point2D inflatePoint2D(Point2D point) { return getAffineTransformAt(point).transform(point, null); }
List<Line2D.Double> inflateSegmentCollection(Collection<Line2D.Double> segments) { final List<Line2D.Double> result = new ArrayList<Line2D.Double>(); for (Line2D.Double seg : segments) { final AffineTransform at = getAffineTransformAt(new Point2D.Double((seg.x1 + seg.x2) / 2, (seg.y1 + seg.y2) / 2)); result.add(new Line2D.Double(at.transform(seg.getP1(), null), at.transform(seg.getP2(), null))); } return result; }
public CircleAndArrow(Point2D p1, Point2D p2) { this.center = new Point2D.Double((p1.getX() + p2.getX()) / 2, (p1.getY() + p2.getY()) / 2); at = AffineTransform.getTranslateInstance(-center.getX(), -center.getY()); at2 = AffineTransform.getTranslateInstance(center.getX(), center.getY()); radius = (int) (p1.distance(p2) / 2); if (radius % 2 == 0) { radius--; } this.p1 = putOnCircle(p1); this.p2 = putOnCircle(p2); this.p3 = at.transform(this.p1, null); this.p3 = new Point2D.Double(p3.getY(), -p3.getX()); this.p3 = at2.transform(p3, null); this.p4 = at.transform(this.p2, null); this.p4 = new Point2D.Double(p4.getY(), -p4.getX()); this.p4 = at2.transform(p4, null); }
public void drawU(UGraphic ug) { final int xWing = 4; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D firstLineTop = new Point2D.Double(-xWing, -lineHeight); Point2D firstLineBottom = new Point2D.Double(-xWing, lineHeight); Point2D secondLineTop = new Point2D.Double(-xWing - 3, -lineHeight); Point2D secondLineBottom = new Point2D.Double(-xWing - 3, lineHeight); Point2D middle = new Point2D.Double(0, 0); Point2D base = new Point2D.Double(-xWing - 4, 0); rotate.transform(middle, middle); rotate.transform(base, base); rotate.transform(firstLineTop, firstLineTop); rotate.transform(firstLineBottom, firstLineBottom); rotate.transform(secondLineTop, secondLineTop); rotate.transform(secondLineBottom, secondLineBottom); drawLine(ug, contact.getX(), contact.getY(), firstLineTop, firstLineBottom); drawLine(ug, contact.getX(), contact.getY(), secondLineTop, secondLineBottom); drawLine(ug, contact.getX(), contact.getY(), base, middle); }
public MagicPointsFactory2(Point2D.Double p1, Point2D.Double p2) { this.p1 = p1; this.p2 = p2; final double dx = p2.x - p1.x; final double dy = p2.y - p1.y; final int interv = 5; final int intervAngle = 10; final double theta = Math.PI * 2 / intervAngle; for (int a = 0; a < 10; a++) { final AffineTransform at = AffineTransform.getRotateInstance(theta * a, p1.x, p1.y); for (int i = 0; i < interv * 2; i++) { final Point2D.Double p = new Point2D.Double(p1.x + dx * i / interv, p1.y + dy * i / interv); result.add((Point2D.Double) at.transform(p, null)); } } }
public USegment rotate(double theta) { if (coord.length != 2) { throw new UnsupportedOperationException(); } Point2D p1 = new Point2D.Double(coord[0], coord[1]); final AffineTransform rotate = AffineTransform.getRotateInstance(theta); rotate.transform(p1, p1); return new USegment(new double[] { p1.getX(), p1.getY() }, pathType); }
public void drawU(UGraphic ug) { final int xWing = 8; final int yAperture = 6; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D middle = new Point2D.Double(0, 0); Point2D left = new Point2D.Double(0, -yAperture); Point2D base = new Point2D.Double(-xWing, 0); Point2D lineTop = new Point2D.Double(-xWing-2, -lineHeight); Point2D lineBottom = new Point2D.Double(-xWing-2, lineHeight); Point2D right = new Point2D.Double(0, yAperture); rotate.transform(left, left); rotate.transform(base, base); rotate.transform(right, right); rotate.transform(lineTop, lineTop); rotate.transform(lineBottom, lineBottom); drawLine(ug, contact.getX(), contact.getY(), base, left); drawLine(ug, contact.getX(), contact.getY(), base, right); drawLine(ug, contact.getX(), contact.getY(), base, middle); drawLine(ug, contact.getX(), contact.getY(), lineTop, lineBottom); }
public void drawU(UGraphic ug) { final int xWing = 4; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D middle = new Point2D.Double(0, 0); Point2D base = new Point2D.Double(-xWing-radius-3, 0); Point2D circleBase = new Point2D.Double(-xWing-radius-3, 0); Point2D lineTop = new Point2D.Double(-xWing, -lineHeight); Point2D lineBottom = new Point2D.Double(-xWing, lineHeight); rotate.transform(lineTop, lineTop); rotate.transform(lineBottom, lineBottom); rotate.transform(base, base); rotate.transform(circleBase, circleBase); drawLine(ug, contact.getX(), contact.getY(), base, middle); ug.apply(new UTranslate(contact.getX()+circleBase.getX()-radius, contact.getY()+circleBase.getY()-radius)).draw(new UEllipse(2*radius, 2*radius)); drawLine(ug, contact.getX(), contact.getY(), lineTop, lineBottom); }
public void drawU(UGraphic ug) { final int xWing = 8; final int yAperture = 8; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D middle = new Point2D.Double(0, 0); Point2D left = new Point2D.Double(0, -yAperture); Point2D base = new Point2D.Double(-xWing, 0); Point2D right = new Point2D.Double(0, yAperture); rotate.transform(left, left); rotate.transform(base, base); rotate.transform(right, right); if (side == Side.WEST || side == Side.EAST) { left.setLocation(middle.getX(), left.getY()); right.setLocation(middle.getX(), right.getY()); } if (side == Side.SOUTH || side == Side.NORTH) { left.setLocation(left.getX(), middle.getY()); right.setLocation(right.getX(), middle.getY()); } drawLine(ug, contact.getX(), contact.getY(), base, left); drawLine(ug, contact.getX(), contact.getY(), base, right); drawLine(ug, contact.getX(), contact.getY(), base, middle); }
public void drawU(UGraphic ug) { final int xWing = 8; final int yAperture = 6; final AffineTransform rotate = AffineTransform.getRotateInstance(this.angle); Point2D middle = new Point2D.Double(0, 0); Point2D left = new Point2D.Double(0, -yAperture); Point2D base = new Point2D.Double(-xWing, 0); Point2D right = new Point2D.Double(0, yAperture); Point2D circleBase = new Point2D.Double(-xWing-radius-2, 0); rotate.transform(left, left); rotate.transform(base, base); rotate.transform(right, right); rotate.transform(circleBase, circleBase); drawLine(ug, contact.getX(), contact.getY(), base, left); drawLine(ug, contact.getX(), contact.getY(), base, right); drawLine(ug, contact.getX(), contact.getY(), base, middle); ug.apply(new UTranslate(contact.getX()+circleBase.getX()-radius, contact.getY()+circleBase.getY()-radius)).draw(new UEllipse(2*radius, 2*radius)); }
public MinMax getMinMax(Dimension2D rect) { MinMax result = MinMax.getEmpty(false); final AffineTransform tmp = getAffineTransform(rect); result = result.addPoint(tmp.transform(new Point2D.Double(0, 0), null)); result = result.addPoint(tmp.transform(new Point2D.Double(0, rect.getHeight()), null)); result = result.addPoint(tmp.transform(new Point2D.Double(rect.getWidth(), 0), null)); result = result.addPoint(tmp.transform(new Point2D.Double(rect.getWidth(), rect.getHeight()), null)); return result; }
@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); }
at.transform(pts, 0, pts, 0, 3);
before.transform(pos, pos);
@Override public float getWidthFromFont(int code) throws IOException { String name = codeToName(code); float width = genericFont.getWidth(name); Point2D p = new Point2D.Float(width, 0); fontMatrixTransform.transform(p, p); return (float)p.getX(); }
/** * Transforms a point using the CTM. */ public Point2D.Float transformedPoint(float x, float y) { float[] position = { x, y }; getGraphicsState().getCurrentTransformationMatrix().createAffineTransform() .transform(position, 0, position, 0, 1); return new Point2D.Float(position[0], position[1]); }