mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Pencil 32-bit tip: only the measured sizes get the smaller radius (#17560)
The issue measured the 32-bit aliased round tip at sizes 1, 2, 3, 4, 9, 13, 21 and 50 and says unmeasured cases keep today's behaviour. Any other size now keeps the 8 and 16-bit radius (size 6 paints its 6 px block again instead of nothing). New test: unmeasured_sizes_keep_their_size_in_32_bit.
This commit is contained in:
1 parent
edfca55824
commit
63abb08c0c
2 files changed
+24
-5
No files matched your search
@@ -1,7 +1,8 @@
|
||||
//! #17560: the Pencil's hard round tip in 32-bit RGB and Grayscale documents. The reference paints
|
||||
//! a smaller disc there: its radius is two and a half pixels less than the tip's, so sizes 2 and 4
|
||||
//! paint nothing, 1 and 3 one pixel, and 9, 13, 21 and 50 discs 5, 9, 17 and 44 px across, with a
|
||||
//! one-pixel spike at the top and bottom. 8 and 16 bit are unchanged.
|
||||
//! one-pixel spike at the top and bottom. 8 and 16 bit, and the sizes the reference wasn't
|
||||
//! measured at, are unchanged.
|
||||
//!
|
||||
//! The click lands in pixel (499, 299), left of its centre: where the reference's click at
|
||||
//! (500, 300) puts odd tips (centred on that pixel) and even ones (on its top-left corner).
|
||||
@@ -175,3 +176,16 @@ fn other_tips_keep_their_size_in_32_bit() {
|
||||
// The round pencil tip itself does change.
|
||||
assert_ne!(dab(&pencil(9.0), &at, Some(RGB32)), dab(&pencil(9.0), &at, None));
|
||||
}
|
||||
|
||||
/// Not measured, so unchanged in 32 bit: sizes other than 1, 2, 3, 4, 9, 13, 21 and 50 paint the
|
||||
/// same footprint as in 8 bit (size 6 kept its 6 px block instead of painting nothing).
|
||||
#[test]
|
||||
fn unmeasured_sizes_keep_their_size_in_32_bit() {
|
||||
for size in [5.0, 6.0, 7.0, 8.0, 10.0, 12.0, 20.0, 30.0, 49.0, 51.0, 64.0] {
|
||||
let want = bounds(&click(PixelFormat::RGBA8, size));
|
||||
assert!(want.is_some(), "size {size} paints in 8 bit");
|
||||
for fmt in [RGB32, GRAY32] {
|
||||
assert_eq!(bounds(&click(fmt, size)), want, "{fmt:?} size {size}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,12 +130,17 @@ pub fn grid_square(x: f64, y: f64, diameter: f32) -> [f64; 4] {
|
||||
[f64::from(cx) - h, f64::from(cy) - h, f64::from(cx) + h, f64::from(cy) + h]
|
||||
}
|
||||
|
||||
/// The tip sizes (diameters) the reference's 32-bit aliased round tip was measured at (#17560).
|
||||
const FLOAT_ALIASED_MEASURED: [f32; 8] = [1.0, 2.0, 3.0, 4.0, 9.0, 13.0, 21.0, 50.0];
|
||||
|
||||
/// The radius of the aliased (Pencil) round tip of `radius` in a 32-bit RGB or Grayscale
|
||||
/// document: two and a half pixels less, never below 0. A pixel is painted when its centre lies
|
||||
/// within it of the dab's [`grid_center`], so sizes 2 and 4 paint nothing, 1 and 3 one pixel,
|
||||
/// 9 a 5 px disc and 50 a 44 px one, as the reference measures (#17560).
|
||||
pub fn float_aliased_radius(radius: f32) -> f32 {
|
||||
if radius.is_finite() { (radius - 2.5).max(0.0) } else { 0.0 }
|
||||
/// 9 a 5 px disc and 50 a 44 px one, as the reference measures (#17560). Only the measured sizes
|
||||
/// get it: any other size returns `None` and keeps the 8 and 16-bit radius.
|
||||
pub fn float_aliased_radius(radius: f32) -> Option<f32> {
|
||||
let measured = radius.is_finite() && FLOAT_ALIASED_MEASURED.iter().any(|s| (2.0 * radius - s).abs() < 1e-3);
|
||||
measured.then(|| (radius - 2.5).max(0.0))
|
||||
}
|
||||
|
||||
fn smoothstep(e0: f32, e1: f32, x: f32) -> f32 {
|
||||
@@ -374,7 +379,7 @@ impl BrushContext {
|
||||
let r = d.radius;
|
||||
let ro = d.roundness.max(0.5 / r).min(1.0);
|
||||
let float_round = aliased && self.float_target && mips.is_none() && !b.square && ro >= 1.0 && d.angle == 0.0;
|
||||
let rm = if float_round { float_aliased_radius(r) } else { (r * ro).max(0.5) };
|
||||
let rm = float_round.then(|| float_aliased_radius(r)).flatten().unwrap_or_else(|| (r * ro).max(0.5));
|
||||
let profile = TipProfile::new(rm.max(0.5), hardness);
|
||||
let reach = if aliased || mips.is_some() { rm } else { profile.reach().max(rm) };
|
||||
let reach2 = (reach + 0.5) * (reach + 0.5);
|
||||
|
||||
Reference in new issue
Block a user