mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-01 13:47:21 -06:00
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.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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()))
|
||||
|
||||
Reference in New Issue
Block a user