mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-14 19:26:56 -04:00
clippy: as_chunks for fixed-size pixel and pair chunks (Rust 1.99 lint was red on main)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c4236e1bb2
commit
0f241aac9f
7 files changed
+9
-9
No files matched your search
@@ -131,7 +131,7 @@ pub fn scribble(path: &PathData, b: Rect, p: &Value) -> PathData {
|
||||
}
|
||||
}
|
||||
xs.sort_by(f64::total_cmp);
|
||||
let mut spans: Vec<(f64, f64)> = xs.chunks_exact(2).map(|s| (s[0] - overlap, s[1] + overlap)).collect();
|
||||
let mut spans: Vec<(f64, f64)> = xs.as_chunks::<2>().0.iter().map(|s| (s[0] - overlap, s[1] + overlap)).collect();
|
||||
if row % 2 == 1 {
|
||||
spans.reverse();
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ fn deep_point(bp: &BezPath) -> Option<kurbo::Point> {
|
||||
_ => {}
|
||||
});
|
||||
xs.sort_by(f64::total_cmp);
|
||||
for w in xs.chunks_exact(2) {
|
||||
for w in xs.as_chunks::<2>().0 {
|
||||
let span = w[1] - w[0];
|
||||
if best.is_none_or(|(b, _)| span > b) {
|
||||
best = Some((span, kurbo::Point::new((w[0] + w[1]) / 2.0, y)));
|
||||
|
||||
@@ -247,7 +247,7 @@ pub(crate) fn post(pixels: &mut [u8], opts: &RenderOptions) {
|
||||
let lut = cms::active().proof_lut(proof);
|
||||
let mut last_in = [0u8; 4];
|
||||
let mut last_out = [0u8; 4];
|
||||
for px in pixels.chunks_exact_mut(4) {
|
||||
for px in pixels.as_chunks_mut::<4>().0 {
|
||||
let a = px[3];
|
||||
if a == 0 {
|
||||
continue;
|
||||
|
||||
@@ -33,7 +33,7 @@ impl Image {
|
||||
}
|
||||
/// Number of pixels for which `pred(rgba)` holds.
|
||||
pub fn count(&self, pred: impl Fn([u8; 4]) -> bool) -> usize {
|
||||
self.rgba.chunks_exact(4).filter(|p| pred([p[0], p[1], p[2], p[3]])).count()
|
||||
self.rgba.as_chunks::<4>().0.iter().filter(|p| pred([p[0], p[1], p[2], p[3]])).count()
|
||||
}
|
||||
/// Pixels that differ from opaque white and are not fully transparent.
|
||||
pub fn ink(&self) -> usize {
|
||||
|
||||
@@ -158,7 +158,7 @@ fn poly_intervals(polys: &[Vec<Point>], y: f64) -> Vec<(f64, f64)> {
|
||||
}
|
||||
}
|
||||
xs.sort_by(f64::total_cmp);
|
||||
xs.chunks_exact(2).map(|c| (c[0], c[1])).collect()
|
||||
xs.as_chunks::<2>().0.iter().map(|c| (c[0], c[1])).collect()
|
||||
}
|
||||
|
||||
/// Union of sorted-or-not intervals.
|
||||
|
||||
@@ -229,7 +229,7 @@ pub fn hatch(path: &BezPath, gap: f64) -> BezPath {
|
||||
}
|
||||
}
|
||||
xs.sort_by(f64::total_cmp);
|
||||
for pair in xs.chunks_exact(2) {
|
||||
for pair in xs.as_chunks::<2>().0 {
|
||||
out.move_to(unrot(Point::new(pair[0], y)));
|
||||
out.line_to(unrot(Point::new(pair[1], y)));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ fn luma(p: [u8; 4]) -> u8 {
|
||||
|
||||
/// Reduce `img` to a palette according to `params.mode`.
|
||||
pub fn quantize(img: &Raster, params: &TraceParams) -> Quantized {
|
||||
let px = img.rgba.chunks_exact(4).map(|c| [c[0], c[1], c[2], c[3]]);
|
||||
let px = img.rgba.as_chunks::<4>().0.iter().map(|c| [c[0], c[1], c[2], c[3]]);
|
||||
match params.mode {
|
||||
Mode::BlackAndWhite => {
|
||||
let t = params.threshold;
|
||||
@@ -38,7 +38,7 @@ pub fn quantize(img: &Raster, params: &TraceParams) -> Quantized {
|
||||
}
|
||||
Mode::Grayscale => {
|
||||
let mut hist = [0u64; 256];
|
||||
for p in img.rgba.chunks_exact(4) {
|
||||
for p in img.rgba.as_chunks::<4>().0 {
|
||||
if p[3] >= 128 {
|
||||
hist[luma([p[0], p[1], p[2], p[3]]) as usize] += 1;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ pub fn quantize(img: &Raster, params: &TraceParams) -> Quantized {
|
||||
Mode::Color => {
|
||||
// 15-bit colour histogram with per-bin sums (exact bin means).
|
||||
let mut bins: Vec<Bin> = vec![Bin::default(); 1 << 15];
|
||||
for p in img.rgba.chunks_exact(4) {
|
||||
for p in img.rgba.as_chunks::<4>().0 {
|
||||
if p[3] >= 128 {
|
||||
let b = &mut bins[key(p[0], p[1], p[2])];
|
||||
b.n += 1;
|
||||
|
||||
Reference in new issue
Block a user