Slightly faster version of value-of-values

This commit is contained in:
heyarne 2022-10-02 18:26:17 +02:00
commit be2204af7e

View file

@ -59,8 +59,8 @@ fn view(app: &App, model: &Model, frame: Frame) {
// extract colors from current rect // extract colors from current rect
let mut cols: Vec<Hsv> = Vec::new(); let mut cols: Vec<Hsv> = Vec::new();
for px_x in img_x1..img_x2 { for px_y in img_y1..img_y2 {
for px_y in img_y1..img_y2 { for px_x in img_x1..img_x2 {
let px = model.image.get_pixel(px_x, px_y); let px = model.image.get_pixel(px_x, px_y);
let col = rgb( let col = rgb(
px[0] as f32 / 255.0, px[0] as f32 / 255.0,
@ -81,12 +81,9 @@ fn view(app: &App, model: &Model, frame: Frame) {
}); });
// draw sorted colors // draw sorted colors
for px_x in img_x1..img_x2 { for y in 0..(img_y2 - img_y1) {
for px_y in img_y1..img_y2 { for x in 0..(img_x2 - img_x1) {
let x = px_x - img_x1;
let y = px_y - img_y1;
let i = (x * (rect_size as u32) + y) as usize; let i = (x * (rect_size as u32) + y) as usize;
let pos_x = pos_x + (rect_size * (x as f32 / rect_size)); let pos_x = pos_x + (rect_size * (x as f32 / rect_size));
let pos_y = pos_y + (rect_size * (y as f32 / rect_size)); let pos_y = pos_y + (rect_size * (y as f32 / rect_size));
draw.rect() draw.rect()