Non-collecting parallel iterators

This commit is contained in:
Michael Zhang 2023-01-31 17:56:36 -06:00
parent 3b04a7c494
commit 9aa823971e

View file

@ -15,9 +15,7 @@ use anyhow::Result;
use clap::Parser;
use itertools::Itertools;
use ordered_float::NotNan;
use rayon::prelude::{
IndexedParallelIterator, IntoParallelIterator, ParallelIterator,
};
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use crate::image::Image;
use crate::input_file::parse_input_file;
@ -26,6 +24,7 @@ use crate::scene_data::Object;
use crate::vec3::Vec3;
use crate::view::Rect;
/// Viewing distance
const ARBITRARY_D: f64 = 2.0;
/// Simple raycaster.
@ -103,15 +102,13 @@ fn main() -> Result<()> {
}
};
// This is an L because par_bridge is unordered
let pixels = (0..scene.image_height)
.cartesian_product(0..scene.image_width)
.collect_vec();
let pixels_iter = (0..scene.image_height)
.into_par_iter()
.flat_map(|x| (0..scene.image_width).into_par_iter().map(move |y| (y, x)));
// Loop through every single pixel of the output file
let pixels = pixels
.into_par_iter()
.map(|(py, px)| {
let pixels = pixels_iter
.map(|(px, py)| {
let pixel_in_space = translate_pixel(px, py);
let ray = Ray::from_endpoints(scene.eye_pos, pixel_in_space);
@ -140,6 +137,7 @@ fn main() -> Result<()> {
})
.collect::<Vec<_>>();
// Construct and emit image
let image = Image {
width: scene.image_width,
height: scene.image_height,