Width profiles: keep the profile docs in step with its shape

The end-slope removal leaves the profile's ends on their span's own slope;
say so in the interpolation and tangent docs, and keep the neighboring
comment wording.
This commit is contained in:
adambelis committed 2026-11-20 18:40:33 +01:00
1 parent 82c3c38ecc
commit cd3dda3f2a
1 file changed
+17 -11
+17 -11
View File
@@ -26,11 +26,15 @@ impl WidthProfile {
pub fn at(&self, t: f64) -> (f64, f64) {
Self::at_points(&self.points, t)
}
/// [`Self::at`] of a profile's points (a preset's or a saved profile's). Each side runs through
/// its points on a monotone cubic curve (Fritsch–Carlson): it flows through a width point
/// without a kink, turns flat at a point wider or narrower than both neighbours, and never
/// goes past either point of the span it is in (#5714). Points on one straight line stay on
/// it. A step (two points at one position, [`Self::around`]) ends the curve on each side of it.
/// [`Self::at`] of a profile's points (a preset's or a saved profile's).
///
/// Each side runs through its points on a cubic Hermite curve, its slope at each one the
/// weighted harmonic mean of the secants either side (Fritsch–Carlson). That is C1 continuous
/// and monotone between points, so it never overshoots them, a point eases into its neighbours
/// instead of making a corner, and moving one reshapes the curve as far as its neighbours'
/// neighbours (their slopes depend on it). The ends of a run take the span's own slope, so a
/// two-point profile stays a straight taper. Two points at one `t` are still a step: each run
/// either side ends independently at it.
pub fn at_points(p: &[(f64, f64, f64)], t: f64) -> (f64, f64) {
if p.is_empty() {
return (1.0, 1.0);
@@ -71,9 +75,10 @@ impl WidthProfile {
// Two swells between narrow necks.
ProfilePreset { id: "wave", label: "Wave", points: &[(0.0, 0.3, 0.3), (0.25, 1.0, 1.0), (0.5, 0.3, 0.3), (0.75, 1.0, 1.0), (1.0, 0.3, 0.3)] },
];
/// The widest the stroke gets, as a multiple of its weight, 1 for a profile without points. Each
/// side stays between the widths of the two points of each span ([`Self::at_points`]), but the
/// two sides needn't peak together, so a span counts its wider left and its wider right.
/// The widest the stroke gets, as a multiple of its weight, 1 for a profile without points.
/// Each side's smooth curve stays between the widths of the two points of each span
/// ([`Self::at_points`]), but the two sides needn't peak together, so a span counts its wider
/// left and its wider right.
pub fn widest(&self) -> f64 {
let p = &self.points;
if p.is_empty() {
@@ -259,9 +264,10 @@ const STEP: f64 = 1e-7;
/// The slope of one side (`v` reads it from a point) of width profile `p` at its point `j`, in
/// width per unit of position: Fritsch–Carlson's choice for a monotone cubic curve. It is 0 where
/// the point is wider or narrower than both neighbours, the weighted harmonic mean of the slopes
/// of the spans on either side elsewhere (never more than three times either, so no span
/// overshoots its points), and the span's own slope at an end of the profile or beside a step.
/// the point is wider or narrower than both neighbours, and the weighted harmonic mean of the
/// slopes of the spans on either side elsewhere (never more than three times either, so no span
/// overshoots its points). The ends of a run take their secant; a step ends the run on each
/// side, so the points either side of it do not see across it.
fn tangent(p: &[(f64, f64, f64)], j: usize, v: fn(&(f64, f64, f64)) -> f64) -> f64 {
let Some(q) = p.get(j) else { return 0.0 };
let before = j.checked_sub(1).and_then(|k| p.get(k)).filter(|a| q.0 - a.0 > STEP);