diff --git a/crates/tessellation/src/stroke.rs b/crates/tessellation/src/stroke.rs index 35032216..b96edae6 100644 --- a/crates/tessellation/src/stroke.rs +++ b/crates/tessellation/src/stroke.rs @@ -1723,7 +1723,7 @@ fn compute_join_side_positions_fixed_width( let n0 = join.side_points[front_side].prev - join.position; let n1 = join.side_points[front_side].next - join.position; let (prev_normal, next_normal) = - get_clip_intersections(n0, n1, front_normal, miter_limit * 0.5 * vertex.half_width); + get_clip_intersections(n0, n1, front_normal, miter_limit * vertex.half_width); join.side_points[front_side].prev = join.position + prev_normal; join.side_points[front_side].next = join.position + next_normal; } @@ -2118,7 +2118,7 @@ fn compute_join_side_positions( let n0 = join.side_points[side].prev - join.position; let n1 = join.side_points[side].next - join.position; let (prev_normal, next_normal) = - get_clip_intersections(n0, n1, normal, miter_limit * 0.5 * join.half_width); + get_clip_intersections(n0, n1, normal, miter_limit * join.half_width); join.side_points[side].prev = join.position + prev_normal; join.side_points[side].next = join.position + next_normal; nan_check!(n0, n1, prev_normal, next_normal); @@ -3376,3 +3376,41 @@ fn issue_894() { &mut BuffersBuilder::new(&mut geometry, VariableWidthStrokeCtor), ); } + +#[test] +fn correct_miter_clip_length() { + let path_max_y = 300.0; + let line_width = 30.0; + let miter_limit = 3.0; + + let mut path = Path::builder(); + path.begin(point(-70.0, -200.0)); + path.line_to(point(0.0, path_max_y)); + path.line_to(point(70.0, -200.0)); + path.end(false); + let path = path.build(); + + let mut tessellator = StrokeTessellator::new(); + + let options = StrokeOptions::default() + .with_line_width(line_width) + .with_line_join(LineJoin::MiterClip) + .with_miter_limit(miter_limit); + + let mut mesh = VertexBuffers::new(); + let mut builder = simple_builder(&mut mesh); + tessellator + .tessellate_path(&path, &options, &mut builder) + .unwrap(); + + let max_y = mesh.vertices.iter() + .map(|p| p.y) + .reduce(|acc, y| acc.max(y)) + .unwrap(); + + // miter_length = line_width * miter_limit + // miter_clip = miter_length * 0.5 + let expected_max_y = path_max_y + line_width * miter_limit * 0.5; + + assert_eq!(expected_max_y, max_y); +} \ No newline at end of file