Skip to content

Instantly share code, notes, and snippets.

@raphlinus
Created April 13, 2023 19:18
Show Gist options
  • Save raphlinus/35d7e9acbb064ceac941313c681e4c4a to your computer and use it in GitHub Desktop.
Save raphlinus/35d7e9acbb064ceac941313c681e4c4a to your computer and use it in GitHub Desktop.
Test running code for path simplification
// Adapted from code provided by @rachael-wang
use std::{env, fs};
fn main() {
let args: Vec<String> = env::args().collect();
let svg_contents = fs::read_to_string(&args[1]).unwrap();
let curve = kurbo::BezPath::from_svg(&svg_contents).expect("SVG parse error");
println!("<svg width='800' height='640' xmlns='http://www.w3.org/2000/svg'>");
println!("<g transform='translate(0 100) scale(8)'>");
println!(
" <path d='{}' stroke='#008' fill='none' stroke-width='0.1'/>",
curve.to_svg()
);
let curve_simplify = kurbo::simplify::SimplifyBezPath::new(curve);
let simplified_path = kurbo::fit_to_bezpath_opt(&curve_simplify, 0.18);
println!(
" <path d='{}' stroke='#e22' fill='none' stroke-width='0.1'/>",
simplified_path.to_svg()
);
println!("</g>");
println!("</svg>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment