com.sksamuel.scrimage.canvas.drawables.Polyline Maven / Gradle / Ivy
package com.sksamuel.scrimage.canvas.drawables;
import com.sksamuel.scrimage.canvas.Drawable;
import com.sksamuel.scrimage.canvas.GraphicsContext;
import com.sksamuel.scrimage.graphics.RichGraphics2D;
import java.util.List;
public class Polyline implements Drawable {
private final List points;
private final GraphicsContext context;
public Polyline(List points, GraphicsContext context) {
this.points = points;
this.context = context;
}
@Override
public void draw(RichGraphics2D g) {
int[] xs = points.stream().mapToInt(p -> p.x).toArray();
int[] ys = points.stream().mapToInt(p -> p.y).toArray();
g.drawPolyline(xs, ys, points.size());
}
public Polygon close() {
return new Polygon(points, context);
}
@Override
public GraphicsContext context() {
return context;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy