mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Brush: taper supersampled coverage at the cursor edge (#17161)
This commit is contained in:
1 parent
ef4cbb4ae4
commit
101ece647d
3 files changed
+25
-1
No files matched your search
@@ -134,6 +134,21 @@ fn bounded_soft_tip_leaves_pixel_centres_outside_its_edge_untouched() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounded_one_pixel_soft_tip_tapers_as_the_pixel_centre_reaches_the_edge() {
|
||||
let brush = BrushSettings { hardness: 0.0, tip_boundary: Some(2.0), ..brush() };
|
||||
let coverage_at = |distance: f64| {
|
||||
let dab = Dab::round(Point::new(50.5 - distance, 50.5), 0.5, 1.0);
|
||||
at(&raster(&brush, &dab), 50, 50)
|
||||
};
|
||||
|
||||
let [inside, near, edge, outside] = [0.75, 0.99, 1.0, 1.01].map(coverage_at);
|
||||
assert!(inside > 0.05);
|
||||
assert!(near > 0.0 && near < inside / 20.0, "coverage {near} close to the edge, {inside} further inside");
|
||||
assert_eq!(edge, 0.0);
|
||||
assert_eq!(outside, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sampled_tip_is_scaled_and_oriented() {
|
||||
// Tip: left half painted.
|
||||
|
||||
@@ -234,6 +234,13 @@ impl TipProfile {
|
||||
pub(crate) fn contains_pixel(self, distance_squared: f32) -> bool {
|
||||
!self.bounded || distance_squared < self.reach * self.reach
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn cap_supersampled_coverage(self, distance: f32, average: f32) -> f32 {
|
||||
// Inward samples can still be inside the tip as the pixel centre reaches the boundary.
|
||||
// The centre's falloff keeps their average from leaving a visible jump at the cutoff.
|
||||
if self.bounded { average.min(self.falloff(distance)) } else { average }
|
||||
}
|
||||
}
|
||||
|
||||
/// `exp(-u)` as `(1 − u/64)⁶⁴` by six squarings: within 1/255 of `exp` where it matters, exact
|
||||
|
||||
@@ -1650,7 +1650,9 @@ impl GeneralTip<'_> {
|
||||
sum += profile.falloff(sd);
|
||||
}
|
||||
}
|
||||
(sum / (SUBPIXEL.len() * SUBPIXEL.len()) as f32, d2.sqrt() / rm)
|
||||
let distance = d2.sqrt();
|
||||
let average = sum / (SUBPIXEL.len() * SUBPIXEL.len()) as f32;
|
||||
(profile.cap_supersampled_coverage(distance, average), distance / rm)
|
||||
}
|
||||
None => {
|
||||
let d2 = (u * ro).powi(2) + v * v;
|
||||
|
||||
Reference in new issue
Block a user