get GeneralPath Index Point - Java 2D Graphics

Java examples for 2D Graphics:Path

Description

get GeneralPath Index Point

Demo Code


//package com.java2s;
import java.awt.geom.PathIterator;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;

public class Main {
    public static Point2D getIndexPoint(int pos, GeneralPath path) {
        double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
        int index = 0;
        double seg[] = new double[6];

        for (PathIterator i = path.getPathIterator(null); !i.isDone(); i
                .next()) {/*from  www  .j av  a 2s.c  o m*/
            int segType = i.currentSegment(seg);

            if (index == 0) {
                x1 = seg[0];
                y1 = seg[1];
                x2 = x1;
                y2 = y1;
            }
            if (index > 0) {
                x1 = x2;
                y1 = y2;
                x2 = seg[0];
                y2 = seg[1];
                if (pos + 1 == index)
                    return (new Point2D.Double(x1, y1));
            }
            index++;
        }
        System.out.println("Error in getIndexPoint: 0<=pos<" + index);
        return null;
    }
}

Related Tutorials