speed test
This commit is contained in:
parent
3f711f0be5
commit
dc9c37908d
1 changed files with 44 additions and 1 deletions
45
src/lib.rs
45
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue