private int layout() {
// Generate the curves intervals
this.midcurve = this.spline.intervals(this.interval);
Polygon polygon;
double[][] left = new double[2][];
double[][] right = new double[2][];
this.leftcurve = new ArrayList<double[]>();
this.rightcurve = new ArrayList<double[]>();
double[][] p = new double[5][2];
int last = this.midcurve.size() - 1;
// Clear the current list of polygons
this.polygons.clear();
// Project the first left and right curve interval
p[1] = this.midcurve.get(0);
p[2] = this.midcurve.get(1);
Vector2D.vector(p[3], p[1][0], p[1][1], p[2][0], p[2][1]);
projectEdges(p, left, right);
left[1] = left[0];
right[1] = right[0];
// Project the left and right curve intervals
for (int i = 1; i < last; i++) {
p[0] = this.midcurve.get(i - 1);
p[1] = this.midcurve.get(i);
p[2] = this.midcurve.get(i + 1);
Vector2D.vector(p[3], p[0][0], p[0][1], p[1][0], p[1][1]);
Vector2D.vector(p[4], p[1][0], p[1][1], p[2][0], p[2][1]);
Vector2D.add(p[3], p[4]);
projectEdges(p, left, right);
//if (intervalsIntersect(left, right)) {
// Work out which control point we're closest to
// int closest = (int)Math.round((i / this.interval)) + 1;
// straightenCorner(closest);
// return i;
//}
// Add the polygon
polygon = new Polygon();
polygon.addPoint((int) left[0][0], (int) left[0][1]);
polygon.addPoint((int) left[1][0], (int) left[1][1]);
polygon.addPoint((int) right[1][0], (int) right[1][1]);
polygon.addPoint((int) right[0][0], (int) right[0][1]);
this.polygons.add(polygon);
// Remember current left/right points
left[1] = left[0];
right[1] = right[0];
}
// Project the last left and right curve interval
p[0] = this.midcurve.get(last - 1);
p[1] = this.midcurve.get(last);
Vector2D.vector(p[3], p[0][0], p[0][1], p[1][0], p[1][1]);
projectEdges(p, left, right);
// Add the last polygon
polygon = new Polygon();
polygon.addPoint((int) left[0][0], (int) left[0][1]);
polygon.addPoint((int) left[1][0], (int) left[1][1]);
polygon.addPoint((int) right[1][0], (int) right[1][1]);
polygon.addPoint((int) right[0][0], (int) right[0][1]);
this.polygons.add(polygon);
return -1;
}