diff --git a/public/js/webgl-book-shape-lab.js b/public/js/webgl-book-shape-lab.js
index 73eb656..a11d64a 100644
--- a/public/js/webgl-book-shape-lab.js
+++ b/public/js/webgl-book-shape-lab.js
@@ -679,7 +679,7 @@ function scoreSupportedPoint(candidate, previous, tangent, supportTangent, angle
supportError = closestDistance - bundleSpacing;
} else {
const floor = coverTopYAtX(candidate.x) + coverClearance(bundleCount);
- supportViolation = Math.max(0, floor - candidate.y);
+ supportViolation = coverSegmentViolation(previous, candidate, bundleCount);
if (!allowViolation && supportViolation > 0.00001) return Number.POSITIVE_INFINITY;
supportError = candidate.y - floor;
}
@@ -693,6 +693,18 @@ function scoreSupportedPoint(candidate, previous, tangent, supportTangent, angle
return Math.abs(supportError) * 1200 + supportViolation * 100000 + backward * 100000 + supportAlignment * 0.85 + bend * 0.22 + angleDelta * 0.04 + outwardTarget * 0.01 + targetHeight * 0.006;
}
+function coverSegmentViolation(previous, candidate, bundleCount) {
+ const clearance = coverClearance(bundleCount);
+ let violation = 0;
+ for (let sample = 1; sample <= 6; sample += 1) {
+ const t = sample / 6;
+ const x = THREE.MathUtils.lerp(previous.x, candidate.x, t);
+ const y = THREE.MathUtils.lerp(previous.y, candidate.y, t);
+ violation = Math.max(violation, coverTopYAtX(x) + clearance - y);
+ }
+ return Math.max(0, violation);
+}
+
function closestPointOnPolyline(point, polyline) {
let best = polyline[0];
let bestDistance = Number.POSITIVE_INFINITY;
diff --git a/public/webgl-book-shape-lab.html b/public/webgl-book-shape-lab.html
index edd9b5b..c487c36 100644
--- a/public/webgl-book-shape-lab.html
+++ b/public/webgl-book-shape-lab.html
@@ -74,6 +74,6 @@
-
+