get GeneralPath Last Line - Java 2D Graphics

Java examples for 2D Graphics:Path

Description

get GeneralPath Last Line

Demo Code


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

import java.awt.geom.Line2D;

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

        for (PathIterator i = path.getPathIterator(null); !i.isDone(); i
                .next()) {//from  w w  w  . j  av a 2 s .c o  m
            int segType = i.currentSegment(seg);
            if (index == 0) {
                x1 = seg[0];
                y1 = seg[1];
                x2 = seg[0];
                y2 = seg[1];
            } else if (index == 1) {
                x2 = seg[0];
                y2 = seg[1];
            } else if (index > 1) {
                x1 = x2;
                y1 = y2;
                x2 = seg[0];
                y2 = seg[1];
            }
            index++;
        }
        return (new Line2D.Double(x1, y1, x2, y2));
    }
}

Related Tutorials