From 2a5e2e8588e3f3bc497c621c83b291659a1ba00d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 30 Oct 2026 22:40:49 -0700 Subject: [PATCH] Blob Brush: the tip preview draws 0% Roundness as thin as the brush The Tool Options tip preview floored the short axis at 1% of the long one, while the brush draws 0% Roundness at 0.1%. The preview now uses the same 0.1% minimum, with a test that compares it with the tip the brush draws. --- crates/ui-egui/src/dialogs/freehand.rs | 8 +++++++- crates/ui-egui/src/dialogs/freehand/tests.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/freehand.rs b/crates/ui-egui/src/dialogs/freehand.rs index 85d863056..bd6068638 100644 --- a/crates/ui-egui/src/dialogs/freehand.rs +++ b/crates/ui-egui/src/dialogs/freehand.rs @@ -276,7 +276,7 @@ fn blob_tip_preview(ui: &mut egui::Ui, d: &mut Dialog) { let u = egui::vec2(a.cos() as f32, -a.sin() as f32); let v = egui::vec2(-u.y, u.x); let long = 18.0; - let short = long * (d.f64("roundness", 100.0).clamp(0.0, 100.0) as f32 / 100.0).max(0.01); + let short = long * blob_tip_short_ratio(d.f64("roundness", 100.0)); let dab = |center: egui::Pos2, color: egui::Color32| { let points = (0..32) .map(|i| { @@ -295,6 +295,12 @@ fn blob_tip_preview(ui: &mut egui::Ui, d: &mut Dialog) { } } +/// The preview tip's short axis as a fraction of its long axis: Roundness in percent, with 0 +/// percent drawn as 0.1 percent, the minimum the brush draws with. +fn blob_tip_short_ratio(roundness: f64) -> f32 { + (roundness.clamp(0.0, 100.0) as f32 / 100.0).max(0.001) +} + /// OK: set the tool's options. fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { let values: Map = KEYS.iter().filter_map(|k| Some((k.to_string(), d.fields.get(*k)?.clone()))).collect(); diff --git a/crates/ui-egui/src/dialogs/freehand/tests.rs b/crates/ui-egui/src/dialogs/freehand/tests.rs index 0136d25c5..81aeae9b5 100644 --- a/crates/ui-egui/src/dialogs/freehand/tests.rs +++ b/crates/ui-egui/src/dialogs/freehand/tests.rs @@ -28,6 +28,14 @@ fn blob_tip_fields_confirm_and_cancel() { assert_eq!(app.session.tool_options_of("blobBrush")["roundness"], json!(0.0)); } +#[test] +fn the_tip_preview_is_as_flat_as_the_tip_the_brush_draws() { + for roundness in [-5.0, 0.0, 0.05, 0.1, 1.0, 50.0, 100.0, 120.0] { + let drawn = vectorcraft_tools::draw2::blob_tip(0.0, roundness).as_coeffs()[3] as f32; + assert!((blob_tip_short_ratio(roundness) - drawn).abs() < 1e-6, "roundness {roundness}: drawn {drawn}"); + } +} + /// The labels the open dialog paints. fn painted(app: &mut VectorcraftApp) -> String { crate::tests_labels::painted_text(app, |app, ui| super::super::show(app, ui.ctx()))