mirror of
https://github.com/visioncortex/vtracer.git
synced 2025-12-06 17:15:41 -08:00
SVG path string numeric precision
This commit is contained in:
@@ -22,7 +22,7 @@ console_log = { version = "0.2", features = ["color"] }
|
||||
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
visioncortex = "0.4.0"
|
||||
visioncortex = "0.6.0"
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
# logging them with `console.error`. This is great for development, but requires
|
||||
|
||||
@@ -185,6 +185,19 @@
|
||||
<input id="splice" type="range" min="0" max="180" step="1" value="45">
|
||||
</div>
|
||||
|
||||
<div style="display: none">
|
||||
<div class="spline-options">
|
||||
<div title="Number of decimal places used in svg path string">
|
||||
Path Precision <span>(More digits)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div id="pathprecisionvalue" class="spline-options">
|
||||
8
|
||||
</div>
|
||||
<div class="spline-options">
|
||||
<input id="pathprecision" class="uk-range" type="range" min="0" max="16" step="1" value="8">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="./bootstrap.js"></script>
|
||||
|
||||
@@ -52,6 +52,7 @@ var presetConfigs = [
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 4,
|
||||
color_precision: 6,
|
||||
path_precision: 8,
|
||||
layer_difference: 16,
|
||||
mode: 'spline',
|
||||
corner_threshold: 60,
|
||||
@@ -66,6 +67,7 @@ var presetConfigs = [
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 4,
|
||||
color_precision: 8,
|
||||
path_precision: 8,
|
||||
layer_difference: 25,
|
||||
mode: 'spline',
|
||||
corner_threshold: 60,
|
||||
@@ -77,9 +79,10 @@ var presetConfigs = [
|
||||
{
|
||||
src: 'assets/samples/Gum Tree Vector.jpg',
|
||||
clustering_mode: 'color',
|
||||
clustering_hierarchical: 'cutout',
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 4,
|
||||
color_precision: 8,
|
||||
path_precision: 8,
|
||||
layer_difference: 28,
|
||||
mode: 'spline',
|
||||
corner_threshold: 60,
|
||||
@@ -94,6 +97,7 @@ var presetConfigs = [
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 8,
|
||||
color_precision: 7,
|
||||
path_precision: 8,
|
||||
layer_difference: 64,
|
||||
mode: 'spline',
|
||||
corner_threshold: 60,
|
||||
@@ -108,6 +112,7 @@ var presetConfigs = [
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 10,
|
||||
color_precision: 8,
|
||||
path_precision: 8,
|
||||
layer_difference: 48,
|
||||
mode: 'spline',
|
||||
corner_threshold: 180,
|
||||
@@ -122,6 +127,7 @@ var presetConfigs = [
|
||||
clustering_hierarchical: 'stacked',
|
||||
filter_speckle: 0,
|
||||
color_precision: 8,
|
||||
path_precision: 8,
|
||||
layer_difference: 0,
|
||||
mode: 'none',
|
||||
corner_threshold: 180,
|
||||
@@ -178,6 +184,9 @@ function loadConfig(config) {
|
||||
document.getElementById('layerdifferencevalue').innerHTML = globallayerdifference;
|
||||
document.getElementById('layerdifference').value = globallayerdifference;
|
||||
|
||||
globalpathprecision = config.path_precision;
|
||||
document.getElementById('pathprecisionvalue').innerHTML = globalpathprecision;
|
||||
document.getElementById('pathprecision').value = globalpathprecision;
|
||||
}
|
||||
|
||||
// Choose template from gallery
|
||||
@@ -244,7 +253,8 @@ var globalcorner = parseInt(document.getElementById('corner').value),
|
||||
globalsplice = parseInt(document.getElementById('splice').value),
|
||||
globalfilterspeckle = parseInt(document.getElementById('filterspeckle').value),
|
||||
globalcolorprecision = parseInt(document.getElementById('colorprecision').value),
|
||||
globallayerdifference = parseInt(document.getElementById('layerdifference').value);
|
||||
globallayerdifference = parseInt(document.getElementById('layerdifference').value),
|
||||
globalpathprecision = parseInt(document.getElementById('pathprecision').value);
|
||||
|
||||
// Load past inputs from localStorage
|
||||
/*
|
||||
@@ -327,6 +337,12 @@ document.getElementById('splice').addEventListener('change', function (e) {
|
||||
restart();
|
||||
});
|
||||
|
||||
document.getElementById('pathprecision').addEventListener('change', function (e) {
|
||||
globalpathprecision = parseInt(this.value);
|
||||
document.getElementById('pathprecisionvalue').innerHTML = this.value;
|
||||
restart();
|
||||
});
|
||||
|
||||
// Save inputs before unloading
|
||||
/*
|
||||
window.addEventListener('beforeunload', function () {
|
||||
@@ -404,6 +420,7 @@ function restart() {
|
||||
'filter_speckle': globalfilterspeckle*globalfilterspeckle,
|
||||
'color_precision': 8-globalcolorprecision,
|
||||
'layer_difference': globallayerdifference,
|
||||
'path_precision': globalpathprecision,
|
||||
});
|
||||
if (runner) {
|
||||
runner.stop();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user