SVG path string numeric precision

This commit is contained in:
Bobby Ng
2021-07-23 23:35:45 +08:00
committed by Chris Tsang
parent 9ce7df176a
commit d0593e716a
10 changed files with 74 additions and 17 deletions

View File

@@ -17,6 +17,7 @@ pub struct BinaryImageConverterParams {
pub max_iterations: usize,
pub splice_threshold: f64,
pub filter_speckle: usize,
pub path_precision: u32,
}
#[wasm_bindgen]
@@ -80,6 +81,7 @@ impl BinaryImageConverter {
self.svg.prepend_path(
&paths,
&color,
Some(self.params.path_precision),
);
}
self.counter += 1;

View File

@@ -21,6 +21,7 @@ pub struct ColorImageConverterParams {
pub filter_speckle: usize,
pub color_precision: i32,
pub layer_difference: i32,
pub path_precision: u32,
}
#[wasm_bindgen]
@@ -137,6 +138,7 @@ impl ColorImageConverter {
self.svg.prepend_path(
&paths,
&cluster.residue_color(),
Some(self.params.path_precision),
);
self.counter += 1;
false

View File

@@ -13,11 +13,11 @@ impl Svg {
Self { element }
}
pub fn prepend_path(&mut self, paths: &CompoundPath, color: &Color) {
pub fn prepend_path(&mut self, paths: &CompoundPath, color: &Color, precision: Option<u32>) {
let path = document()
.create_element_ns(Some("http://www.w3.org/2000/svg"), "path")
.unwrap();
let (string, offset) = paths.to_svg_string(true, PointF64::default());
let (string, offset) = paths.to_svg_string(true, PointF64::default(), precision);
path.set_attribute("d", &string).unwrap();
path.set_attribute(
"transform",