當前位置: 首頁>>代碼示例>>Java>>正文


Java PathIterator.currentSegment方法代碼示例

本文整理匯總了Java中java.awt.geom.PathIterator.currentSegment方法的典型用法代碼示例。如果您正苦於以下問題:Java PathIterator.currentSegment方法的具體用法?Java PathIterator.currentSegment怎麽用?Java PathIterator.currentSegment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.geom.PathIterator的用法示例。


在下文中一共展示了PathIterator.currentSegment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: mapShape

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:LayoutPathImpl.java

示例2: writeGeoPath

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
private void writeGeoPath(PrintWriter writer, GeoPath geoPath) {
    writer.write("        { \"type\": \"LineString\", \"coordinates\":\n          [");

    DecimalFormat format = new DecimalFormat("#.###");
    PathIterator iterator = geoPath.getPathIterator(null, flatness);
    double[] coordinates = new double[6];
    while (!iterator.isDone()) {
        final int type = iterator.currentSegment(coordinates);
        switch (type) {
            case PathIterator.SEG_MOVETO:
            case PathIterator.SEG_LINETO:
                writer.print(" [ ");
                writer.print(format.format(coordinates[0]));
                writer.print(",");
                writer.print(format.format(coordinates[1]));
                writer.print(" ]");
                iterator.next();
                if (!iterator.isDone()) {
                    writer.print(",");
                }
                break;
        }
        
    }
    writer.println(" ] },");
}
 
開發者ID:berniejenny,項目名稱:MapAnalyst,代碼行數:27,代碼來源:GeoJSONExporter.java

示例3: testFlattening

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
static void testFlattening(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(at, FLATNESS);
    final PathIterator itB = pathB.getPathIterator(at, FLATNESS);

    float[] coordsA = new float[6];
    float[] coordsB = new float[6];

    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);

        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] "
                + "type are not equals [" + typeA + "|" + typeB + "] !");
        }
        // Take care of floating-point precision:
        if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords"
                + " are not equals [" + Arrays.toString(coordsA) + "|"
                + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testFlattening: " + n + " segments.");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:Path2DCopyConstructor.java

示例4: testIterator

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
static void testIterator(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(at);
    final PathIterator itB = pathB.getPathIterator(at);

    float[] coordsA = new float[6];
    float[] coordsB = new float[6];

    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);

        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] "
                + "type are not equals [" + typeA + "|" + typeB + "] !");
        }
        // Take care of floating-point precision:
        if (!equalsArrayEps(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords"
                + " are not equals [" + Arrays.toString(coordsA) + "|"
                + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testIterator: " + n + " segments.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:Path2DCopyConstructor.java

示例5: setCurrentSegment

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
protected void setCurrentSegment(GeneralPath path) {
	if (currentSegment != null)
		trackLayer.removeRenderable( currentSegment );
	
	if (path == null)
	{
		currentSegment = null;
		return;
	}
	
	PathIterator pi =
		path.getPathIterator(new AffineTransform());
	List<LatLon> pos = new LinkedList<LatLon>();

	float [] coords = new float[6];
	int t = pi.currentSegment(coords);
	pos.add( LatLon.fromDegrees(coords[1], coords[0]));
	while (!pi.isDone())
	{
		t = pi.currentSegment(coords);
		if (t == PathIterator.SEG_LINETO && 
				!(coords[1] == 0 && coords[0]==0))
			pos.add( LatLon.fromDegrees(coords[1], coords[0]));
		
		pi.next();
	}
	
	Polyline line = new Polyline(pos, 0);
	line.setLineWidth(4);
	line.setFollowTerrain(true);
	line.setColor( Color.red );
	trackLayer.addRenderable(line);
	currentSegment = line;
	
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:36,代碼來源:WWMGG.java

示例6: getPoints

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
public static List<Point2D> getPoints(final Path2D path) {
  final PathIterator pi = path.getPathIterator(null);
  final double[] coordinates = new double[22];
  final List<Point2D> points = new ArrayList<>();
  while (!pi.isDone()) {
    pi.next();

    pi.currentSegment(coordinates);
    final Point2D currentPoint = new Point2D.Double(coordinates[0], coordinates[1]);
    points.add(currentPoint);
  }

  return points;
}
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:15,代碼來源:GeometricUtilities.java

示例7: getType

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
public String getType() {
  final StringBuilder buffer = new StringBuilder();
  if (shape != null) {
    final PathIterator it = shape.getPathIterator(new AffineTransform());
    final float[] pts = new float[6];
    while (!it.isDone()) {
      switch (it.currentSegment(pts)) {
      case PathIterator.SEG_MOVETO:
        buffer.append('m')
              .append(',')
              .append(Math.round(pts[0]))
              .append(',')
              .append(Math.round(pts[1]));
        break;
      case PathIterator.SEG_LINETO:
      case PathIterator.SEG_CUBICTO:
      case PathIterator.SEG_QUADTO:
        buffer.append('l')
              .append(',')
              .append(Math.round(pts[0]))
              .append(',')
              .append(Math.round(pts[1]));
        break;
      case PathIterator.SEG_CLOSE:
        buffer.append('c');
        break;
      }
      it.next();
      if (!it.isDone()) {
        buffer.append(',');
      }
    }
  }
  return ID + buffer.toString();
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:36,代碼來源:NonRectangular.java

示例8: testEqual

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
static void testEqual(Path2D pathA, Path2D pathB) {
    final PathIterator itA = pathA.getPathIterator(null);
    final PathIterator itB = pathB.getPathIterator(null);

    float[] coordsA = new float[6];
    float[] coordsB = new float[6];

    int n = 0;
    for (; !itA.isDone() && !itB.isDone(); itA.next(), itB.next(), n++) {
        int typeA = itA.currentSegment(coordsA);
        int typeB = itB.currentSegment(coordsB);

        if (typeA != typeB) {
            throw new IllegalStateException("Path-segment[" + n + "] "
                + " type are not equals [" + typeA + "|" + typeB + "] !");
        }
        if (!equalsArray(coordsA, coordsB, getLength(typeA))) {
            throw new IllegalStateException("Path-segment[" + n + "] coords"
                + " are not equals [" + Arrays.toString(coordsA) + "|"
                + Arrays.toString(coordsB) + "] !");
        }
    }
    if (!itA.isDone() || !itB.isDone()) {
        throw new IllegalStateException("Paths do not have same lengths !");
    }
    log("testEqual: " + n + " segments.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Path2DCopyConstructor.java

示例9: createStrokedShape

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
public Shape createStrokedShape(Shape shape) {
    // We are flattening the path iterator to only get line segments.
    PathIterator path = shape.getPathIterator(null, 1);
    float points[] = new float[6];
    GeneralPath strokepath = new GeneralPath();
    float ix = 0, iy = 0;
    float px = 0, py = 0;

    while (!path.isDone()) {
        int type = path.currentSegment(points);
        switch (type) {
            case PathIterator.SEG_MOVETO:
                ix = px = points[0];
                iy = py = points[1];
                strokepath.moveTo(ix, iy);
                break;
            case PathIterator.SEG_LINETO:
                strokepath.append(createArrow(px, py, points[0], points[1]),
                        false);
                px = points[0];
                py = points[1];
                break;
            case PathIterator.SEG_CLOSE:
                if (px != ix && py != ix)
                    strokepath.append(createArrow(px, py, ix, iy), false);
                break;
            default:
                strokepath.append(createArrow(px, py, points[0], points[1]),
                        false);
                px = points[0];
                py = points[1];
                // never appear.
        }
        path.next();
    }
    return strokepath;
}
 
開發者ID:Vitaliy-Yakovchuk,項目名稱:ramus,代碼行數:38,代碼來源:WayStroke.java

示例10: addGeneralPath

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
private void addGeneralPath(GeneralPath path) {
        PathIterator itr = path.getPathIterator(null, 0.1);
        ArrayList<Point2D.Float> pathList = new ArrayList();
        Point2D.Float pathStart = null, lastPoint = null;
        boolean closed = false;
        while (!itr.isDone()) {
            float[] coords = new float[6];
            int segtype = itr.currentSegment(coords);
            switch (segtype) {
                case PathIterator.SEG_MOVETO:
                    pathStart = new Point2D.Float(coords[0], coords[1]); // save start point
                case PathIterator.SEG_LINETO:
                case PathIterator.SEG_QUADTO:
                case PathIterator.SEG_CUBICTO:
                    pathList.add((lastPoint = new Point2D.Float(coords[0], coords[1]))); // TODO store quads/cubes as well as linesSVG
                    break;
                case PathIterator.SEG_CLOSE:
                    closed = true;
//                            if (pathStart != null) {
//                                pathList.add(pathStart);
//                            }
                    break;
                default:
                    log.info("found other element " + segtype);
            }
            itr.next();
        }
        if (closed && lastPoint != null) {
            pathList.remove(lastPoint);
        }
        if (pathList.size() > longestPath) {
            ballPathSVG = pathList;
            longestPath = ballPathSVG.size();
        }
        pathsSVG.add(pathList);
    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:37,代碼來源:LabyrinthMap.java

示例11: feedConsumer

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
/**
 * Utility method to feed a {@link PathConsumer2D} object from a
 * given {@link PathIterator}.
 * This method deals with the details of running the iterator and
 * feeding the consumer a segment at a time.
 */
public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) {
    float coords[] = new float[6];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case PathIterator.SEG_MOVETO:
            consumer.moveTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_LINETO:
            consumer.lineTo(coords[0], coords[1]);
            break;
        case PathIterator.SEG_QUADTO:
            consumer.quadTo(coords[0], coords[1],
                            coords[2], coords[3]);
            break;
        case PathIterator.SEG_CUBICTO:
            consumer.curveTo(coords[0], coords[1],
                             coords[2], coords[3],
                             coords[4], coords[5]);
            break;
        case PathIterator.SEG_CLOSE:
            consumer.closePath();
            break;
        }
        pi.next();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:RenderingEngine.java

示例12: createStrokedShape

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
/** 
 * @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
 */
public Shape createStrokedShape (Shape shape) {
	GeneralPath result = new GeneralPath();
	PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
	float points[] = new float[6];
	float moveX = 0, moveY = 0;
	float lastX = 0, lastY = 0;
	float thisX = 0, thisY = 0;
	int type = 0;
	float next = 0;
	int phase = 0;
	while (!it.isDone()) {
		type = it.currentSegment(points);
		switch (type) {
		case PathIterator.SEG_MOVETO:
			moveX = lastX = points[0];
			moveY = lastY = points[1];
			result.moveTo(moveX, moveY);
			next = wavelength / 2;
			break;

		case PathIterator.SEG_CLOSE:
			points[0] = moveX;
			points[1] = moveY;
			// Fall into....

		case PathIterator.SEG_LINETO:
			thisX = points[0];
			thisY = points[1];
			float dx = thisX - lastX;
			float dy = thisY - lastY;
			float distance = (float)Math.sqrt(dx * dx + dy * dy);
			if (distance >= next) {
				float r = 1.0f / distance;
				while (distance >= next) {
					float x = lastX + next * dx * r;
					float y = lastY + next * dy * r;
					if ((phase & 1) == 0)
						result.lineTo(x + amplitude * dy * r, y - amplitude * dx * r);
					else
						result.lineTo(x - amplitude * dy * r, y + amplitude * dx * r);
					next += wavelength;
					phase++;
				}
			}
			next -= distance;
			lastX = thisX;
			lastY = thisY;
			if (type == PathIterator.SEG_CLOSE) result.closePath();
			break;
		}
		it.next();
	}
	return new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(result);
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:58,代碼來源:OutlineZigzagEffect.java

示例13: createStrokedShape

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
/**
 * @see java.awt.Stroke#createStrokedShape(java.awt.Shape)
 */
public Shape createStrokedShape (Shape shape) {
	GeneralPath result = new GeneralPath();
	shape = new BasicStroke(getWidth(), BasicStroke.CAP_SQUARE, getJoin()).createStrokedShape(shape);
	PathIterator it = new FlatteningPathIterator(shape.getPathIterator(null), FLATNESS);
	float points[] = new float[6];
	float moveX = 0, moveY = 0;
	float lastX = 0, lastY = 0;
	float thisX = 0, thisY = 0;
	int type = 0;
	float next = 0;
	while (!it.isDone()) {
		type = it.currentSegment(points);
		switch (type) {
		case PathIterator.SEG_MOVETO:
			moveX = lastX = randomize(points[0]);
			moveY = lastY = randomize(points[1]);
			result.moveTo(moveX, moveY);
			next = 0;
			break;

		case PathIterator.SEG_CLOSE:
			points[0] = moveX;
			points[1] = moveY;
			// Fall into....

		case PathIterator.SEG_LINETO:
			thisX = randomize(points[0]);
			thisY = randomize(points[1]);
			float dx = thisX - lastX;
			float dy = thisY - lastY;
			float distance = (float)Math.sqrt(dx * dx + dy * dy);
			if (distance >= next) {
				float r = 1.0f / distance;
				while (distance >= next) {
					float x = lastX + next * dx * r;
					float y = lastY + next * dy * r;
					result.lineTo(randomize(x), randomize(y));
					next += detail;
				}
			}
			next -= distance;
			lastX = thisX;
			lastY = thisY;
			break;
		}
		it.next();
	}

	return result;
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:54,代碼來源:OutlineWobbleEffect.java

示例14: updateLayer

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
public synchronized void updateLayer() {
	if (sceneGraph == null)
		return;

	boolean flat = false; 
	
	if (layerKey != -1) {
		flat = sceneGraph.isAFlatScene(layerKey);
		sceneGraph.disposeSubLayer(layerKey);
	}

	layerKey = sceneGraph.createSubLayer();

	if (flat)
		sceneGraph.makeFlatLayer(layerKey);

	Map<Integer, DetailedIcon> myIcons = this.getIconMap();
	int size = (int) (ICON_SIZE * symbolSize / 100f);

	if (iconRenderer == null)
		iconRenderer = new DetailedIconRenderer();

	int index = 0;
	for (UnknownData d : this.data) {
		boolean invalidStation = (Float.isNaN(d.y) || d.y > 90 || d.y < -90);
		invalidStation = invalidStation || (Float.isNaN(d.x) || d.x > 360 || d.y < -180);

		if (!invalidStation) {
			DetailedIcon icon = new DetailedIcon(ICON_PATH, Position.fromDegrees(d.y, d.x, 0));
			icon.setIconColor( this.getColor() );
			icon.setSize(new Dimension(size, size));
			icon.setHighlightScale(2);
			myIcons.put(index, icon);
			
			sceneGraph.addItem(
					new WWSceneGraph.SceneItemIcon(icon, iconRenderer),
					layerKey);
		}
		index++;
	}

	for (Polyline poly : getPolylineMap().values())
		renderableLayer.removeRenderable(poly);
	getPolylineMap().clear();

	for (int polyIndex : polylines) {
		UnknownData ud = data.get(polyIndex);
		if (ud.polyline == null) continue;

		List<Position> points = new LinkedList<Position>();

		PathIterator pi = ud.polyline.getPathIterator(new AffineTransform());
		float[] coords = new float[2];
		while (true) {
			pi.currentSegment(coords);
			if (pi.isDone()) break;
			points.add( Position.fromDegrees(coords[1] + ud.polyY0, coords[0] + ud.polyX0, 0) );
			pi.next();
		}

		Polyline pl = new Polyline(points);
		pl.setClosed(false);
		pl.setColor(Color.BLUE);
		pl.setFollowTerrain(true);
		pl.setLineWidth(2);
		getPolylineMap().put(polyIndex, pl);

		renderableLayer.addRenderable(pl);
	}
	processVisibility();
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:72,代碼來源:WWUnknownDataSet.java

示例15: convertToWPath

import java.awt.geom.PathIterator; //導入方法依賴的package包/類
/**
 * Given a Java2D <code>PathIterator</code> instance,
 * this method translates that into a Window's path
 * in the printer device context.
 */
private void convertToWPath(PathIterator pathIter) {

    float[] segment = new float[6];
    int segmentType;

    WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();

    /* Map the PathIterator's fill rule into the Window's
     * polygon fill rule.
     */
    int polyFillRule;
    if (pathIter.getWindingRule() == PathIterator.WIND_EVEN_ODD) {
        polyFillRule = WPrinterJob.POLYFILL_ALTERNATE;
    } else {
        polyFillRule = WPrinterJob.POLYFILL_WINDING;
    }
    wPrinterJob.setPolyFillMode(polyFillRule);

    wPrinterJob.beginPath();

    while (pathIter.isDone() == false) {
        segmentType = pathIter.currentSegment(segment);

        switch (segmentType) {
         case PathIterator.SEG_MOVETO:
            wPrinterJob.moveTo(segment[0], segment[1]);
            break;

         case PathIterator.SEG_LINETO:
            wPrinterJob.lineTo(segment[0], segment[1]);
            break;

        /* Convert the quad path to a bezier.
         */
         case PathIterator.SEG_QUADTO:
            int lastX = wPrinterJob.getPenX();
            int lastY = wPrinterJob.getPenY();
            float c1x = lastX + (segment[0] - lastX) * 2 / 3;
            float c1y = lastY + (segment[1] - lastY) * 2 / 3;
            float c2x = segment[2] - (segment[2] - segment[0]) * 2/ 3;
            float c2y = segment[3] - (segment[3] - segment[1]) * 2/ 3;
            wPrinterJob.polyBezierTo(c1x, c1y,
                                     c2x, c2y,
                                     segment[2], segment[3]);
            break;

         case PathIterator.SEG_CUBICTO:
            wPrinterJob.polyBezierTo(segment[0], segment[1],
                                     segment[2], segment[3],
                                     segment[4], segment[5]);
            break;

         case PathIterator.SEG_CLOSE:
            wPrinterJob.closeFigure();
            break;
        }


        pathIter.next();
    }

    wPrinterJob.endPath();

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:70,代碼來源:WPathGraphics.java


注:本文中的java.awt.geom.PathIterator.currentSegment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。