Pixel Art Algorithm: Pixel Perfect
Created on 2021-12-09T21:33:50-06:00
Filter out and don't dab a pixel if it would result in creating a degenerate section of pixel art.
pub fn pixel_perfect(path: &[Pixel]) -> Vec{ if path.len() == 1 || path.len() == 0 { return path.iter().cloned().collect(); } let mut ret = Vec::new(); let mut c = 0; while c < path.len() { if c > 0 && c+1 < path.len() && (path[c-1].point.x == path[c].point.x || path[c-1].point.y == path[c].point.y) && (path[c+1].point.x == path[c].point.x || path[c+1].point.y == path[c].point.y) && path[c-1].point.x != path[c+1].point.x && path[c-1].point.y != path[c+1].point.y { c += 1; } ret.push(path[c]); c += 1; } ret }