use super::RasterBuffer;
pub fn squircle_mask(size: u32, n: f32) -> RasterBuffer {
let w = size as usize;
let h = size as usize;
let cx = size as f32 * 0.5;
let cy = size as f32 * 0.5;
let r = size as f32 * 0.5;
let mut data = vec![0u8; w * h * 4];
for y in 0..h {
for x in 0..w {
let abs_dx = ((x as f32 - cx) / r).abs();
let abs_dy = ((y as f32 - cy) / r).abs();
let d = abs_dx.powf(n) + abs_dy.powf(n);
let gx = n * abs_dx.powf(n - 1.0) / r;
let gy = n * abs_dy.powf(n - 1.0) / r;
let grd = (gx * gx + gy * gy).sqrt().max(1e-6);
let px_dist = (d - 1.0) / grd;
let alpha = if px_dist < -1.0 {
0u8 } else if px_dist > 1.0 {
255u8 } else {
let t = (px_dist + 1.0) * 0.5; let t = t * t * (3.0 - 2.0 * t); (t * 255.0).round() as u8
};
data[(y * w + x) * 4 + 3] = alpha;
}
}
RasterBuffer { width: size, height: size, data }
}