mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
develop crystal tests: smaller grids, one extra tile for the eviction fill, two seeds for the held draw, margins printed
This commit is contained in:
@@ -103,8 +103,8 @@ fn reference_render_has_unit_variance_and_no_mean() {
|
||||
fn small_render_is_the_downscaled_reference() {
|
||||
for (size, rough) in [(0.0, 50.0), (25.0, 50.0), (100.0, 50.0), (25.0, 0.0), (25.0, 100.0)] {
|
||||
let t = tile_of(size, rough);
|
||||
for k in [2usize, 4, 8] {
|
||||
let n = 48;
|
||||
for k in [2usize, 8] {
|
||||
let n = 32;
|
||||
let full = patch(&t, REF_LONG, n * k, 0);
|
||||
let down: Vec<f32> = (0..n * n)
|
||||
.map(|q| {
|
||||
@@ -120,6 +120,7 @@ fn small_render_is_the_downscaled_reference() {
|
||||
.collect();
|
||||
let small = patch(&t, REF_LONG / k as f64, n, 0);
|
||||
let worst = down.iter().zip(&small).map(|(a, b)| (a - b).abs()).fold(0.0, f32::max);
|
||||
eprintln!("DIAG downscale size {size} roughness {rough} 1/{k}: worst {worst} (limit 2e-3)");
|
||||
assert!(worst < 2e-3, "size {size} roughness {rough} 1/{k}: differs by {worst}");
|
||||
}
|
||||
}
|
||||
@@ -129,7 +130,7 @@ fn small_render_is_the_downscaled_reference() {
|
||||
fn strength_matches_the_target_at_mid_grey() {
|
||||
for (a, s, r) in [(50.0, 25.0, 50.0), (25.0, 25.0, 50.0), (50.0, 0.0, 50.0), (50.0, 100.0, 50.0), (50.0, 25.0, 0.0)] {
|
||||
let g = CrystalGrain::new(&Grain { amount: a, size: s, roughness: r, seed: 3 }, REF_LONG).expect("grain");
|
||||
let n = 320;
|
||||
let n = 200;
|
||||
let lum: Vec<f32> = (0..n * n)
|
||||
.map(|k| {
|
||||
let (x, y) = ((k % n) as f32 + 0.5, (k / n) as f32 + 0.5);
|
||||
@@ -138,6 +139,7 @@ fn strength_matches_the_target_at_mid_grey() {
|
||||
})
|
||||
.collect();
|
||||
let want = strength_levels(a, s, r);
|
||||
eprintln!("DIAG strength {a}/{s}/{r}: deviation {:.4} (limit 0.06)", std(&lum) / want - 1.0);
|
||||
assert!((std(&lum) / want - 1.0).abs() < 0.06, "{a}/{s}/{r}: {} levels, want {want}", std(&lum));
|
||||
}
|
||||
}
|
||||
@@ -153,7 +155,7 @@ fn tones_keep_their_mean() {
|
||||
for (amount, size, levels) in cases {
|
||||
let g = CrystalGrain::new(&Grain { amount, size, roughness: 50.0, seed: 3 }, REF_LONG).expect("grain");
|
||||
for &level in levels {
|
||||
let n = 256;
|
||||
let n = 160;
|
||||
let mut sum = 0.0f64;
|
||||
for k in 0..n * n {
|
||||
let (x, y) = ((k % n) as f32 + 0.5, (k / n) as f32 + 0.5);
|
||||
@@ -161,6 +163,7 @@ fn tones_keep_their_mean() {
|
||||
sum += (e[1].clamp(0.0, 1.0) * 255.0) as f64;
|
||||
}
|
||||
let shift = sum / (n * n) as f64 - level as f64;
|
||||
eprintln!("DIAG tones {amount}/{size} level {level}: shift {shift:+.3} (limit 0.5)");
|
||||
assert!(shift.abs() < 0.5, "{amount}/{size}: level {level} moved {shift:+.2}");
|
||||
}
|
||||
}
|
||||
@@ -443,8 +446,10 @@ fn a_waiting_render_gets_the_tile_the_cache_evicted() {
|
||||
keep(&OWN, key, drawn.clone());
|
||||
// other renders' tiles push it out of the cache before the waiter wakes
|
||||
// (each its own tile: a waiter that took another key's would fail the check below)
|
||||
// (one tile of another seed under every key: a different `Arc` from the drawn one, drawn once)
|
||||
let other_tile = Arc::new(CrystalTile::new(look, seed + 1).expect("tile"));
|
||||
for other in 1..=CACHE as u32 {
|
||||
keep(&OWN, key_of(look, seed + other), Arc::new(CrystalTile::new(look, seed + other).expect("tile")));
|
||||
keep(&OWN, key_of(look, seed + other), other_tile.clone());
|
||||
}
|
||||
assert!(cached(&OWN, key).is_none(), "the tile is still cached");
|
||||
drop(marker);
|
||||
@@ -477,7 +482,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() {
|
||||
static OWN: Cache = Mutex::new(Vec::new());
|
||||
const N: usize = 8;
|
||||
// the first render's draw waits for the other seven to miss the tile too
|
||||
const SEEDS: u32 = 5;
|
||||
// (each seed is a full trial, as the draw is held until the others wait, so a few are enough)
|
||||
const SEEDS: u32 = 2;
|
||||
HOLDS.lock().unwrap_or_else(PoisonError::into_inner).push((std::ptr::from_ref(&OWN) as usize, N - 1, SEEDS as usize));
|
||||
let look = CrystalLook::new(0.0, 50.0);
|
||||
for seed in 0x0d4a_1000..0x0d4a_1000 + SEEDS {
|
||||
@@ -502,7 +508,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() {
|
||||
fn width_matches_lightroom_classic() {
|
||||
let lrc = [(0.0, 50.0, 0.5), (25.0, 50.0, 1.13), (100.0, 50.0, 3.38), (25.0, 0.0, 0.86), (25.0, 100.0, 1.54)];
|
||||
for (s, r, want) in lrc {
|
||||
let got = half_width(&patch(&tile_of(s, r), REF_LONG, 360, 0), 360);
|
||||
let got = half_width(&patch(&tile_of(s, r), REF_LONG, 256, 0), 256);
|
||||
eprintln!("DIAG width size {s} roughness {r}: {got:.3} want {want} (limit 10 percent)");
|
||||
assert!((got / want - 1.0).abs() < 0.1, "size {s} roughness {r}: width {got:.3}, want {want}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user