// Push all the curve points away from each other so the course feels more open.
for round in 0..10 {
for i in 0..curve_points.len() {
let mut p = curve_points[i].clone();
for j in 0..curve_points.len() {
if i != j {
let other = curve_points[j].clone();
let dist = (p - other).length();
p -= (other - curve_points[i]) * 10.0 / (dist * dist);
}
}
curve_points[i] = p;
}
}
// swap the order of some curve poitnts to make the course less loopy.
for i in 0..curve_points.len() {
for j in 1..curve_points.len() - 2 {
let v1 = (curve_points[j + 1] - curve_points[j]).normalize();
let v2 = (curve_points[j + 2] - curve_points[j + 1]).normalize();
if v1.dot(v2) < 0.75 {
let temp = curve_points[j + 1];
curve_points[j + 1] = curve_points[j + 2];
curve_points[j + 2] = temp;
}
}
}