List of usage examples for java.awt.geom PathIterator next
public void next();
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);//from w ww . j av a2s . c om 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 v a 2 s . com*/ pi.next(); } }
From source file:DescribePath.java
public static void describePath(Shape s) { PathIterator pi = s.getPathIterator(null); while (pi.isDone() == false) { describeCurrentSegment(pi);/* w w w.j a v a 2 s . c o m*/ pi.next(); } }
From source file:Main.java
/** * Converts a {@link Shape} to TDL. /*from w w w .j a va 2 s. c o 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
/** * 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 w w. j a v a2 s . co 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 .j a v a2s . c o m 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: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 .jav a 2 s . c o m 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:longMethod.jfreechart.drawItem.SamplingXYLineRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device.//from w w w . j a v a2 s . c o m * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // do nothing if item is not visible if (!getItemVisible(series, item)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); State s = (State) state; // update path to reflect latest point if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.lastPointGood) { if ((Math.abs(x - s.lastX) > s.dX)) { s.seriesPath.lineTo(x, y); if (s.lowY < s.highY) { s.intervalPath.moveTo((float) s.lastX, (float) s.lowY); s.intervalPath.lineTo((float) s.lastX, (float) s.highY); } s.lastX = x; s.openY = y; s.highY = y; s.lowY = y; s.closeY = y; } else { s.highY = Math.max(s.highY, y); s.lowY = Math.min(s.lowY, y); s.closeY = y; } } else { s.seriesPath.moveTo(x, y); s.lastX = x; s.openY = y; s.highY = y; s.lowY = y; s.closeY = y; } s.lastPointGood = true; } else { s.lastPointGood = false; } // if this is the last item, draw the path ... if (item == s.getLastItemIndex()) { // draw path PathIterator pi = s.seriesPath.getPathIterator(null); int count = 0; while (!pi.isDone()) { count++; pi.next(); } g2.setStroke(getItemStroke(series, item)); g2.setPaint(getItemPaint(series, item)); g2.draw(s.seriesPath); g2.draw(s.intervalPath); } }
From source file:edu.uci.ics.jung.visualization.picking.ShapePickSupport.java
/** * Returns an edge whose shape intersects the 'pickArea' footprint of the passed * x,y, coordinates./*from w w w . ja va2 s . co m*/ */ public E getEdge(Layout<V, E> layout, double x, double y) { Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, new Point2D.Double(x, y)); x = ip.getX(); y = ip.getY(); // as a Line has no area, we can't always use edgeshape.contains(point) so we // make a small rectangular pickArea around the point and check if the // edgeshape.intersects(pickArea) Rectangle2D pickArea = new Rectangle2D.Float((float) x - pickSize / 2, (float) y - pickSize / 2, pickSize, pickSize); E closest = null; double minDistance = Double.MAX_VALUE; while (true) { try { for (E e : getFilteredEdges(layout)) { Shape edgeShape = getTransformedEdgeShape(layout, e); if (edgeShape == null) continue; // because of the transform, the edgeShape is now a GeneralPath // see if this edge is the closest of any that intersect if (edgeShape.intersects(pickArea)) { float cx = 0; float cy = 0; float[] f = new float[6]; PathIterator pi = new GeneralPath(edgeShape).getPathIterator(null); if (pi.isDone() == false) { pi.next(); pi.currentSegment(f); cx = f[0]; cy = f[1]; if (pi.isDone() == false) { pi.currentSegment(f); cx = f[0]; cy = f[1]; } } float dx = (float) (cx - x); float dy = (float) (cy - y); float dist = dx * dx + dy * dy; if (dist < minDistance) { minDistance = dist; closest = e; } } } break; } catch (ConcurrentModificationException cme) { } } return closest; }
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 w w w . j a va 2 s . c o m*/ } 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())); }