Skip to content

Commit

Permalink
Revert "Experiment with idealizing small circles"
Browse files Browse the repository at this point in the history
This reverts commit c3012c6.
  • Loading branch information
tyt2y3 committed Mar 29, 2024
1 parent 1777971 commit ddb47e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
2 changes: 1 addition & 1 deletion cmdapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords = ["svg", "computer-graphics"]
[dependencies]
clap = "2.33.3"
image = "0.23.10"
visioncortex = { version = "0.8.4" }
visioncortex = { version = "0.8.1" }
fastrand = "1.8"
pyo3 = { version = "0.19.0", optional = true }

Expand Down
37 changes: 10 additions & 27 deletions cmdapp/src/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ use super::config::{ColorMode, Config, ConverterConfig, Hierarchical};
use super::svg::SvgFile;
use fastrand::Rng;
use visioncortex::color_clusters::{KeyingAction, Runner, RunnerConfig, HIERARCHICAL_MAX};
use visioncortex::{
approximate_circle_with_spline, Color, ColorImage, ColorName, CompoundPath, PathSimplifyMode,
};
use visioncortex::{Color, ColorImage, ColorName};

const NUM_UNUSED_COLOR_ITERATIONS: usize = 6;
/// The fraction of pixels in the top/bottom rows of the image that need to be transparent before
/// the entire image will be keyed.
const KEYING_THRESHOLD: f32 = 0.2;

const SMALL_CIRCLE: i32 = 12;

/// Convert an in-memory image into an in-memory SVG
pub fn convert(img: ColorImage, config: Config) -> Result<SvgFile, String> {
let config = config.into_converter_config();
Expand Down Expand Up @@ -171,28 +167,15 @@ fn color_image_to_svg(mut img: ColorImage, config: ConverterConfig) -> Result<Sv
let mut svg = SvgFile::new(width, height, config.path_precision);
for &cluster_index in view.clusters_output.iter().rev() {
let cluster = view.get_cluster(cluster_index);
let paths = if matches!(config.mode, PathSimplifyMode::Spline)
&& cluster.rect.width() < SMALL_CIRCLE
&& cluster.rect.height() < SMALL_CIRCLE
&& cluster.to_shape(&view).is_circle()
{
let mut paths = CompoundPath::new();
paths.add_spline(approximate_circle_with_spline(
cluster.rect.left_top(),
cluster.rect.width(),
));
paths
} else {
cluster.to_compound_path(
&view,
false,
config.mode,
config.corner_threshold,
config.length_threshold,
config.max_iterations,
config.splice_threshold,
)
};
let paths = cluster.to_compound_path(
&view,
false,
config.mode,
config.corner_threshold,
config.length_threshold,
config.max_iterations,
config.splice_threshold,
);
svg.add_path(paths, cluster.residue_color());
}

Expand Down

0 comments on commit ddb47e1

Please sign in to comment.