use of net.sf.latexdraw.parser.svg.path.SVGPathSeg in project latexdraw by arnobl.
the class SVGModifiablePointsShape method getLinePointsFromSVGPathElement.
/**
* Gets the line points from the given SVGPathElement
*/
static List<Point> getLinePointsFromSVGPathElement(final SVGPathElement elt) {
if (elt == null) {
return Collections.emptyList();
}
final SVGPathSegList segs = elt.getSegList();
final int size = segs.get(segs.size() - 1) instanceof SVGPathSegClosePath ? segs.size() - 1 : segs.size();
// Creating a point to support when the first path element is relative.
Point2D pt = new Point2D.Double();
final List<Point> pts = new ArrayList<>();
for (int i = 0; i < size; i++) {
final SVGPathSeg seg = segs.get(i);
if (!(seg instanceof SVGPathSegLineto)) {
// NON-NLS
throw new IllegalArgumentException("The given SVG path element is not a set of lines.");
}
pt = ((SVGPathSegLineto) seg).getPoint(pt);
pts.add(ShapeFactory.INST.createPoint(pt.getX(), pt.getY()));
}
return pts;
}
Aggregations