python again

This commit is contained in:
Chris Tsang
2023-09-16 17:59:52 +01:00
parent 79dd451da1
commit f5cce867f2
+25 -25
View File
@@ -1,24 +1,25 @@
use crate::*;
use pyo3::prelude::*; use pyo3::prelude::*;
use std::path::PathBuf;
use visioncortex::{PathSimplifyMode}; use visioncortex::PathSimplifyMode;
use super::converter::*;
/// Python binding /// Python binding
#[pyfunction] #[pyfunction]
fn convert_image_to_svg_py( image_path: &str, fn convert_image_to_svg_py(
out_path: &str, image_path: &str,
colormode: Option<&str>, // "color" or "binary" out_path: &str,
hierarchical: Option<&str>, // "stacked" or "cutout" colormode: Option<&str>, // "color" or "binary"
mode: Option<&str>, // "polygon", "spline", "none" hierarchical: Option<&str>, // "stacked" or "cutout"
filter_speckle: Option<usize>, // default: 4 mode: Option<&str>, // "polygon", "spline", "none"
color_precision: Option<i32>, // default: 6 filter_speckle: Option<usize>, // default: 4
layer_difference: Option<i32>, // default: 16 color_precision: Option<i32>, // default: 6
corner_threshold: Option<i32>, // default: 60 layer_difference: Option<i32>, // default: 16
length_threshold: Option<f64>, // in [3.5, 10] default: 4.0 corner_threshold: Option<i32>, // default: 60
max_iterations: Option<usize>, // default: 10 length_threshold: Option<f64>, // in [3.5, 10] default: 4.0
splice_threshold: Option<i32>, // default: 45 max_iterations: Option<usize>, // default: 10
path_precision: Option<u32> // default: 8 splice_threshold: Option<i32>, // default: 45
) -> PyResult<()> { path_precision: Option<u32>, // default: 8
) -> PyResult<()> {
let input_path = PathBuf::from(image_path); let input_path = PathBuf::from(image_path);
let output_path = PathBuf::from(out_path); let output_path = PathBuf::from(out_path);
@@ -43,13 +44,13 @@ fn convert_image_to_svg_py( image_path: &str,
_ => PathSimplifyMode::Spline, _ => PathSimplifyMode::Spline,
}; };
let filter_speckle = filter_speckle.unwrap_or(4); let filter_speckle = filter_speckle.unwrap_or(4);
let color_precision = color_precision.unwrap_or(6); let color_precision = color_precision.unwrap_or(6);
let layer_difference = layer_difference.unwrap_or(16); let layer_difference = layer_difference.unwrap_or(16);
let corner_threshold = corner_threshold.unwrap_or(60); let corner_threshold = corner_threshold.unwrap_or(60);
let length_threshold = length_threshold.unwrap_or(4.0); let length_threshold = length_threshold.unwrap_or(4.0);
let splice_threshold = splice_threshold.unwrap_or(45); let splice_threshold = splice_threshold.unwrap_or(45);
let max_iterations = max_iterations.unwrap_or(10); let max_iterations = max_iterations.unwrap_or(10);
let config = Config { let config = Config {
input_path, input_path,
@@ -68,7 +69,6 @@ fn convert_image_to_svg_py( image_path: &str,
..Default::default() ..Default::default()
}; };
convert_image_to_svg(config).unwrap(); convert_image_to_svg(config).unwrap();
Ok(()) Ok(())
} }