get Path To Index - Java 2D Graphics

Java examples for 2D Graphics:Path

Description

get Path To Index

Demo Code


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

public class Main {
    public static GeneralPath getPathToIndex(int point, GeneralPath path) {

        GeneralPath newPath = new GeneralPath(GeneralPath.WIND_EVEN_ODD);

        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   w w w .  jav a  2  s  .  c o  m
            int segType = i.currentSegment(seg);

            if (index == 0) {
                newPath.moveTo((int) seg[0], (int) seg[1]);
            }
            if (index > 0) {
                if (index > point)
                    return newPath;
                newPath.lineTo((int) seg[0], (int) seg[1]);
            }
            index++;
        }
        return newPath;
    }
}

Related Tutorials