From dc9c37908d2af217d646b1dff460041650b95a31 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Mon, 9 Feb 2026 18:18:14 +0100 Subject: [PATCH] speed test --- src/lib.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 3e7420e..45b5d2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -97,7 +97,7 @@ pub trait ImgSyn: Clone { #[cfg(test)] mod test { - use std::fs; + use std::{fs, hint::black_box}; use crate::{Canvas, ImgSyn, PixFnFloat, Pixel, polar_math::distance_from_circle}; @@ -183,4 +183,47 @@ mod test { ) .unwrap(); } + + #[test] + fn speed() { + let canvas = Canvas::new(10000., 10000., Pixel::new_white()); + black_box( + canvas + .add_image( + 0.07, + 0.03, + 0.9, + 0.9, + Canvas::new(9000., 9000., Pixel::new_black()).map_area( + |x, y, _| distance_from_circle(x, y, 1.0, 0.0, 0.5, 1.0, 1.0) > 0.0, + |x, y, px: Pixel| px.with_r(x).with_g(1. - y), + ), + ) + .map_area( + |x, y, _| { + let xc = 0.07; + let yc = 0.93; + let t = 0.003; + (xc - t..=xc + t).contains(&x) && y >= 0.03 + || (yc - t..=yc + t).contains(&y) && x <= 0.97 + }, + |x, y, px: Pixel| { + if (1. + x - y) % 0.03 <= 0.02 { + px.with_rgb(1.0, 0.0, 0.5) + } else { + px.with_rgb(1.0, 1.0, 0.0) + } + }, + ) + .mapped_rect(0.02, 0.93, 0.05, 0.05, |img| { + img.map_area( + |x: f64, y: f64, _| { + distance_from_circle(x, y, 0.6, 0.5, 0.2, 1.0, 1.4).abs() < 0.03 + }, + |_, _, px: Pixel| px.with_rgb_of(0.0), + ) + }) + .paint(canvas), + ); + } }