From 030d9238ac7395573efc4d961d0c8cf303030954 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 21 May 2024 22:58:43 +0200 Subject: [PATCH 1/2] Fix square end caps in the stroke tessellator --- crates/tessellation/src/stroke.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/crates/tessellation/src/stroke.rs b/crates/tessellation/src/stroke.rs index a851fd81..35032216 100644 --- a/crates/tessellation/src/stroke.rs +++ b/crates/tessellation/src/stroke.rs @@ -2148,6 +2148,33 @@ fn tessellate_last_edge( let sides = [Side::Positive, Side::Negative]; for side in 0..2 { + let side_position = p1.side_points[side].prev; + let clip = match options.end_cap { + LineCap::Square => Some(p1.half_width), + LineCap::Butt => Some(0.0), + _ => None, + }; + + if let Some(clip) = clip { + let normal = (p1.position - p0.position).normalize(); + let clip_line = Line { + point: p1.position + normal * clip, + vector: tangent(normal), + }; + let side_line = Line { + point: side_position, + vector: side_position - p0.side_points[side].next, + }; + + let intersection = clip_line + .to_f64() + .intersection(&side_line.to_f64()) + .map(|p| p.to_f32()) + .unwrap_or(p1.side_points[side].prev); + + p1.side_points[side].prev = intersection; + } + vertex.side = sides[side]; vertex.normal = (p1.side_points[side].prev - p1.position) / p1.half_width; let prev_vertex = output.add_stroke_vertex(StrokeVertex(vertex, attributes))?; From 2186ab8deccacbcb8ce15a6e1b3976ecbb42dc25 Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Tue, 21 May 2024 23:00:05 +0200 Subject: [PATCH 2/2] lyon_tessellation 1.0.15 --- Cargo.lock | 4 ++-- crates/tessellation/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1ad9939..a103724f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1600,7 +1600,7 @@ dependencies = [ [[package]] name = "lyon_path" -version = "1.0.4" +version = "1.0.5" dependencies = [ "lyon_geom", "num-traits", @@ -1609,7 +1609,7 @@ dependencies = [ [[package]] name = "lyon_tessellation" -version = "1.0.14" +version = "1.0.15" dependencies = [ "float_next_after", "lyon_extra", diff --git a/crates/tessellation/Cargo.toml b/crates/tessellation/Cargo.toml index e27c9175..e0686721 100644 --- a/crates/tessellation/Cargo.toml +++ b/crates/tessellation/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lyon_tessellation" -version = "1.0.14" +version = "1.0.15" description = "A low level path tessellation library." authors = ["Nicolas Silva "] repository = "https://github.com/nical/lyon"