* @param means Cluster means
* @return SVG path
*/
public static SVGPath drawVoronoi(Projection2D proj, List<SweepHullDelaunay2D.Triangle> delaunay, List<double[]> means) {
final SVGPath path = new SVGPath();
CanvasSize viewport = proj.estimateViewport();
for(int i = 0; i < delaunay.size(); i++) {
SweepHullDelaunay2D.Triangle del = delaunay.get(i);
final double[] projcx = proj.fastProjectDataToRenderSpace(del.m.getArrayRef());
if(del.ab > i) {
Triangle oth = delaunay.get(del.ab);
path.moveTo(projcx);
path.drawTo(proj.fastProjectDataToRenderSpace(oth.m.getArrayRef()));
}
else if(del.ab < 0) {
double[] dirv = VMath.minus(means.get(del.a), means.get(del.b));
VMath.rotate90Equals(dirv);
double[] dir = proj.fastProjectRelativeDataToRenderSpace(dirv);
final double factor = viewport.continueToMargin(projcx, dir);
if(factor > 0) {
path.moveTo(projcx);
path.relativeLineTo(factor * dir[0], factor * dir[1]);
}
}
if(del.bc > i) {
Triangle oth = delaunay.get(del.bc);
path.moveTo(projcx);
path.drawTo(proj.fastProjectDataToRenderSpace(oth.m.getArrayRef()));
}
else if(del.bc < 0) {
double[] dirv = VMath.minus(means.get(del.b), means.get(del.c));
VMath.rotate90Equals(dirv);
double[] dir = proj.fastProjectRelativeDataToRenderSpace(dirv);
final double factor = viewport.continueToMargin(projcx, dir);
if(factor > 0) {
path.moveTo(projcx);
path.relativeLineTo(factor * dir[0], factor * dir[1]);
}
}
if(del.ca > i) {
Triangle oth = delaunay.get(del.ca);
path.moveTo(projcx);
path.drawTo(proj.fastProjectDataToRenderSpace(oth.m.getArrayRef()));
}
else if(del.ca < 0) {
double[] dirv = VMath.minus(means.get(del.c), means.get(del.a));
VMath.rotate90Equals(dirv);
double[] dir = proj.fastProjectRelativeDataToRenderSpace(dirv);
final double factor = viewport.continueToMargin(projcx, dir);
if(factor > 0) {
path.moveTo(projcx);
path.relativeLineTo(factor * dir[0], factor * dir[1]);
}
}