use std::sync::Arc;
use super::resolved::ClipPlan;
pub(crate) struct ClipResolver;
impl ClipResolver {
pub(crate) const fn new() -> Self {
Self
}
pub(crate) fn resolve_with_mask(&self, mask: Option<Arc<tiny_skia::Mask>>) -> ClipPlan {
match mask {
None => ClipPlan::None,
Some(m) => ClipPlan::Mask(m),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn no_mask_yields_none() {
let plan = ClipResolver::new().resolve_with_mask(None);
match plan {
ClipPlan::None => {},
_ => panic!("expected None"),
}
}
#[test]
fn mask_round_trip_preserves_arc_identity() {
let mask = Arc::new(tiny_skia::Mask::new(8, 8).expect("8x8 mask"));
let plan_a = ClipResolver::new().resolve_with_mask(Some(mask.clone()));
let plan_b = ClipResolver::new().resolve_with_mask(Some(mask.clone()));
let (a, b) = match (&plan_a, &plan_b) {
(ClipPlan::Mask(a), ClipPlan::Mask(b)) => (a, b),
_ => panic!("both plans should be Mask"),
};
assert!(Arc::ptr_eq(a, b), "the resolver must wrap, not clone, the underlying Mask");
}
#[test]
fn mask_dimensions_round_trip() {
let mask = Arc::new(tiny_skia::Mask::new(13, 17).expect("13x17 mask"));
let plan = ClipResolver::new().resolve_with_mask(Some(mask));
match plan {
ClipPlan::Mask(m) => {
assert_eq!(m.width(), 13);
assert_eq!(m.height(), 17);
},
_ => panic!("expected Mask"),
}
}
}