use crate::layout::render_list::StrokeStyle;
pub fn corner_fade(on: f32) -> f32 {
let t = on.clamp(0.0, 1.0);
t * t * (3.0 - 2.0 * t)
}
pub fn corner_color_mix(turn: f32) -> f32 {
let t = turn.clamp(0.0, 1.0);
t * t * (3.0 - 2.0 * t)
}
pub const HOLE_MARGIN: f32 = 1.0;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct StrokeShape {
pub half: [f32; 2],
pub radii: [f32; 4],
pub stroke: [f32; 4],
pub style: StrokeStyle,
}
fn corner(x: f32, y: f32) -> usize {
match (y < 0.0, x < 0.0) {
(true, true) => 0,
(true, false) => 1,
(false, false) => 2,
(false, true) => 3,
}
}
fn elliptical_box_distance(x: f32, y: f32, half: [f32; 2], radius: [f32; 2]) -> f32 {
let (rx, ry) = (radius[0].max(0.0), radius[1].max(0.0));
let qx = x.abs() - half[0] + rx;
let qy = y.abs() - half[1] + ry;
if qx > 0.0 && qy > 0.0 {
if rx <= 0.0 || ry <= 0.0 {
return qx.max(qy);
}
let (nx, ny) = (qx / rx, qy / ry);
let length = nx.hypot(ny);
if length <= 1e-6 {
return -rx.min(ry);
}
let gradient = (nx / rx).hypot(ny / ry).max(1e-6);
return (length - 1.0) * length / gradient;
}
(qx - rx).max(qy - ry)
}
fn inset(width: f32) -> f32 {
if width > 0.0 { width } else { -HOLE_MARGIN }
}
fn quadrant_widths(x: f32, y: f32, shape: &StrokeShape) -> [f32; 2] {
let [top, right, bottom, left] = shape.stroke.map(|width| width.max(0.0));
[if x < 0.0 { left } else { right }, if y < 0.0 { top } else { bottom }]
}
fn corner_widths(sides: [f32; 2], radius: f32) -> [f32; 2] {
if radius <= 0.0 {
return sides;
}
let width = sides[0].max(sides[1]);
sides.map(|side| if side <= 0.0 { width } else { side })
}
fn ring_widths(x: f32, y: f32, shape: &StrokeShape, radius: f32, sides: [f32; 2]) -> [f32; 2] {
let corner = corner_widths(sides, radius);
if corner == sides {
return sides;
}
let radii_at = shape.style.radii_at;
let p = [x.abs(), y.abs()];
let in_arc = (0..2).all(|axis| {
let edge = shape.half[axis] + radii_at * (corner[axis] - sides[axis]);
p[axis] > edge - (radius + radii_at * corner[axis])
});
if in_arc { corner } else { sides }
}
fn inset_box(half: [f32; 2], [top, right, bottom, left]: [f32; 4]) -> ([f32; 2], [f32; 2]) {
(
[0.5 * (left - right), 0.5 * (top - bottom)],
[
(half[0] - 0.5 * (left + right)).max(0.0),
(half[1] - 0.5 * (top + bottom)).max(0.0),
],
)
}
pub fn stroke_distance(x: f32, y: f32, shape: &StrokeShape) -> f32 {
let radius = shape.radii[corner(x, y)].max(0.0);
let radii_at = shape.style.radii_at;
let sides = quadrant_widths(x, y, shape);
let corner = ring_widths(x, y, shape, radius, sides);
let reach = [radii_at * (corner[0] - sides[0]), radii_at * (corner[1] - sides[1])];
let mut outward = [0.0; 4];
let mut insets = shape.stroke.map(|width| inset(width.max(0.0)));
let (across_side, along_side) = (if x < 0.0 { 3 } else { 1 }, if y < 0.0 { 0 } else { 2 });
outward[across_side] = reach[0];
outward[along_side] = reach[1];
insets[across_side] = inset(corner[0]);
insets[along_side] = inset(corner[1]);
let outer_radius = if radius > 0.0 {
[radius + radii_at * corner[0], radius + radii_at * corner[1]]
} else {
[0.0; 2]
};
let hole_radius = if radius > 0.0 {
[
(outer_radius[0] - inset(corner[0])).max(0.0),
(outer_radius[1] - inset(corner[1])).max(0.0),
]
} else {
[0.0; 2]
};
let (outer_centre, outer_half) = inset_box(shape.half, outward.map(|reach| -reach));
let outer = elliptical_box_distance(x - outer_centre[0], y - outer_centre[1], outer_half, outer_radius);
let hole_insets = [0, 1, 2, 3].map(|side| insets[side] - outward[side]);
let (hole_centre, hole_half) = inset_box(shape.half, hole_insets);
let hole = elliptical_box_distance(x - hole_centre[0], y - hole_centre[1], hole_half, hole_radius);
outer.max(-hole)
}
pub fn corner_turn(x: f32, y: f32, shape: &StrokeShape) -> f32 {
let radius = shape.radii[corner(x, y)].max(0.0);
let radii_at = shape.style.radii_at;
let sides = quadrant_widths(x, y, shape);
let corner = corner_widths(sides, radius);
let p = [x.abs(), y.abs()];
let edge = [0, 1].map(|axis| shape.half[axis] + radii_at * (corner[axis] - sides[axis]));
let outer_radius = if radius > 0.0 {
[radius + radii_at * corner[0], radius + radii_at * corner[1]]
} else {
[0.0; 2]
};
let d = [p[0] - (edge[0] - outer_radius[0]), p[1] - (edge[1] - outer_radius[1])];
if d[0] > 0.0 && d[1] > 0.0 && outer_radius[0] > 0.0 {
return (d[0] / outer_radius[0]).atan2(d[1] / outer_radius[1]) * std::f32::consts::FRAC_2_PI;
}
if d[0] <= 0.0 && d[1] > 0.0 {
return 0.0;
}
if d[0] > 0.0 && d[1] <= 0.0 {
return 1.0;
}
let to_edge = [edge[0] - p[0], edge[1] - p[1]];
let span = corner[0].hypot(corner[1]).max(1e-4);
(0.5 + (to_edge[1] * corner[0] - to_edge[0] * corner[1]) / span).clamp(0.0, 1.0)
}
pub fn corner_fade_at(x: f32, y: f32, shape: &StrokeShape) -> f32 {
let radius = shape.radii[corner(x, y)].max(0.0);
let [across, along] = quadrant_widths(x, y, shape);
if across <= 0.0 && along <= 0.0 {
let [top, right, bottom, left] = shape.stroke.map(|width| width.max(0.0));
let far = [if x < 0.0 { right } else { left }, if y < 0.0 { bottom } else { top }];
let from_far = [shape.half[0] + x.abs() - 1.0, shape.half[1] + y.abs() - 1.0];
return if from_far[0] < far[0] || from_far[1] < far[1] {
1.0
} else {
0.0
};
}
if radius <= 0.0 || (across > 0.0) == (along > 0.0) {
return 1.0;
}
let turn = corner_turn(x, y, shape);
if along > 0.0 {
corner_fade(1.0 - turn)
} else {
corner_fade(turn)
}
}
pub fn side_color_weights(x: f32, y: f32, shape: &StrokeShape) -> [f32; 4] {
let [across, along] = quadrant_widths(x, y, shape);
let (across_side, along_side) = (if x < 0.0 { 3 } else { 1 }, if y < 0.0 { 0 } else { 2 });
let mut weights = [0.0; 4];
if along <= 0.0 {
weights[across_side] = 1.0;
} else if across <= 0.0 {
weights[along_side] = 1.0;
} else {
let mix = corner_color_mix(corner_turn(x, y, shape));
weights[along_side] = 1.0 - mix;
weights[across_side] = mix;
}
weights
}
const CORNER_BIAS: f32 = 0.01;
fn first_edge(first: f32, second: f32, first_width: f32, second_width: f32) -> bool {
if second_width <= 0.0 {
true
} else if first_width <= 0.0 {
false
} else {
first <= second + CORNER_BIAS
}
}
pub fn outline_position(x: f32, y: f32, half: [f32; 2], radii: [f32; 4], stroke: [f32; 4]) -> (f32, f32) {
let [hx, hy] = half;
let limit = hx.min(hy).max(0.0);
let [r0, r1, r2, r3] = radii.map(|radius| radius.clamp(0.0, limit));
let quarter = std::f32::consts::FRAC_PI_2;
let top = (2.0 * hx - r0 - r1).max(0.0);
let right = (2.0 * hy - r1 - r2).max(0.0);
let bottom = (2.0 * hx - r2 - r3).max(0.0);
let left = (2.0 * hy - r3 - r0).max(0.0);
let right_arc = top;
let right_edge = right_arc + quarter * r1;
let bottom_arc = right_edge + right;
let bottom_edge = bottom_arc + quarter * r2;
let left_arc = bottom_edge + bottom;
let left_edge = left_arc + quarter * r3;
let top_arc = left_edge + left;
let total = top_arc + quarter * r0;
let on_top = (x + hx - r0).clamp(0.0, top);
let on_right = right_edge + (y + hy - r1).clamp(0.0, right);
let on_bottom = bottom_edge + (hx - r2 - x).clamp(0.0, bottom);
let on_left = left_edge + (hy - r3 - y).clamp(0.0, left);
let position = match corner(x, y) {
0 => {
let (cx, cy) = (-hx + r0, -hy + r0);
if x < cx && y < cy {
top_arc + (cy - y).atan2(cx - x) * r0
} else if first_edge(x + hx, y + hy, stroke[3], stroke[0]) {
on_left
} else {
on_top
}
}
1 => {
let (cx, cy) = (hx - r1, -hy + r1);
if x > cx && y < cy {
right_arc + (x - cx).atan2(cy - y) * r1
} else if first_edge(y + hy, hx - x, stroke[0], stroke[1]) {
on_top
} else {
on_right
}
}
2 => {
let (cx, cy) = (hx - r2, hy - r2);
if x > cx && y > cy {
bottom_arc + (y - cy).atan2(x - cx) * r2
} else if first_edge(hx - x, hy - y, stroke[1], stroke[2]) {
on_right
} else {
on_bottom
}
}
_ => {
let (cx, cy) = (-hx + r3, hy - r3);
if x < cx && y > cy {
left_arc + (cx - x).atan2(y - cy) * r3
} else if first_edge(hy - y, x + hx, stroke[2], stroke[3]) {
on_bottom
} else {
on_left
}
}
};
(position, total)
}
pub fn dash_coverage(position: f32, total: f32, dash: [f32; 2]) -> f32 {
let [on, off] = dash;
if on <= 0.0 || off <= 0.0 || total <= 0.0 {
return 1.0;
}
let period = on + off;
let fitted = total / (total / period + 0.5).floor().max(1.0);
let on = on * fitted / period;
let phase = position - (position / fitted).floor() * fitted;
let distance = if phase <= on {
-phase.min(on - phase)
} else {
(phase - on).min(fitted - phase)
};
(0.5 - distance).clamp(0.0, 1.0)
}
fn ring_sample(x: f32, y: f32, shape: &StrokeShape) -> f32 {
let distance = stroke_distance(x, y, shape);
let change =
(stroke_distance(x + 1.0, y, shape) - distance).abs() + (stroke_distance(x, y + 1.0, shape) - distance).abs();
(0.5 - distance / (0.5 * change.max(1.0))).clamp(0.0, 1.0)
}
pub fn stroke_coverage(x: f32, y: f32, shape: &StrokeShape) -> f32 {
if shape.half[0] <= 0.0 || shape.half[1] <= 0.0 {
return 0.0;
}
let centre = stroke_distance(x, y, shape);
let ring = if centre > 2.0 {
0.0
} else if centre < -2.0 {
1.0
} else {
[(-0.25, -0.25), (0.25, -0.25), (-0.25, 0.25), (0.25, 0.25)]
.into_iter()
.map(|(dx, dy)| ring_sample(x + dx, y + dy, shape))
.sum::<f32>()
* 0.25
};
let ring = if ring > 0.0 {
ring * corner_fade_at(x, y, shape)
} else {
ring
};
if ring <= 0.0 || shape.style.dash[0] <= 0.0 {
return ring;
}
let (position, total) = outline_position(x, y, shape.half, shape.radii, shape.stroke);
ring * dash_coverage(position, total, shape.style.dash)
}
#[cfg(test)]
mod tests {
use super::*;
fn shape(stroke: [f32; 4], radius: f32, radii_at: f32) -> StrokeShape {
StrokeShape {
half: [50.0, 20.0],
radii: [radius; 4],
stroke,
style: StrokeStyle {
radii_at,
..StrokeStyle::default()
},
}
}
#[test]
fn a_ring_of_one_width_is_what_it_always_was() {
let ring = shape([2.0; 4], 8.0, 0.0);
assert_eq!(stroke_coverage(0.0, -19.0, &ring), 1.0);
assert_eq!(stroke_coverage(0.0, -17.0, &ring), 0.0);
assert_eq!(stroke_coverage(-49.0, 0.0, &ring), 1.0);
assert_eq!(stroke_coverage(-47.0, 0.0, &ring), 0.0);
let diagonal = std::f32::consts::FRAC_1_SQRT_2;
let on_ring = (-42.0 - 7.0 * diagonal, -12.0 - 7.0 * diagonal);
assert_eq!(stroke_coverage(on_ring.0, on_ring.1, &ring), 1.0);
let in_hole = (-42.0 - 4.0 * diagonal, -12.0 - 4.0 * diagonal);
assert_eq!(stroke_coverage(in_hole.0, in_hole.1, &ring), 0.0);
let outside = (-42.0 - 9.5 * diagonal, -12.0 - 9.5 * diagonal);
assert_eq!(stroke_coverage(outside.0, outside.1, &ring), 0.0);
}
#[test]
fn a_stroke_on_one_side_goes_round_a_rounded_corner_at_its_width_and_fades_out() {
let left = shape([0.0, 0.0, 0.0, 4.0], 10.0, 0.0);
assert_eq!(stroke_coverage(-48.0, 0.0, &left), 1.0);
assert_eq!(stroke_coverage(-45.0, 0.0, &left), 0.0);
assert_eq!(stroke_coverage(-49.5, -19.5, &left), 0.0);
let at = |angle_deg: f32, radius: f32| {
let angle = angle_deg.to_radians();
(-40.0 - radius * angle.cos(), -10.0 - radius * angle.sin())
};
for angle in [10.0, 45.0, 80.0] {
let depth = (0..40)
.map(|step| 10.0 - step as f32 * 0.25)
.filter(|radius| {
let (x, y) = at(angle, *radius);
stroke_distance(x, y, &left) < 0.0
})
.count() as f32
* 0.25;
assert!((3.75..=4.25).contains(&depth), "the width at {angle} degrees: {depth}");
}
let coverage = |angle: f32| {
let (x, y) = at(angle, 8.0);
stroke_coverage(x, y, &left)
};
let (low, middle, high) = (coverage(10.0), coverage(45.0), coverage(80.0));
assert!(low > middle && middle > high, "{low} {middle} {high}");
assert!(low > 0.9, "nearly whole near the side: {low}");
assert!((0.4..=0.6).contains(&middle), "half way round: {middle}");
assert!(high < 0.1, "nearly nothing near the top edge: {high}");
assert_eq!(stroke_coverage(-40.0, -18.0, &left), 0.0, "where the top edge starts");
}
#[test]
fn a_stroke_on_one_side_ends_at_a_square_corner() {
let left = shape([0.0, 0.0, 0.0, 4.0], 0.0, 0.0);
assert_eq!(stroke_coverage(-48.0, -19.5, &left), 1.0);
assert_eq!(stroke_coverage(-48.0, 19.5, &left), 1.0);
assert_eq!(stroke_coverage(-45.0, -19.5, &left), 0.0);
assert_eq!(stroke_coverage(-48.0, -20.6, &left), 0.0);
}
#[test]
fn a_stroke_outside_the_box_goes_round_the_corner_past_the_side_with_none() {
let bottom = shape([0.0, 0.0, 2.0, 0.0], 8.0, 1.0);
assert!(bottom.style.outset(bottom.stroke) >= 2.0);
let (cx, cy) = (42.0, 10.0);
let diagonal = std::f32::consts::FRAC_1_SQRT_2;
let at = |radius: f32| {
let (x, y) = (cx + radius * diagonal, cy + radius * diagonal);
(stroke_distance(x, y, &bottom), stroke_coverage(x, y, &bottom))
};
assert!(at(7.0).0 > 0.0, "inside the element's corner");
let (distance, coverage) = at(9.0);
assert!(
distance < 0.0 && (0.3..=0.7).contains(&coverage),
"in the border: {coverage}"
);
assert!(at(11.0).0 > 0.0, "outside the border");
assert!(stroke_distance(51.0, cy + 0.5, &bottom) < 0.0);
assert!(stroke_coverage(51.0, cy + 0.5, &bottom) < 0.02);
assert!(stroke_distance(51.0, cy - 0.5, &bottom) > 0.0);
}
#[test]
fn two_sides_of_two_colors_mix_across_their_corner_at_full_coverage() {
let corner = StrokeShape {
style: StrokeStyle {
side_colors: Some([crate::node::color::Color::new(0, 0, 0, 255); 4]),
..StrokeStyle::default()
},
..shape([0.0, 0.0, 2.0, 2.0], 10.0, 0.0)
};
let at = |angle_deg: f32| {
let angle = angle_deg.to_radians();
(-40.0 - 9.0 * angle.cos(), 10.0 + 9.0 * angle.sin())
};
for angle in [5.0, 30.0, 45.0, 60.0, 85.0] {
let (x, y) = at(angle);
assert_eq!(stroke_coverage(x, y, &corner), 1.0, "coverage at {angle} degrees");
}
let weights = |angle| {
let (x, y) = at(angle);
side_color_weights(x, y, &corner)
};
assert!((weights(45.0)[2] - 0.5).abs() < 1e-3 && (weights(45.0)[3] - 0.5).abs() < 1e-3);
assert!(weights(5.0)[3] > 0.95, "near the left side: {:?}", weights(5.0));
assert!(weights(85.0)[2] > 0.95, "near the bottom side: {:?}", weights(85.0));
assert_eq!(side_color_weights(0.0, 19.0, &corner), [0.0, 0.0, 1.0, 0.0]);
assert_eq!(side_color_weights(-49.0, 0.0, &corner), [0.0, 0.0, 0.0, 1.0]);
}
#[test]
fn two_sides_meet_on_the_diagonal_of_a_square_corner() {
let corner = shape([0.0, 0.0, 2.0, 2.0], 0.0, 0.0);
assert_eq!(side_color_weights(-49.5, 18.2, &corner), [0.0, 0.0, 0.0, 1.0]);
assert_eq!(side_color_weights(-48.2, 19.5, &corner), [0.0, 0.0, 1.0, 0.0]);
assert_eq!(side_color_weights(-49.0, 19.0, &corner), [0.0, 0.0, 0.5, 0.5]);
}
#[test]
fn a_side_with_no_stroke_has_no_coverage_at_its_edge() {
let left = shape([0.0, 0.0, 0.0, 4.0], 10.0, 0.0);
for offset in [-0.4_f32, -0.1, 0.0, 0.1, 0.4] {
assert_eq!(
stroke_coverage(-20.0, -20.0 + offset, &left),
0.0,
"top beyond the corner at {offset}"
);
assert_eq!(stroke_coverage(10.0, -20.0 + offset, &left), 0.0, "top at {offset}");
assert_eq!(stroke_coverage(50.0 + offset, 3.0, &left), 0.0, "right at {offset}");
assert_eq!(stroke_coverage(10.0, 20.0 + offset, &left), 0.0, "bottom at {offset}");
let diagonal = std::f32::consts::FRAC_1_SQRT_2 * (10.0 + offset);
assert_eq!(
stroke_coverage(40.0 + diagonal, -10.0 - diagonal, &left),
0.0,
"corner at {offset}"
);
}
}
#[test]
fn radii_of_the_hole_grow_the_outer_corner_by_the_width() {
let outside = shape([2.0; 4], 8.0, 1.0);
let diagonal = std::f32::consts::FRAC_1_SQRT_2;
let (cx, cy) = (-40.0, -10.0);
let at = |radius: f32| stroke_coverage(cx - radius * diagonal, cy - radius * diagonal, &outside);
assert_eq!(at(7.0), 0.0, "inside the element's corner");
assert_eq!(at(9.0), 1.0, "in the border");
assert_eq!(at(11.0), 0.0, "outside the border");
}
#[test]
fn a_square_corner_stays_square_wherever_the_radii_are() {
let outside = shape([2.0; 4], 0.0, 1.0);
assert_eq!(stroke_coverage(-49.5, -19.5, &outside), 1.0);
assert_eq!(stroke_coverage(-47.5, -17.5, &outside), 0.0);
}
#[test]
fn the_outline_is_walked_once_clockwise_from_the_start_of_the_top_edge() {
let (half, radii) = ([50.0, 20.0], [8.0; 4]);
let at = |x: f32, y: f32| outline_position(x, y, half, radii, [2.0; 4]);
let quarter = std::f32::consts::FRAC_PI_2 * 8.0;
let (start, total) = at(-42.0, -20.0);
assert_eq!(start, 0.0);
assert!((total - (2.0 * 84.0 + 2.0 * 24.0 + 4.0 * quarter)).abs() < 1e-3);
let top_end = at(42.0, -20.0).0;
assert!((top_end - 84.0).abs() < 1e-3);
let right_start = at(50.0, -12.0).0;
assert!((right_start - (84.0 + quarter)).abs() < 1e-3);
let bottom_start = at(42.0, 20.0).0;
assert!((bottom_start - (84.0 + quarter + 24.0 + quarter)).abs() < 1e-3);
let left_end = at(-50.0, -12.0).0;
assert!((left_end - (total - quarter)).abs() < 1e-3);
let inside = at(0.0, -18.5).0;
assert!((inside - 42.0).abs() < 1e-3);
}
#[test]
fn positions_along_the_outline_never_jump() {
let (half, radii) = ([50.0, 20.0], [8.0, 0.0, 12.0, 4.0]);
let total = outline_position(0.0, 0.0, half, radii, [2.0; 4]).1;
let mut previous = None;
let mut walk = |x: f32, y: f32| {
let position = outline_position(x, y, half, radii, [2.0; 4]).0;
if let Some(last) = previous {
let step: f32 = position - last;
let step = if step < -total * 0.5 { step + total } else { step };
assert!((-0.01..=2.5).contains(&step), "from {last} to {position} at ({x}, {y})");
}
previous = Some(position);
};
let steps = 400;
for index in 0..=steps {
walk(-49.0 + 98.0 * index as f32 / steps as f32, -19.0);
}
for index in 0..=steps {
walk(49.0, -19.0 + 38.0 * index as f32 / steps as f32);
}
for index in 0..=steps {
walk(49.0 - 98.0 * index as f32 / steps as f32, 19.0);
}
for index in 0..=steps {
walk(-49.0, 19.0 - 38.0 * index as f32 / steps as f32);
}
}
#[test]
fn dashes_fit_the_outline_a_whole_number_of_times() {
assert_eq!(dash_coverage(3.0, 100.0, [6.0, 4.0]), 1.0);
assert_eq!(dash_coverage(8.0, 100.0, [6.0, 4.0]), 0.0);
assert_eq!(dash_coverage(13.0, 100.0, [6.0, 4.0]), 1.0);
let dash = 6.0 * 10.4 / 10.0;
assert_eq!(dash_coverage(dash - 1.0, 104.0, [6.0, 4.0]), 1.0);
assert_eq!(dash_coverage(dash + 1.0, 104.0, [6.0, 4.0]), 0.0);
assert_eq!(dash_coverage(103.0, 104.0, [6.0, 4.0]), 0.0);
assert_eq!(
dash_coverage(0.0, 104.0, [6.0, 4.0]),
0.5,
"the edge of a dash is half covered"
);
assert_eq!(dash_coverage(8.0, 100.0, [0.0, 0.0]), 1.0);
}
#[test]
fn a_dashed_stroke_is_its_ring_cut_along_the_outline() {
let dashed = StrokeShape {
style: StrokeStyle {
dash: [6.0, 4.0],
..StrokeStyle::default()
},
..shape([2.0; 4], 0.0, 0.0)
};
assert_eq!(stroke_coverage(-47.0, -19.0, &dashed), 1.0);
assert_eq!(stroke_coverage(-42.0, -19.0, &dashed), 0.0);
assert_eq!(stroke_coverage(-37.0, -19.0, &dashed), 1.0);
assert_eq!(stroke_coverage(-47.0, -10.0, &dashed), 0.0);
}
#[test]
fn the_dashes_of_one_side_run_to_its_ends() {
let (half, radii, stroke) = ([75.0, 20.0], [0.0; 4], [0.0, 0.0, 2.0, 0.0]);
let bottom_edge = 150.0 + 40.0;
for (x, along) in [(74.5, 0.5), (73.5, 1.5), (0.0, 75.0), (-73.5, 148.5), (-74.5, 149.5)] {
for y in [18.5, 19.5] {
let position = outline_position(x, y, half, radii, stroke).0;
assert!(
(position - (bottom_edge + along)).abs() < 1e-3,
"({x}, {y}): {position}"
);
}
}
}
}