From 971372cf6350533e36db0404afedb1a36817037c Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Fri, 17 Feb 2023 17:48:41 +0100 Subject: =?UTF-8?q?=F0=9F=A7=B9=20Refactor=20rendering=20&=20Cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored how the threading worked. Before it just keept up splitting the screen recursively for x number of times. Felt like using recursion was unnecessary. It's now just done in a loop instead. The user can control the behaviour by setting `num_threads_width` and `num_threads_height` which will split the image x number of times and run a thread for each. Split up the rendering function for one that does scaling and one that doesn't. I just don't want to deal with any kind of scaling when actually rendering the image. The code shouldn't change much so maintaining is going to be ok. - Fixed scaling issues where black bars would appear if the subimage size wasn't divisible by the scale. - Cleaned up a bunch of arcs and other things that wasn't neccesary any more. --- racer-tracer/src/image.rs | 65 +---------------------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) (limited to 'racer-tracer/src/image.rs') diff --git a/racer-tracer/src/image.rs b/racer-tracer/src/image.rs index 1df4cc5..094b1f8 100644 --- a/racer-tracer/src/image.rs +++ b/racer-tracer/src/image.rs @@ -1,3 +1,4 @@ +#[derive(Clone)] pub struct Image { pub aspect_ratio: f64, pub width: usize, @@ -14,20 +15,6 @@ impl Image { } } -// TODO: SubImage and Image can probably be the same struct -impl From<&Image> for SubImage { - fn from(image: &Image) -> Self { - SubImage { - x: 0, - y: 0, - width: image.width, - height: image.height, - screen_width: image.width, - screen_height: image.height, - } - } -} - pub struct SubImage { pub x: usize, pub y: usize, @@ -36,53 +23,3 @@ pub struct SubImage { pub width: usize, pub height: usize, } - -pub trait QuadSplit { - fn quad_split(&self) -> [SubImage; 4]; -} - -impl QuadSplit for SubImage { - fn quad_split(&self) -> [SubImage; 4] { - let half_w = self.width / 2; - let half_h = self.height / 2; - - [ - // Top Left - SubImage { - x: self.x, - y: self.y, - width: half_w, - height: half_h, - screen_width: self.screen_width, - screen_height: self.screen_height, - }, - // Top Right - SubImage { - x: self.x + half_w, - y: self.y, - width: half_w, - height: half_h, - screen_width: self.screen_width, - screen_height: self.screen_height, - }, - // Bottom Left - SubImage { - x: self.x, - y: self.y + half_h, - width: half_w, - height: half_h, - screen_width: self.screen_width, - screen_height: self.screen_height, - }, - // Bottom Right - SubImage { - x: self.x + half_w, - y: self.y + half_h, - width: half_w, - height: half_h, - screen_width: self.screen_width, - screen_height: self.screen_height, - }, - ] - } -} -- cgit v1.2.3