Created
April 13, 2023 19:18
-
-
Save raphlinus/35d7e9acbb064ceac941313c681e4c4a to your computer and use it in GitHub Desktop.
Test running code for path simplification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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