List of usage examples for java.awt.geom PathIterator SEG_CLOSE
int SEG_CLOSE
To view the source code for java.awt.geom PathIterator SEG_CLOSE.
Click Source Link
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 w ww. j a v a2 s . c o m 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. j av a2s .co 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:ExtendedGeneralPath.java
/** * Delegates to the enclosed <code>GeneralPath</code>. *//*from w ww. ja v a2 s. c om*/ 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 ww w . j a va 2 s . c o m 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:SWTGraphics2D.java
/** * Converts an AWT <code>Shape</code> into a SWT <code>Path</code>. * * @param shape the shape (<code>null</code> not permitted). * * @return The path./*from w w w . ja va2 s . co m*/ */ private Path toSwtPath(Shape shape) { int type; float[] coords = new float[6]; Path path = new Path(this.gc.getDevice()); PathIterator pit = shape.getPathIterator(null); while (!pit.isDone()) { type = pit.currentSegment(coords); switch (type) { case (PathIterator.SEG_MOVETO): path.moveTo(coords[0], coords[1]); break; case (PathIterator.SEG_LINETO): path.lineTo(coords[0], coords[1]); break; case (PathIterator.SEG_QUADTO): path.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case (PathIterator.SEG_CUBICTO): path.cubicTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case (PathIterator.SEG_CLOSE): path.close(); break; default: break; } pit.next(); } return path; }
From source file:org.apache.fop.afp.AFPGraphics2D.java
/** * Processes a path iterator generating the necessary painting operations. * * @param iter PathIterator to process//from w w w. jav a2 s . c o m */ private void processPathIterator(PathIterator iter) { double[] dstPts = new double[6]; double[] currentPosition = new double[2]; for (int[] openingCoords = new int[2]; !iter.isDone(); iter.next()) { switch (iter.currentSegment(dstPts)) { case PathIterator.SEG_LINETO: graphicsObj.addLine(new int[] { (int) Math.round(dstPts[X]), (int) Math.round(dstPts[Y]) }, true); currentPosition = new double[] { dstPts[X], dstPts[Y] }; break; case PathIterator.SEG_QUADTO: graphicsObj.addFillet(new int[] { (int) Math.round(dstPts[X1]), (int) Math.round(dstPts[Y1]), (int) Math.round(dstPts[X2]), (int) Math.round(dstPts[Y2]) }, true); currentPosition = new double[] { dstPts[X2], dstPts[Y2] }; break; case PathIterator.SEG_CUBICTO: double[] cubicCoords = new double[] { currentPosition[0], currentPosition[1], dstPts[X1], dstPts[Y1], dstPts[X2], dstPts[Y2], dstPts[X3], dstPts[Y3] }; double[][] quadParts = CubicBezierApproximator.fixedMidPointApproximation(cubicCoords); if (quadParts.length >= 4) { for (int segIndex = 0; segIndex < quadParts.length; segIndex++) { double[] quadPts = quadParts[segIndex]; if (quadPts != null && quadPts.length == 4) { graphicsObj.addFillet( new int[] { (int) Math.round(quadPts[X1]), (int) Math.round(quadPts[Y1]), (int) Math.round(quadPts[X2]), (int) Math.round(quadPts[Y2]) }, true); currentPosition = new double[] { quadPts[X2], quadPts[Y2] }; } } } break; case PathIterator.SEG_MOVETO: openingCoords = new int[] { (int) Math.round(dstPts[X]), (int) Math.round(dstPts[Y]) }; currentPosition = new double[] { dstPts[X], dstPts[Y] }; graphicsObj.setCurrentPosition(openingCoords); break; case PathIterator.SEG_CLOSE: graphicsObj.addLine(openingCoords, true); currentPosition = new double[] { openingCoords[0], openingCoords[1] }; break; default: LOG.debug("Unrecognised path iterator type"); break; } } }
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;//ww w. j a va 2 s. co m 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 a v a 2s. 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; }
From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java
protected Element createShape(Shape shape) { PathIterator pathIter = shape.getPathIterator(null); StringBuffer pathStr = new StringBuffer(); while (!pathIter.isDone()) { float[] points = new float[6]; int TYPE = pathIter.currentSegment(points); switch (TYPE) { case PathIterator.SEG_CLOSE: pathStr.append(" Z"); //$NON-NLS-1$ break; case PathIterator.SEG_LINETO: pathStr.append(" L").append(toString(points, 2, ' ')); //$NON-NLS-1$ break; case PathIterator.SEG_QUADTO: pathStr.append(" Q").append(toString(points, 4, ' ')); //$NON-NLS-1$ break; case PathIterator.SEG_CUBICTO: pathStr.append(" C").append(toString(points, 6, ' ')); //$NON-NLS-1$ break; case PathIterator.SEG_MOVETO: pathStr.append(" M").append(toString(points, 2, ' ')); //$NON-NLS-1$ break; }/*from w ww .j a v a2 s .co m*/ pathIter.next(); } Element elem = dom.createElement("path"); //$NON-NLS-1$ elem.setAttribute("d", pathStr.toString()); //$NON-NLS-1$ return elem; }
From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java
public static GeneralPath areaToPath(final Area negativeArea, final double deltaX, final GeneralPath pixelPath) { final float[] floats = new float[6]; // move to correct rectangle final AffineTransform transform = AffineTransform.getTranslateInstance(deltaX, 0.0); final PathIterator iterator = negativeArea.getPathIterator(transform); while (!iterator.isDone()) { final int segmentType = iterator.currentSegment(floats); if (segmentType == PathIterator.SEG_LINETO) { pixelPath.lineTo(floats[0], floats[1]); } else if (segmentType == PathIterator.SEG_MOVETO) { pixelPath.moveTo(floats[0], floats[1]); } else if (segmentType == PathIterator.SEG_CLOSE) { pixelPath.closePath();//from ww w .j a v a2 s .com } iterator.next(); } return pixelPath; }