mirror of
https://github.com/visioncortex/vtracer.git
synced 2026-10-15 15:10:02 -07:00
Expose simplify in the Python and Node bindings
Config(simplify=...) / property in Python; simplify option in Node, with the tolerance documented in .pyi, index.d.ts, and both READMEs. The Node README's option list also catches up with the clustering rename and the binary/watershed options, and test.js drops the stale colorMode key (silently ignored since the rename, so its bw assertion was testing the default path) and asserts simplify shrinks output.
This commit is contained in:
+8
-5
@@ -37,11 +37,14 @@ const svg2 = vtracer.convertPixels(rgba, width, height, { clustering: 'bw' });
|
||||
### `Options` (all optional, camelCase)
|
||||
|
||||
`preset` (`"bw" | "poster" | "photo"`, applied first), `clustering`
|
||||
(`"color" | "bw"`), `hierarchical` (`"stacked" | "cutout"` for the seam-free
|
||||
mosaic), `mode` (`"pixel" | "polygon" | "spline"`), `filterSpeckle`,
|
||||
`colorPrecision`, `layerDifference`, `cornerThreshold`, `lengthThreshold`,
|
||||
`maxIterations`, `spliceThreshold`, `pathPrecision`, `palette` (list of
|
||||
`#rrggbb`), `maxColors`, `optimize` (`0 | 1 | 2`).
|
||||
(`"color-cluster" | "bw" | "watershed"`), `hierarchical` (`"stacked" | "cutout"`
|
||||
for the seam-free mosaic), `mode` (`"pixel" | "polygon" | "spline"`),
|
||||
`filterSpeckle`, `colorPrecision`, `layerDifference`, `cornerThreshold`,
|
||||
`lengthThreshold`, `maxIterations`, `spliceThreshold`, `simplify` (curve
|
||||
simplification tolerance in px, try 1–2.5), `pathPrecision`, `palette` (list of
|
||||
`#rrggbb`), `maxColors`, `optimize` (`0 | 1 | 2`), `binaryThreshold` /
|
||||
`adaptive` / `adaptiveWindow` / `adaptiveT` (binary mode), `watershedDetail`
|
||||
(0..=255).
|
||||
|
||||
## Build from source
|
||||
|
||||
|
||||
Vendored
+2
@@ -13,6 +13,8 @@ export interface Options {
|
||||
lengthThreshold?: number;
|
||||
maxIterations?: number;
|
||||
spliceThreshold?: number;
|
||||
/** Curve simplification tolerance in px (omit = off; try 1-2.5). */
|
||||
simplify?: number;
|
||||
pathPrecision?: number;
|
||||
/** Fixed palette: `#rrggbb` strings. */
|
||||
palette?: string[];
|
||||
|
||||
@@ -26,6 +26,8 @@ struct Options {
|
||||
length_threshold: Option<f64>,
|
||||
max_iterations: Option<usize>,
|
||||
splice_threshold: Option<i32>,
|
||||
/// Curve simplification tolerance in px (omit = off).
|
||||
simplify: Option<f64>,
|
||||
path_precision: Option<u32>,
|
||||
palette: Option<Vec<String>>,
|
||||
max_colors: Option<usize>,
|
||||
@@ -104,6 +106,9 @@ fn config_from(options: JsValue) -> Result<Config, JsValue> {
|
||||
if let Some(v) = opts.splice_threshold {
|
||||
config.splice_threshold = v;
|
||||
}
|
||||
if let Some(v) = opts.simplify {
|
||||
config.simplify = Some(v);
|
||||
}
|
||||
if let Some(v) = opts.path_precision {
|
||||
config.path_precision = Some(v);
|
||||
}
|
||||
|
||||
+10
-2
@@ -12,11 +12,19 @@ let svg = vtracer.convertBuffer(data);
|
||||
assert(svg.includes('<svg') && svg.includes('<path'), 'default convertBuffer');
|
||||
console.log('convertBuffer default:', (svg.match(/<path/g) || []).length, 'paths');
|
||||
|
||||
// options: bw preset -> all black
|
||||
svg = vtracer.convertBuffer(data, { colorMode: 'bw' });
|
||||
// options: bw clustering -> all black
|
||||
svg = vtracer.convertBuffer(data, { clustering: 'bw' });
|
||||
assert(svg.includes('fill="#000000"'), 'bw produces black');
|
||||
console.log('convertBuffer bw:', (svg.match(/<path/g) || []).length, 'paths');
|
||||
|
||||
// curve simplification shrinks the output
|
||||
{
|
||||
const plain = vtracer.convertBuffer(data);
|
||||
const simplified = vtracer.convertBuffer(data, { simplify: 2 });
|
||||
assert(simplified.length < plain.length, 'simplify shrinks output');
|
||||
console.log('convertBuffer simplify:', plain.length, '->', simplified.length, 'bytes');
|
||||
}
|
||||
|
||||
// options: mosaic + polygon + palette
|
||||
svg = vtracer.convertBuffer(data, { hierarchical: 'cutout', mode: 'polygon', palette: ['#000000', '#ffffff'], optimize: 2 });
|
||||
assert(svg.includes('<svg'), 'mosaic+palette');
|
||||
|
||||
Reference in New Issue
Block a user