Render: thin curve lines stop where the curve turns back

Each line end of a curve drawn as lines moved out by the curve's whole gap
from the chords beside it, including the part along the chord. Where a
curve runs out and back along almost one line, that part points along the
curve, so the end moved past the turn: a cubic from (0, 0) out to x = 75
and back drew its band out to x = 112.5. The ends now move only across
their chords.
This commit is contained in:
dotCooCoo committed 2026-11-28 13:49:09 -08:00
1 parent ce09bd96b4
commit d91b815690
2 files changed
+27 -2

No files matched your search

+10 -2
View File
@@ -397,9 +397,17 @@ fn params(c: &CubicBez, most: usize, chord: f64, pin_start: bool, pin_end: bool)
}
/// How far the curve `c` lies from the chord between parameters `a` and `b`, at its parameter
/// midway: the curve's point there minus the chord's middle.
/// midway: the part across the chord of the curve's point there minus the chord's middle. A chord
/// of no length keeps the whole difference.
fn bulge(c: &CubicBez, a: f64, b: f64) -> Vec2 {
c.eval((a + b) / 2.0) - c.eval(a).midpoint(c.eval(b))
let (p, q) = (c.eval(a), c.eval(b));
let gap = c.eval((a + b) / 2.0) - p.midpoint(q);
let along = q - p;
let len2 = along.hypot2();
if !(len2 > 0.0 && len2.is_finite()) {
return gap;
}
gap - along * (gap.dot(along) / len2)
}
/// A curve of a subpath drawn as lines: the curve, its line ends' parameters, whether its first and
+17
View File
@@ -91,6 +91,23 @@ fn thin_strokes_drawn_as_lines_keep_caps_joins_and_holes() {
assert_eq!(o.winding(kurbo::Point::new(300.0, 300.0)), 0, "the hole");
}
/// A thin curve that runs out and back along almost the same line ends where the curve turns
/// back. The curve goes from (0, 0) to x = 75 and back; its outline reaches no further than half
/// the stroke's width past that.
#[test]
fn thin_strokes_drawn_as_lines_stop_where_a_curve_turns_back() {
let (w, tol, e) = (0.5, 0.25, 1e-9);
let mut path = BezPath::new();
path.move_to((0.0, 0.0));
path.curve_to((100.0, e / 3.0), (100.0, 2.0 * e / 3.0), (0.0, e));
let st = StrokeLayer::new(Paint::solid(Color::BLACK), w);
let o = raster_stroke_outline(&path, &st, w, tol);
let inside = |x: f64| o.winding(kurbo::Point::new(x, 0.0)) != 0;
assert!(inside(10.0) && inside(70.0), "the band");
let far = o.bounding_box().x1;
assert!(far <= 75.0 + w / 2.0 + 1e-6, "the outline reaches x = {far}");
}
/// Independently integrate coverage in radial/angle bins of an original notched ring. Checking
/// only the outline geometry misses raster flattening that cancels its two nearby contours.
#[test]