Sketch: leave out the exact roundoff estimate away from the pixel bound (#10267)
A flat node's roundoff allowance took a hypot per control point. Twice |x| + |y| bounds each hypot from above with room to spare for rounding, and rounding keeps sums monotonic, so whenever the flatness test passes with that larger allowance it passes with the exact one too. Only nodes whose chord distance comes near the 0.5 px bound (or with a non-finite term) now take the exact hypots, and they decide as before. Same result for every node: the reference comparison test still matches bit for bit. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
a69a7c6ffe
commit
a8be28563c
@@ -272,19 +272,31 @@ fn sample(segment: &Seg2, plane: &Plane, view: &PixelCurveView, budget: &mut Sam
|
||||
// Keep floating-point roundoff inside the advertised bound.
|
||||
// Absolute summands also cover cancellation in VP multiplication.
|
||||
// Subdivision propagates roundoff from the original homogeneous hull.
|
||||
let projection_error = q
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let safe_w = p[3] - e[3];
|
||||
if safe_w <= 0.0 {
|
||||
return f64::INFINITY;
|
||||
}
|
||||
let x = (e[0] + (p[0] / p[3]).abs() * e[3]) / safe_w * view.width_px * 0.5;
|
||||
let y = (e[1] + (p[1] / p[3]).abs() * e[3]) / safe_w * view.height_px * 0.5;
|
||||
x.hypot(y)
|
||||
})
|
||||
.fold(0.0, f64::max);
|
||||
let allowance = projection_error + magnitude * f64::EPSILON * 128.0;
|
||||
let mut roundoff = [(0.0, 0.0); MAX_CONTROLS];
|
||||
for (r, p) in roundoff.iter_mut().zip(q) {
|
||||
let safe_w = p[3] - e[3];
|
||||
if safe_w <= 0.0 {
|
||||
// An infinite allowance: never flat.
|
||||
return false;
|
||||
}
|
||||
let x = (e[0] + (p[0] / p[3]).abs() * e[3]) / safe_w * view.width_px * 0.5;
|
||||
let y = (e[1] + (p[1] / p[3]).abs() * e[3]) / safe_w * view.height_px * 0.5;
|
||||
*r = (x, y);
|
||||
}
|
||||
let roundoff = &roundoff[..n];
|
||||
let margin = magnitude * f64::EPSILON * 128.0;
|
||||
// |x| + |y| is never less than hypot(x, y), and twice it leaves far more room
|
||||
// than the rounding of either. Rounding keeps sums in order, so when the test
|
||||
// passes with this larger allowance it passes with the exact one too: the
|
||||
// costly `hypot`s are only needed for nodes near the bound.
|
||||
if roundoff.iter().all(|(x, y)| x.is_finite() && y.is_finite()) {
|
||||
let upper = roundoff.iter().map(|(x, y)| (x.abs() + y.abs()) * 2.0).fold(0.0, f64::max) + margin;
|
||||
if upper.is_finite() && upper < PIXEL_ERROR && off_chord.iter().all(|d| d + upper <= PIXEL_ERROR) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
let projection_error = roundoff.iter().map(|(x, y)| x.hypot(*y)).fold(0.0, f64::max);
|
||||
let allowance = projection_error + margin;
|
||||
allowance < PIXEL_ERROR && off_chord.iter().all(|d| d + allowance <= PIXEL_ERROR)
|
||||
});
|
||||
if !flat || !depth_safe {
|
||||
|
||||
Reference in New Issue
Block a user