mirror of
https://github.com/storytold/texturecraft.git
synced 2026-12-01 10:34:00 +01:00
test(path-cache): a snapshot is charged only for tiles no kept snapshot shares
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ec4775ef6
commit
14f02e5fe7
1 file changed
+27
@@ -770,6 +770,33 @@ mod tests {
|
||||
assert!(snaps[2].is_none(), "snapshot 2 keeps the first fill alive, over the budget");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_snapshot_is_charged_only_for_what_no_kept_snapshot_shares() {
|
||||
let all: Vec<(u32, u32)> = (0..4).flat_map(|y| (0..4).map(move |x| (x, y))).collect();
|
||||
let empty: super::Snap = [(Some(texturecraft_core::Channel::BaseColor), texturecraft_texel::TileImage::new(256, 256, 4))].into();
|
||||
let tile_bytes = texturecraft_texel::TILE_AREA * 4 * 2;
|
||||
// Two full fills then a one-tile stroke (the live pixels). Snapshot 2 shares 15 tiles with
|
||||
// the live pixels and owns one; snapshot 1 owns the whole first fill: 16 tiles.
|
||||
let s1 = painted(&empty, &all);
|
||||
let s2 = painted(&s1, &all);
|
||||
let s3 = painted(&s2, &[(0, 0)]);
|
||||
let fresh = || vec![Some(empty.clone()), Some(s1.clone()), Some(s2.clone()), Some(s3.clone())];
|
||||
let kept = |snaps: &[Option<super::Snap>]| snaps.iter().map(Option::is_some).collect::<Vec<_>>();
|
||||
let mut snaps = fresh();
|
||||
super::evict(&mut snaps, usize::MAX, 0);
|
||||
assert_eq!(kept(&snaps), [true; 4]);
|
||||
let mut snaps = fresh();
|
||||
super::evict(&mut snaps, tile_bytes, 0);
|
||||
assert_eq!(kept(&snaps), [true, false, true, true], "snapshot 2 costs one tile, snapshot 1 sixteen");
|
||||
let mut snaps = fresh();
|
||||
super::evict(&mut snaps, 0, 0);
|
||||
assert_eq!(kept(&snaps), [true, false, false, true], "snapshot 2 owns one tile, over a zero budget");
|
||||
// Keeping snapshot 1 (edited) makes snapshot 2 free of the tiles they share, not of its own.
|
||||
let mut snaps = fresh();
|
||||
super::evict(&mut snaps, 0, 1);
|
||||
assert_eq!(kept(&snaps), [true, true, false, true]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_quick_mask_does_not_clip_paths() {
|
||||
let (mut s, eid) = with_paths(&[0.2, 0.8]);
|
||||
|
||||
Reference in new issue
Block a user