List of usage examples for java.awt.geom PathIterator isDone
public boolean isDone();
From source file:Main.java
public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); PathIterator pi = s.getPathIterator(null, 2); while (pi.isDone() == false) { describeCurrentSegment(pi);// ww w. ja v a2 s.co m pi.next(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); PathIterator pi = s.getPathIterator(null); while (pi.isDone() == false) { describeCurrentSegment(pi);/*from w w w . j a va 2 s.c o m*/ pi.next(); } }
From source file:DescribePath.java
public static void describePath(Shape s) { PathIterator pi = s.getPathIterator(null); while (pi.isDone() == false) { describeCurrentSegment(pi);//from w w w . j a va 2 s . c o m pi.next(); } }
From source file:Main.java
/** * Converts a {@link Shape} to TDL. /*from w w w . ja v a 2 s . co m*/ * @param s * @return a string containing a space separated list of the points * specifiying the shape */ public static String shapeToXML(Shape s) { StringBuilder sb = new StringBuilder(); PathIterator pi = s.getPathIterator(new AffineTransform()); float[] coords = new float[6]; while (!pi.isDone()) { pi.currentSegment(coords); sb.append(String.valueOf(coords[0]) + "," + String.valueOf(coords[1])); pi.next(); if (!pi.isDone()) { sb.append(" "); } } return sb.toString(); }
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]);/* ww w. j a v a 2s.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./*w w w . j a va 2 s . c o m*/ */ 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:Main.java
/** * Serialises a <code>Shape</code> object. * * @param shape the shape object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */// w w w . ja va 2 s . com public static void writeShape(final Shape shape, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (shape != null) { stream.writeBoolean(false); if (shape instanceof Line2D) { final Line2D line = (Line2D) shape; stream.writeObject(Line2D.class); stream.writeDouble(line.getX1()); stream.writeDouble(line.getY1()); stream.writeDouble(line.getX2()); stream.writeDouble(line.getY2()); } else if (shape instanceof Rectangle2D) { final Rectangle2D rectangle = (Rectangle2D) shape; stream.writeObject(Rectangle2D.class); stream.writeDouble(rectangle.getX()); stream.writeDouble(rectangle.getY()); stream.writeDouble(rectangle.getWidth()); stream.writeDouble(rectangle.getHeight()); } else if (shape instanceof Ellipse2D) { final Ellipse2D ellipse = (Ellipse2D) shape; stream.writeObject(Ellipse2D.class); stream.writeDouble(ellipse.getX()); stream.writeDouble(ellipse.getY()); stream.writeDouble(ellipse.getWidth()); stream.writeDouble(ellipse.getHeight()); } else if (shape instanceof Arc2D) { final Arc2D arc = (Arc2D) shape; stream.writeObject(Arc2D.class); stream.writeDouble(arc.getX()); stream.writeDouble(arc.getY()); stream.writeDouble(arc.getWidth()); stream.writeDouble(arc.getHeight()); stream.writeDouble(arc.getAngleStart()); stream.writeDouble(arc.getAngleExtent()); stream.writeInt(arc.getArcType()); } else if (shape instanceof GeneralPath) { stream.writeObject(GeneralPath.class); final PathIterator pi = shape.getPathIterator(null); final float[] args = new float[6]; stream.writeBoolean(pi.isDone()); while (!pi.isDone()) { final int type = pi.currentSegment(args); stream.writeInt(type); // TODO: could write this to only stream the values // required for the segment type for (int i = 0; i < 6; i++) { stream.writeFloat(args[i]); } stream.writeInt(pi.getWindingRule()); pi.next(); stream.writeBoolean(pi.isDone()); } } else { stream.writeObject(shape.getClass()); stream.writeObject(shape); } } else { stream.writeBoolean(true); } }
From source file:com.t_oster.visicut.misc.Helper.java
public static Rectangle2D smallestBoundingBox(Shape s, AffineTransform t) { double minX = 0; double maxX = 0; double minY = 0; double maxY = 0; PathIterator pi = s.getPathIterator(t, 1); double[] last = null; boolean first = true; while (!pi.isDone()) { double[] d = new double[8]; switch (pi.currentSegment(d)) { case PathIterator.SEG_LINETO: { if (last != null) { if (first) { minX = last[0];/*from ww w. j a va2s. co m*/ maxX = last[0]; minY = last[1]; maxY = last[1]; first = false; } else { if (last[0] < minX) { minX = last[0]; } if (last[0] > maxX) { maxX = last[0]; } if (last[1] < minY) { minY = last[1]; } if (last[1] > maxY) { maxY = last[1]; } } } if (first) { minX = d[0]; maxX = d[0]; minY = d[1]; maxY = d[1]; first = false; } else { if (d[0] < minX) { minX = d[0]; } if (d[0] > maxX) { maxX = d[0]; } if (d[1] < minY) { minY = d[1]; } if (d[1] > maxY) { maxY = d[1]; } } break; } case PathIterator.SEG_MOVETO: { last = d; break; } } pi.next(); } return new Rectangle.Double(minX, minY, maxX - minX, maxY - minY); }
From source file:it.unibo.alchemist.model.implementations.linkingrules.ConnectionBeam.java
private boolean projectedBeamOvercomesObstacle(final Position pos1, final Position pos2) { final double p1x = pos1.getCoordinate(0); final double p1y = pos1.getCoordinate(1); final double p2x = pos2.getCoordinate(0); final double p2y = pos2.getCoordinate(1); final double x = p2x - p1x; final double y = p2y - p1y; /*//from www .j a va 2 s .c o m * Compute the angle */ final double angle = atan2(y, x); /* * Deduce surrounding beam vertices */ final double dx = range * cos(PI / 2 + angle); final double dy = range * sin(PI / 2 + angle); /* * Enlarge the beam */ final double cx = range * cos(angle); final double cy = range * sin(angle); /* * Create the beam */ final Path2D.Double beamShape = new Path2D.Double(); beamShape.moveTo(p1x + dx - cx, p1y + dy - cy); beamShape.lineTo(p1x - dx - cx, p1y - dy - cy); beamShape.lineTo(p2x - dx + cx, p2y - dy + cy); beamShape.lineTo(p2x + dx + cx, p2y + dy + cy); beamShape.closePath(); final Area beam = new Area(beamShape); /* * Perform subtraction */ beam.subtract(obstacles); /* * Rebuild single areas */ final List<Path2D.Double> subareas = new ArrayList<>(); Path2D.Double curpath = new Path2D.Double(); final PathIterator pi = beam.getPathIterator(null); final double[] coords = new double[COORDS]; while (!pi.isDone()) { switch (pi.currentSegment(coords)) { case PathIterator.SEG_MOVETO: curpath = new Path2D.Double(); curpath.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: curpath.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_CLOSE: curpath.closePath(); subareas.add(curpath); break; default: throw new IllegalArgumentException(); } pi.next(); } /* * At least one area must contain both points */ for (final Path2D.Double p : subareas) { if (p.contains(p1x, p1y) && p.contains(p2x, p2y)) { return true; } } return false; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) { if (buggyDrawArea) { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()), (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2)); }/*from ww w . j a v a 2 s .c om*/ } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()), (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } else { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX()), (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2)); } } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } final Area a = new Area(area); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } if (dataArea.isEmpty() == false) { a.intersect(new Area(dataArea)); } final PathIterator pathIterator = a.getPathIterator(null, 2); final FloatList floats = new FloatList(100); final float[] coords = new float[6]; while (pathIterator.isDone() == false) { final int retval = pathIterator.currentSegment(coords); if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) { floats.add(coords[0]); floats.add(coords[1]); } pathIterator.next(); } if (floats.size() == 0) { return null; } return (new PolygonImageMapEntry(floats.toArray())); }