List of usage examples for java.awt.geom GeneralPath getPathIterator
public PathIterator getPathIterator(AffineTransform at);
From source file:Main.java
public static void writePath(GeneralPath path, ObjectOutputStream out) throws IOException { PathIterator i = path.getPathIterator(null); float[] data = new float[6]; while (!i.isDone()) { switch (i.currentSegment(data)) { case PathIterator.SEG_MOVETO: out.writeInt(PathIterator.SEG_MOVETO); out.writeFloat(data[0]);// w w w. j a v a 2 s . c om out.writeFloat(data[1]); break; case PathIterator.SEG_LINETO: out.writeInt(PathIterator.SEG_LINETO); out.writeFloat(data[0]); out.writeFloat(data[1]); break; case PathIterator.SEG_QUADTO: out.writeInt(PathIterator.SEG_QUADTO); out.writeFloat(data[0]); out.writeFloat(data[1]); out.writeFloat(data[2]); out.writeFloat(data[3]); break; case PathIterator.SEG_CUBICTO: out.writeInt(PathIterator.SEG_CUBICTO); out.writeFloat(data[0]); out.writeFloat(data[1]); out.writeFloat(data[2]); out.writeFloat(data[3]); out.writeFloat(data[4]); out.writeFloat(data[5]); break; case PathIterator.SEG_CLOSE: out.writeInt(PathIterator.SEG_CLOSE); break; default: throw new IOException(); } i.next(); } out.writeInt(PATH_IS_DONE); }
From source file:Main.java
/** * Tests two polygons for equality. If both are <code>null</code> this * method returns <code>true</code>. * * @param p1 path 1 (<code>null</code> permitted). * @param p2 path 2 (<code>null</code> permitted). * * @return A boolean.//from w ww . java 2s . com */ public static boolean equal(final GeneralPath p1, final GeneralPath p2) { if (p1 == null) { return (p2 == null); } if (p2 == null) { return false; } if (p1.getWindingRule() != p2.getWindingRule()) { return false; } PathIterator iterator1 = p1.getPathIterator(null); PathIterator iterator2 = p2.getPathIterator(null); double[] d1 = new double[6]; double[] d2 = new double[6]; boolean done = iterator1.isDone() && iterator2.isDone(); while (!done) { if (iterator1.isDone() != iterator2.isDone()) { return false; } int seg1 = iterator1.currentSegment(d1); int seg2 = iterator2.currentSegment(d2); if (seg1 != seg2) { return false; } if (!Arrays.equals(d1, d2)) { return false; } iterator1.next(); iterator2.next(); done = iterator1.isDone() && iterator2.isDone(); } return true; }
From source file:com.projity.pm.graphic.network.NetworkRenderer.java
protected void updateLinkConnections(GraphicNode node, double[] linkPoints) { GeneralPath shape = getShape(node); if (shape == null) return;/*from www . jav a 2 s. c om*/ Point2D center = getCenter(node); linkPoints[0] = center.getX(); linkPoints[1] = center.getX(); linkPoints[2] = center.getY(); linkPoints[3] = center.getY(); double x0 = 0.0, y0 = 0.0, x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0, x, y; for (PathIterator j = shape.getPathIterator(null); !j.isDone(); j.next()) { int segmentType = j.currentSegment(segment); switch (segmentType) { case PathIterator.SEG_MOVETO: x0 = segment[0]; y0 = segment[1]; x2 = x0; y2 = y0; break; case PathIterator.SEG_LINETO: x2 = segment[0]; y2 = segment[1]; case PathIterator.SEG_CLOSE: if (segmentType == PathIterator.SEG_CLOSE) { x2 = x0; y2 = y0; } //works only convex shapes double lambda; if (y2 != y1) { x = (center.getY() - y1) * (x2 - x1) / (y2 - y1) + x1; lambda = (x2 == x1) ? 0 : (x - x1) / (x2 - x1); if (x1 == x2 || (lambda >= 0 && lambda <= 1)) { if (x < linkPoints[0]) linkPoints[0] = x; if (x > linkPoints[1]) linkPoints[1] = x; } } if (x2 != x1) { y = (center.getX() - x1) * (y2 - y1) / (x2 - x1) + y1; lambda = (y2 == x1) ? 0 : (y - y1) / (y2 - y1); if (y1 == y2 || (lambda >= 0 && lambda <= 1)) { if (y < linkPoints[2]) linkPoints[2] = y; if (y > linkPoints[3]) linkPoints[3] = y; } } break; } x1 = x2; y1 = y2; } }
From source file:org.apache.pdfbox.pdfviewer.font.CFFGlyph2D.java
private GeneralPath transformGlyph(GeneralPath glyph) { // we have to invert all y-coordinates due to the moved 0,0-reference PathIterator iter = glyph.getPathIterator(null); float[] currentSegment = new float[6]; Path2D.Float path = new Path2D.Float(iter.getWindingRule()); boolean glyphTransformed = false; while (!iter.isDone()) { glyphTransformed = true;//from w w w .j a v a2s.com int type = iter.currentSegment(currentSegment); switch (type) { case PathIterator.SEG_MOVETO: path.moveTo(currentSegment[0], -currentSegment[1]); break; case PathIterator.SEG_LINETO: path.lineTo(currentSegment[0], -currentSegment[1]); break; case PathIterator.SEG_QUADTO: path.quadTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3]); break; case PathIterator.SEG_CUBICTO: path.curveTo(currentSegment[0], -currentSegment[1], currentSegment[2], -currentSegment[3], currentSegment[4], -currentSegment[5]); break; case PathIterator.SEG_CLOSE: path.closePath(); break; } iter.next(); } if (glyphTransformed) { return new GeneralPath(path); } else { return glyph; } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
/** * Returns true if the given path is rectangular. *///from w w w.j ava2s . c om private boolean isRectangular(GeneralPath path) { PathIterator iter = path.getPathIterator(null); double[] coords = new double[6]; int count = 0; int[] xs = new int[4]; int[] ys = new int[4]; while (!iter.isDone()) { switch (iter.currentSegment(coords)) { case PathIterator.SEG_MOVETO: if (count == 0) { xs[count] = (int) Math.floor(coords[0]); ys[count] = (int) Math.floor(coords[1]); } else { return false; } count++; break; case PathIterator.SEG_LINETO: if (count < 4) { xs[count] = (int) Math.floor(coords[0]); ys[count] = (int) Math.floor(coords[1]); } else { return false; } count++; break; case PathIterator.SEG_CUBICTO: return false; case PathIterator.SEG_CLOSE: break; } iter.next(); } if (count == 4) { return xs[0] == xs[1] || xs[0] == xs[2] || ys[0] == ys[1] || ys[0] == ys[3]; } return false; }