MCPcopy Create free account
hub / github.com/alceal/plotlars / smooth_svg_lines

Function smooth_svg_lines

crates/plotlars-plotters/src/render/mod.rs:201–210  ·  view source on GitHub ↗

Post-process SVG to improve line rendering quality: 1. Inject round joins/caps so thick strokes blend smoothly at vertices. 2. Simplify dense polylines (Ramer-Douglas-Peucker) to remove sub-pixel zigzag noise caused by plotters' integer coordinate rounding. No-op for plots without polylines (bar/box/heatmap).

(svg: &mut String)

Source from the content-addressed store, hash-verified

199///
200/// No-op for plots without polylines (bar/box/heatmap).
201fn smooth_svg_lines(svg: &mut String) {
202 if !svg.contains("<polyline ") {
203 return;
204 }
205 *svg = svg.replace(
206 "<polyline fill=\"none\"",
207 "<polyline stroke-linejoin=\"round\" stroke-linecap=\"round\" fill=\"none\"",
208 );
209 simplify_svg_polylines(svg);
210}
211
212/// Find every `points="..."` attribute in the SVG and, when the polyline has
213/// enough vertices, apply Ramer-Douglas-Peucker to remove redundant ones.

Callers 2

save_to_fileFunction · 0.85
render_to_svg_stringFunction · 0.85

Calls 1

simplify_svg_polylinesFunction · 0.85

Tested by

no test coverage detected