Constructs a geometric shape with double precision from a list of path segments. - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

Constructs a geometric shape with double precision from a list of path segments.

Demo Code


import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.FlatteningPathIterator;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Main{
    /**/* w w w. j av  a  2  s.  c om*/
     * Constructs a geometric shape with double precision from a list of path
     * segments.
     *
     * @param segments List of path segments.
     * @return A geometric shape.
     */
    private static Shape getShapeDouble(List<PathSegment> segments) {
        Path2D.Double path = new Path2D.Double(Path2D.WIND_NON_ZERO,
                segments.size());
        for (PathSegment segment : segments) {
            double[] coords = segment.coords;
            if (segment.type == PathIterator.SEG_MOVETO) {
                path.moveTo(coords[0], coords[1]);
            } else if (segment.type == PathIterator.SEG_LINETO) {
                path.lineTo(coords[0], coords[1]);
            } else if (segment.type == PathIterator.SEG_QUADTO) {
                path.quadTo(coords[0], coords[1], coords[2], coords[3]);
            } else if (segment.type == PathIterator.SEG_CUBICTO) {
                path.curveTo(coords[0], coords[1], coords[2], coords[3],
                        coords[4], coords[5]);
            } else if (segment.type == PathIterator.SEG_CLOSE) {
                path.closePath();
            }
        }
        return path;
    }
}

Related Tutorials