summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md6
-rw-r--r--Cargo.toml2
-rw-r--r--source/benoit/benoit.rs2
-rw-r--r--source/benoit/benoit/fractal.rs11
-rw-r--r--source/benoit/benoit/render/render.rs21
-rw-r--r--source/benoit/benoit/render_data.rs40
-rw-r--r--source/benoit/benoit/script/dump_frame.rs10
-rw-r--r--source/benoit/benoit/script/set_title.rs8
8 files changed, 39 insertions, 61 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76733f4..cece66f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+# 2.6.2
+
+* Reorder fractal kinds
+* Optimise renderer
+* Refactor code
+
# 2.6.1
* Update readme
diff --git a/Cargo.toml b/Cargo.toml
index 6be71b2..a5b964b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "benoit"
-version = "2.6.1"
+version = "2.6.2"
authors = ["Gabriel Bjørnager Jensen"]
edition = "2021"
description = "Multithreaded Mandelbrot renderer with support for PNG and WebP encoding."
diff --git a/source/benoit/benoit.rs b/source/benoit/benoit.rs
index 3849d4b..8292e0c 100644
--- a/source/benoit/benoit.rs
+++ b/source/benoit/benoit.rs
@@ -36,7 +36,7 @@ pub mod video;
pub const VERSION: (u32, u32, u32) = (
0x2, // Major
0x6, // Minor
- 0x1, // Patch
+ 0x2, // Patch
);
pub const PRECISION: u32 = 0x80;
diff --git a/source/benoit/benoit/fractal.rs b/source/benoit/benoit/fractal.rs
index 74ad168..d47573d 100644
--- a/source/benoit/benoit/fractal.rs
+++ b/source/benoit/benoit/fractal.rs
@@ -34,17 +34,14 @@ pub type IteratorFunction = fn(&mut Complex, &Complex);
#[derive(Clone, Copy)]
#[repr(u8)]
pub enum FractalKind {
- // Sorted according to exponent.
Mandelbrot,
- BurningShip,
- Tricorn,
Multibrot3,
Multibrot4,
+ BurningShip,
+ Tricorn,
}
impl FractalKind {
- const NUM: usize = Self::Multibrot4 as usize + 0x1;
-
pub fn name(self) -> &'static str {
return match self {
FractalKind::BurningShip => "burning ship",
@@ -58,9 +55,9 @@ impl FractalKind {
pub fn cycle(&mut self, direction: i8) {
let raw = *self as i16 + direction as i16;
- const NUM: isize = FractalKind::NUM as isize;
+ const NUM: isize = FractalKind::Tricorn as isize + 0x1;
let new: u8 = match raw as isize {
- -0x1 => (FractalKind::NUM - 0x1) as u8,
+ -0x1 => (NUM - 0x1) as u8,
NUM => 0x0,
_ => raw as u8,
};
diff --git a/source/benoit/benoit/render/render.rs b/source/benoit/benoit/render/render.rs
index 63a0e19..21a86a9 100644
--- a/source/benoit/benoit/render/render.rs
+++ b/source/benoit/benoit/render/render.rs
@@ -69,7 +69,7 @@ impl Render {
}
fn render_point(data: &RenderData, x: u32, y: u32, iterator: IteratorFunction) -> (u32, f32) {
- let (centre, zoom, max_iter_count) = data.input();
+ let (centre, extra, zoom, max_iter_count, inverse, julia) = data.input();
let (x_offset, y_offset, x_factor, y_factor) = data.consts();
@@ -86,8 +86,21 @@ fn render_point(data: &RenderData, x: u32, y: u32, iterator: IteratorFunction) -
Complex {real: a, imag: b}
};
- z = data.factor_inverse(z);
- let (mut z, c) = data.setup_julia(z);
+ if inverse {
+ let mut factor_inverse = Float::with_val(PRECISION, &z.real * &z.real);
+ factor_inverse += &z.imag * &z.imag;
+ factor_inverse.recip_mut();
+
+ z.real *= &factor_inverse;
+ z.imag *= factor_inverse;
+ }
+
+ // We can optimise pertubation by adding w (extra)
+ // to c.
+ let c = match julia {
+ false => Complex { real: Float::with_val(PRECISION, &z.real + &extra.real), imag: Float::with_val(PRECISION, &z.imag + &extra.imag) },
+ true => extra.clone(),
+ };
let mut z_prev = Complex {
real: Float::with_val(PRECISION, Special::Nan),
@@ -112,8 +125,6 @@ fn render_point(data: &RenderData, x: u32, y: u32, iterator: IteratorFunction) -
iterator(&mut z, &c);
- z = data.perturbate(z);
-
iter_count += 0x1;
}
diff --git a/source/benoit/benoit/render_data.rs b/source/benoit/benoit/render_data.rs
index f846c0c..2f13d4b 100644
--- a/source/benoit/benoit/render_data.rs
+++ b/source/benoit/benoit/render_data.rs
@@ -21,7 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
-use crate::benoit::{PRECISION, width_height_ratio};
+use crate::benoit::width_height_ratio;
use crate::benoit::complex::Complex;
extern crate rug;
@@ -90,8 +90,8 @@ impl RenderData {
}
#[must_use]
- pub fn input(&self) -> (&Complex, &Float, u32) {
- return (&self.centre, &self.zoom, self.max_iter_count);
+ pub fn input(&self) -> (&Complex, &Complex, &Float, u32, bool, bool) {
+ return (&self.centre, &self.extra, &self.zoom, self.max_iter_count, self.inverse, self.julia);
}
#[must_use]
@@ -109,38 +109,4 @@ impl RenderData {
let y = (index / self.canvas_width as usize) as u32;
return (x, y);
}
-
- #[must_use]
- pub fn factor_inverse(&self, mut z: Complex) -> Complex {
- if self.inverse {
- let mut factor_inverse = Float::with_val(PRECISION, &z.real * &z.real);
- factor_inverse += &z.imag * &z.imag;
- factor_inverse.recip_mut();
-
- z.real *= &factor_inverse;
- z.imag *= factor_inverse;
- }
-
- return z;
- }
-
- #[must_use]
- pub fn setup_julia(&self, z: Complex) -> (Complex, Complex) {
- let c = match self.julia {
- false => z.clone(),
- true => self.extra.clone(),
- };
-
- return (z, c);
- }
-
- #[must_use]
- pub fn perturbate(&self, mut z: Complex) -> Complex {
- if !self.julia {
- z.real += &self.extra.real;
- z.imag += &self.extra.imag;
- }
-
- return z;
- }
}
diff --git a/source/benoit/benoit/script/dump_frame.rs b/source/benoit/benoit/script/dump_frame.rs
index 29dd718..84125e1 100644
--- a/source/benoit/benoit/script/dump_frame.rs
+++ b/source/benoit/benoit/script/dump_frame.rs
@@ -49,7 +49,7 @@ impl Script {
image_format: ImageFormat,
) {
eprint!("\"{name}\" (2^{:.9}x): rendering...", zoom.to_f64().log2());
- Script::set_title("rendering");
+ Script::set_title("Rendering...");
let time_start = Instant::now();
@@ -63,19 +63,19 @@ impl Script {
let render_time = time_start.elapsed();
eprint!(" {:.3}ms, colouring...", render_time.as_micros() as f32 / 1000.0);
- Script::set_title("colouring");
+ Script::set_title("Colouring...");
image.colour(&render, palette, max_iter_count, colour_range);
let colour_time = time_start.elapsed() - render_time;
eprint!(" {:.3}ms, dumping...", colour_time.as_micros() as f32 / 1000.0);
- Script::set_title("dumping");
+ Script::set_title("Dumping...");
let path = format!("{dump_path}/{name}");
image.dump(path.as_str(), image_format);
let dump_time = time_start.elapsed() - colour_time - render_time;
- eprintln!(" {:.3}ms - \u{1B}[1m\u{1B}[92mdone!\u{1B}[0m", dump_time.as_micros() as f32 / 1000.0);
- Script::set_title("done");
+ eprintln!(" {:.3}ms - \u{1B}[1m\u{1B}[92mdone\u{1B}[0m", dump_time.as_micros() as f32 / 1000.0);
+ Script::set_title("Done");
}
}
diff --git a/source/benoit/benoit/script/set_title.rs b/source/benoit/benoit/script/set_title.rs
index d063165..b8bcb56 100644
--- a/source/benoit/benoit/script/set_title.rs
+++ b/source/benoit/benoit/script/set_title.rs
@@ -30,13 +30,11 @@ extern crate windows;
use windows::Win32::System::Console::SetConsoleTitleA;
impl Script {
- #[cfg(unix)]
pub(super) fn set_title(title: &str) {
- eprint!("\u{1B}]0;{title}\u{07}");
- }
+ #[cfg(unix)]
+ { eprint!("\u{1B}]0;{title}\u{07}") };
- #[cfg(windows)]
- pub(super) fn set_title(title: &str) {
+ #[cfg(windows)]
unsafe { SetConsoleTitleA(title) };
}
}