List of usage examples for java.awt.geom PathIterator SEG_MOVETO
int SEG_MOVETO
To view the source code for java.awt.geom PathIterator SEG_MOVETO.
Click Source Link
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 ww . j av a2s .com*/ } 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())); }
From source file:ExtendedGeneralPath.java
/** * Delegates to the enclosed <code>GeneralPath</code>. *///from ww w.j a v a 2s. c o m public synchronized void closePath() { // Don't double close path. if ((numSeg != 0) && (types[numSeg - 1] == PathIterator.SEG_CLOSE)) return; // Only close path if the previous command wasn't a moveto if ((numSeg != 0) && (types[numSeg - 1] != PathIterator.SEG_MOVETO)) path.closePath(); makeRoom(0); types[numSeg++] = PathIterator.SEG_CLOSE; cx = mx; cy = my; }
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;/* w w w . j a va2 s . com*/ 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:ExtendedGeneralPath.java
/** * Checks if previous command was a moveto command, * skipping a close command (if present). *//* w w w . ja v a 2 s .c o m*/ protected void checkMoveTo() { if (numSeg == 0) return; switch (types[numSeg - 1]) { case PathIterator.SEG_MOVETO: path.moveTo(values[numVals - 2], values[numVals - 1]); break; case PathIterator.SEG_CLOSE: if (numSeg == 1) return; if (types[numSeg - 2] == PathIterator.SEG_MOVETO) path.moveTo(values[numVals - 2], values[numVals - 1]); break; default: break; } }
From source file:PathLength.java
/** * Returns the index of the path segment that bounds the specified * length along the path.// w ww. j a v a2s .co m * @param length The length along the path * @return The path segment index, or -1 if there is not such segment */ public int findUpperIndex(float length) { if (!initialised) { initialise(); } if (length < 0 || length > pathLength) { // Length is outside the path, so return -1. return -1; } // Find the two segments that are each side of the length. int lb = 0; int ub = segments.size() - 1; while (lb != ub) { int curr = (lb + ub) >> 1; PathSegment ps = (PathSegment) segments.get(curr); if (ps.getLength() >= length) { ub = curr; } else { lb = curr + 1; } } for (;;) { PathSegment ps = (PathSegment) segments.get(ub); if (ps.getSegType() != PathIterator.SEG_MOVETO || ub == segments.size() - 1) { break; } ub++; } int upperIndex = -1; int currentIndex = 0; int numSegments = segments.size(); while (upperIndex <= 0 && currentIndex < numSegments) { PathSegment ps = (PathSegment) segments.get(currentIndex); if (ps.getLength() >= length && ps.getSegType() != PathIterator.SEG_MOVETO) { upperIndex = currentIndex; } currentIndex++; } return upperIndex; }
From source file:ExtendedGeneralPath.java
/** * Delegates to the enclosed <code>GeneralPath</code>. *//*from www . j a v a 2 s .c o m*/ public void append(PathIterator pi, boolean connect) { double[] vals = new double[6]; while (!pi.isDone()) { Arrays.fill(vals, 0); int type = pi.currentSegment(vals); pi.next(); if (connect && (numVals != 0)) { if (type == PathIterator.SEG_MOVETO) { double x = vals[0]; double y = vals[1]; if ((x != cx) || (y != cy)) { // Change MOVETO to LINETO. type = PathIterator.SEG_LINETO; } else { // Redundent segment (move to current loc) drop it... if (pi.isDone()) break; // Nothing interesting type = pi.currentSegment(vals); pi.next(); } } connect = false; } switch (type) { case PathIterator.SEG_CLOSE: closePath(); break; case PathIterator.SEG_MOVETO: moveTo((float) vals[0], (float) vals[1]); break; case PathIterator.SEG_LINETO: lineTo((float) vals[0], (float) vals[1]); break; case PathIterator.SEG_QUADTO: quadTo((float) vals[0], (float) vals[1], (float) vals[2], (float) vals[3]); break; case PathIterator.SEG_CUBICTO: curveTo((float) vals[0], (float) vals[1], (float) vals[2], (float) vals[3], (float) vals[4], (float) vals[5]); break; } } }
From source file:ExtendedGeneralPath.java
/** * Delegates to the enclosed <code>GeneralPath</code>. *///from w w w. j a v a2 s.c om public void append(ExtendedPathIterator epi, boolean connect) { float[] vals = new float[7]; while (!epi.isDone()) { Arrays.fill(vals, 0); int type = epi.currentSegment(vals); epi.next(); if (connect && (numVals != 0)) { if (type == PathIterator.SEG_MOVETO) { float x = vals[0]; float y = vals[1]; if ((x != cx) || (y != cy)) { // Change MOVETO to LINETO. type = PathIterator.SEG_LINETO; } else { // Redundant segment (move to current loc) drop it... if (epi.isDone()) break; // Nothing interesting type = epi.currentSegment(vals); epi.next(); } } connect = false; } switch (type) { case PathIterator.SEG_CLOSE: closePath(); break; case PathIterator.SEG_MOVETO: moveTo(vals[0], vals[1]); break; case PathIterator.SEG_LINETO: lineTo(vals[0], vals[1]); break; case PathIterator.SEG_QUADTO: quadTo(vals[0], vals[1], vals[2], vals[3]); break; case PathIterator.SEG_CUBICTO: curveTo(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]); break; case ExtendedPathIterator.SEG_ARCTO: arcTo(vals[0], vals[1], vals[2], (vals[3] != 0), (vals[4] != 0), vals[5], vals[6]); break; } } }
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 w w w .j av a 2s . c om 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:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Returns a transform to position the arrowhead on this edge shape at the * point where it intersects the passed vertex shape. */// w ww .j a v a 2 s. co m public AffineTransform getArrowTransform(GeneralPath edgeShape, Shape vertexShape) { float[] seg = new float[6]; Point2D p1 = null; Point2D p2 = null; AffineTransform at = new AffineTransform(); // when the PathIterator is done, switch to the line-subdivide // method to get the arrowhead closer. for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) { int ret = i.currentSegment(seg); if (ret == PathIterator.SEG_MOVETO) { p2 = new Point2D.Float(seg[0], seg[1]); } else if (ret == PathIterator.SEG_LINETO) { p1 = p2; p2 = new Point2D.Float(seg[0], seg[1]); if (vertexShape.contains(p2)) { at = getArrowTransform(new Line2D.Float(p1, p2), vertexShape); break; } } } return at; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * <p>Returns a transform to position the arrowhead on this edge shape at the * point where it intersects the passed vertex shape.</p> * /*from w ww . j av a 2s . c o m*/ * <p>The Loop edge is a special case because its staring point is not inside * the vertex. The passedGo flag handles this case.</p> * * @param edgeShape * @param vertexShape * @param passedGo - used only for Loop edges */ public AffineTransform getReverseArrowTransform(GeneralPath edgeShape, Shape vertexShape, boolean passedGo) { float[] seg = new float[6]; Point2D p1 = null; Point2D p2 = null; AffineTransform at = new AffineTransform(); for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) { int ret = i.currentSegment(seg); if (ret == PathIterator.SEG_MOVETO) { p2 = new Point2D.Float(seg[0], seg[1]); } else if (ret == PathIterator.SEG_LINETO) { p1 = p2; p2 = new Point2D.Float(seg[0], seg[1]); if (passedGo == false && vertexShape.contains(p2)) { passedGo = true; } else if (passedGo == true && vertexShape.contains(p2) == false) { at = getReverseArrowTransform(new Line2D.Float(p1, p2), vertexShape); break; } } } return at; }