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" 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))?;