Skip to content

VectorCraft: An open-source, vector art tool written by scratch in pure Rust

Blob Brush: the tip preview draws 0% Roundness as thin as the brush

dotCooCoo2a5e2e8588e3
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<Value, String> {
let values: Map<String, Value> = 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()))