summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/benoit/benoit.rs2
-rw-r--r--source/benoit/benoit/application.rs2
-rw-r--r--source/benoit/benoit/application/animate.rs15
-rw-r--r--source/benoit/benoit/application/draw.rs2
-rw-r--r--source/benoit/benoit/application/handle_keys.rs3
-rw-r--r--source/benoit/benoit/application/initialise.rs11
-rw-r--r--source/benoit/benoit/application/render.rs6
-rw-r--r--source/benoit/benoit/application/render_row.rs41
-rw-r--r--source/benoit/benoit/configuration.rs10
-rw-r--r--source/benoit/benoit/configuration/default.rs11
-rw-r--r--source/benoit/benoit/configuration/load.rs22
-rw-r--r--source/benoit/main.rs1
12 files changed, 71 insertions, 55 deletions
diff --git a/source/benoit/benoit.rs b/source/benoit/benoit.rs
index f3d5299..4251fa8 100644
--- a/source/benoit/benoit.rs
+++ b/source/benoit/benoit.rs
@@ -24,3 +24,5 @@
pub mod application;
pub mod configuration;
pub mod video;
+
+pub const PRECISION: u32 = 0x100;
diff --git a/source/benoit/benoit/application.rs b/source/benoit/benoit/application.rs
index ad5964a..3b8571c 100644
--- a/source/benoit/benoit/application.rs
+++ b/source/benoit/benoit/application.rs
@@ -59,6 +59,4 @@ pub struct Application {
interactive: bool,
do_draw: bool,
do_dump: bool,
-
- precision: u32,
}
diff --git a/source/benoit/benoit/application/animate.rs b/source/benoit/benoit/application/animate.rs
index 6ff628e..6fd6fe4 100644
--- a/source/benoit/benoit/application/animate.rs
+++ b/source/benoit/benoit/application/animate.rs
@@ -21,6 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::application::Application;
extern crate rug;
@@ -32,7 +33,7 @@ use std::ops::MulAssign;
impl Application {
pub fn animate(&self) -> i32 {
- let stop_zoom = Float::with_val(self.precision, &self.zoom);
+ let stop_zoom = Float::with_val(PRECISION, &self.zoom);
let zoom_factor = {
// To get the zoom factor, we first want the 'a'
@@ -51,19 +52,19 @@ impl Application {
//
// (x1-x0)^(1/y1*y0) = (zoom)^(1/frame_count)
- let x_difference = Float::with_val(self.precision, self.frame_count);
+ let x_difference = Float::with_val(PRECISION, self.frame_count);
- let exponent = Float::with_val(self.precision, 1.0 / &x_difference);
+ let exponent = Float::with_val(PRECISION, 1.0 / &x_difference);
- let mut factor = Float::with_val(self.precision, &stop_zoom);
+ let mut factor = Float::with_val(PRECISION, &stop_zoom);
factor.pow_assign(exponent);
factor
};
- let mut zoom = Float::with_val(self.precision, 1.0);
+ let mut zoom = Float::with_val(PRECISION, 1.0);
- eprintln!("animating {} frames at {}{:+} to {:.3} (fac.: {:.3})", self.frame_count, self.center_real.to_f64(), self.center_imaginary.to_f64(), stop_zoom.to_f64(), zoom_factor.to_f64());
+ eprintln!("animating {} frames at {}{:+}i to {:.3} (fac.: {:.3})", self.frame_count, self.center_real.to_f64(), self.center_imaginary.to_f64(), stop_zoom.to_f64(), zoom_factor.to_f64());
let canvas_size = self.canvas_height as usize * self.canvas_width as usize;
@@ -72,7 +73,7 @@ impl Application {
for frame in 0x0..self.frame_count {
eprint!("{frame:010}: ");
- self.render(&mut data[..], self.precision, &self.center_real, &self.center_imaginary, &zoom, self.maximum_iteration_count);
+ self.render(&mut data[..], &self.center_real, &self.center_imaginary, &zoom, self.maximum_iteration_count);
self.colour(&mut image[..], &data[..]);
self.dump(format!("{}/frame{frame:010}.webp", self.dump_path), &image, self.canvas_width, self.canvas_height);
diff --git a/source/benoit/benoit/application/draw.rs b/source/benoit/benoit/application/draw.rs
index c41d9c9..1bc22c3 100644
--- a/source/benoit/benoit/application/draw.rs
+++ b/source/benoit/benoit/application/draw.rs
@@ -32,7 +32,7 @@ impl Application {
pub fn draw(&mut self, data: &mut [u32], image: &mut [u8]) {
let canvas_size = self.canvas_height * self.canvas_width;
- self.render(&mut data[..], self.precision, &self.center_real, &self.center_imaginary, &self.zoom, self.maximum_iteration_count);
+ self.render(&mut data[..], &self.center_real, &self.center_imaginary, &self.zoom, self.maximum_iteration_count);
self.colour(&mut image[..], &data[..]);
for pixel in 0x0..canvas_size {
diff --git a/source/benoit/benoit/application/handle_keys.rs b/source/benoit/benoit/application/handle_keys.rs
index 265bc18..5d52024 100644
--- a/source/benoit/benoit/application/handle_keys.rs
+++ b/source/benoit/benoit/application/handle_keys.rs
@@ -21,6 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::application::Application;
extern crate rug;
@@ -47,7 +48,7 @@ impl Application {
};
let translate_ammount = {
- let mut ammount = Float::with_val(self.precision, 1.0);
+ let mut ammount = Float::with_val(PRECISION, 1.0);
ammount.div_assign(4.0);
ammount.div_assign(&self.zoom);
diff --git a/source/benoit/benoit/application/initialise.rs b/source/benoit/benoit/application/initialise.rs
index 6091da2..7891810 100644
--- a/source/benoit/benoit/application/initialise.rs
+++ b/source/benoit/benoit/application/initialise.rs
@@ -21,6 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::application::Application;
use crate::benoit::configuration::Configuration;
use crate::benoit::video::Video;
@@ -40,8 +41,6 @@ impl Application {
None => Configuration::default(),
};
- let precision: u32 = 0x100;
-
let thread_count: u32 = if configuration.thread_count == 0x0 {
match available_parallelism() {
Ok(ammount) => ammount.get() as u32,
@@ -66,9 +65,9 @@ impl Application {
scale: configuration.scale,
frame_count: configuration.frame_count,
- center_real: Float::with_val(precision, configuration.center_real),
- center_imaginary: Float::with_val(precision, configuration.center_imaginary),
- zoom: Float::with_val(precision, configuration.zoom),
+ center_real: Float::with_val(PRECISION, configuration.center_real),
+ center_imaginary: Float::with_val(PRECISION, configuration.center_imaginary),
+ zoom: Float::with_val(PRECISION, configuration.zoom),
maximum_iteration_count: configuration.maximum_iteration_count,
dump_path: configuration.dump_path,
@@ -78,8 +77,6 @@ impl Application {
interactive: configuration.interactive,
do_draw: true,
do_dump: false,
-
- precision: precision,
};
}
}
diff --git a/source/benoit/benoit/application/render.rs b/source/benoit/benoit/application/render.rs
index e353732..726857c 100644
--- a/source/benoit/benoit/application/render.rs
+++ b/source/benoit/benoit/application/render.rs
@@ -32,7 +32,7 @@ use std::time::Instant;
use std::ptr::addr_of_mut;
impl Application {
- pub fn render(&self, buffer: &mut [u32], precision: u32, center_real: &Float, center_imaginary: &Float, zoom: &Float, maximum_iteration_count: u32) {
+ pub fn render(&self, buffer: &mut [u32], center_real: &Float, center_imaginary: &Float, zoom: &Float, maximum_iteration_count: u32) {
eprint!("rendering...");
let mut threads = Vec::<JoinHandle<()>>::with_capacity(self.thread_count as usize);
@@ -66,7 +66,7 @@ impl Application {
let center_imaginary = center_imaginary.clone();
let zoom = zoom.clone();
- threads.push(spawn(move || { Application::render_row(buffer_slice, precision, y, canvas_width, canvas_height, center_real, center_imaginary, zoom, maximum_iteration_count) }));
+ threads.push(spawn(move || { Application::render_row(buffer_slice, y, canvas_width, canvas_height, center_real, center_imaginary, zoom, maximum_iteration_count) }));
y += 0x1;
}
@@ -85,7 +85,7 @@ impl Application {
let center_imaginary = center_imaginary.clone();
let zoom = zoom.clone();
- threads.push(spawn(move || { Application::render_row(buffer_slice, precision, y, canvas_width, canvas_height, center_real, center_imaginary, zoom, maximum_iteration_count) }));
+ threads.push(spawn(move || { Application::render_row(buffer_slice, y, canvas_width, canvas_height, center_real, center_imaginary, zoom, maximum_iteration_count) }));
}
}
diff --git a/source/benoit/benoit/application/render_row.rs b/source/benoit/benoit/application/render_row.rs
index 64f9f4c..f47f166 100644
--- a/source/benoit/benoit/application/render_row.rs
+++ b/source/benoit/benoit/application/render_row.rs
@@ -21,6 +21,7 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::application::Application;
extern crate rug;
@@ -29,25 +30,25 @@ use rug::Float;
use std::ops::{AddAssign, DivAssign, MulAssign};
impl Application {
- pub fn render_row(data: &mut [u32], precision: u32, y: u32, canvas_width: u32, canvas_height: u32, center_real: Float, center_imaginary: Float, zoom: Float, maximum_iteration_count: u32) {
- let two = Float::with_val(precision, 2.0);
+ pub fn render_row(data: &mut [u32], y: u32, canvas_width: u32, canvas_height: u32, center_real: Float, center_imaginary: Float, zoom: Float, maximum_iteration_count: u32) {
+ let two = Float::with_val(PRECISION, 2.0);
for x in 0x0..canvas_width {
- let canvas_width = Float::with_val(precision, canvas_width);
- let canvas_height = Float::with_val(precision, canvas_height);
+ let canvas_width = Float::with_val(PRECISION, canvas_width);
+ let canvas_height = Float::with_val(PRECISION, canvas_height);
- //let ca = Float::with_val(precision, (&x - &canvas_width / 2.0) / &canvas_width * 4.0 / &zoom + &center_real);
- //let cb = Float::with_val(precision, (&y - &canvas_height / 2.0) / &canvas_height * 4.0 / &zoom + &center_imaginary);
+ //let ca = Float::with_val(PRECISION, (&x - &canvas_width / 2.0) / &canvas_width * 4.0 / &zoom + &center_real);
+ //let cb = Float::with_val(PRECISION, (&y - &canvas_height / 2.0) / &canvas_height * 4.0 / &zoom + &center_imaginary);
- let x_float = Float::with_val(precision, x);
- let y_float = Float::with_val(precision, y);
+ let x_float = Float::with_val(PRECISION, x);
+ let y_float = Float::with_val(PRECISION, y);
// Re(c) = (x-canvas_width/2)/canvas_width*4/zoom+Re(z)
let ca = {
- let tmp0 = Float::with_val(precision, &canvas_width / 2.0);
+ let tmp0 = Float::with_val(PRECISION, &canvas_width / 2.0);
- let mut ca = Float::with_val(precision, &x_float - &tmp0);
+ let mut ca = Float::with_val(PRECISION, &x_float - &tmp0);
ca.div_assign(&canvas_width);
ca.mul_assign(4.0);
ca.div_assign(&zoom);
@@ -59,9 +60,9 @@ impl Application {
// Im(c) = (x-canvas_height/2)/canvas_height*4/zoom+Im(z)
let cb = {
- let tmp0 = Float::with_val(precision, &canvas_height / 2.0);
+ let tmp0 = Float::with_val(PRECISION, &canvas_height / 2.0);
- let mut cb = Float::with_val(precision, &y_float - &tmp0);
+ let mut cb = Float::with_val(PRECISION, &y_float - &tmp0);
cb.div_assign(&canvas_height);
cb.mul_assign(4.0);
cb.div_assign(&zoom);
@@ -70,12 +71,12 @@ impl Application {
cb
};
- let mut za = Float::with_val(precision, &ca);
- let mut zb = Float::with_val(precision, &cb);
+ let mut za = Float::with_val(PRECISION, &ca);
+ let mut zb = Float::with_val(PRECISION, &cb);
let mut iteration_count: u32 = 0x0;
while iteration_count < maximum_iteration_count {
- let square_distance = Float::with_val(precision, &za * &za + &zb * &zb);
+ let square_distance = Float::with_val(PRECISION, &za * &za + &zb * &zb);
if square_distance > 4.0 { break }
{
@@ -85,13 +86,13 @@ impl Application {
// a = a^2 - b^2
// b = 2abi
- let za_temporary = Float::with_val(precision, &za);
+ let za_temporary = Float::with_val(PRECISION, &za);
- za = Float::with_val(precision, &za * &za - &zb * &zb);
- za = Float::with_val(precision, &za + &ca);
+ za = Float::with_val(PRECISION, &za * &za - &zb * &zb);
+ za = Float::with_val(PRECISION, &za + &ca);
- zb = Float::with_val(precision, &za_temporary * &zb);
- zb = Float::with_val(precision, &zb * &two + &cb);
+ zb = Float::with_val(PRECISION, &za_temporary * &zb);
+ zb = Float::with_val(PRECISION, &zb * &two + &cb);
}
iteration_count += 0x1;
diff --git a/source/benoit/benoit/configuration.rs b/source/benoit/benoit/configuration.rs
index 29a2b67..3b00c0f 100644
--- a/source/benoit/benoit/configuration.rs
+++ b/source/benoit/benoit/configuration.rs
@@ -21,6 +21,10 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+extern crate rug;
+
+use rug::Float;
+
pub mod default;
pub mod load;
@@ -32,9 +36,9 @@ pub struct Configuration {
pub scale: u32,
pub frame_count: u32,
- pub center_real: f64,
- pub center_imaginary: f64,
- pub zoom: f64,
+ pub center_real: Float,
+ pub center_imaginary: Float,
+ pub zoom: Float,
pub maximum_iteration_count: u32,
pub dump_path: String,
diff --git a/source/benoit/benoit/configuration/default.rs b/source/benoit/benoit/configuration/default.rs
index 227e588..a185837 100644
--- a/source/benoit/benoit/configuration/default.rs
+++ b/source/benoit/benoit/configuration/default.rs
@@ -21,8 +21,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::configuration::Configuration;
+extern crate rug;
+
+use rug::Float;
+
impl Configuration {
pub fn default() -> Configuration {
return Configuration {
@@ -33,9 +38,9 @@ impl Configuration {
scale: 0x1,
frame_count: 0x10,
- center_real: 0.0,
- center_imaginary: 0.0,
- zoom: 1.0,
+ center_real: Float::with_val(PRECISION, 0.0),
+ center_imaginary: Float::with_val(PRECISION, 0.0),
+ zoom: Float::with_val(PRECISION, 1.0),
maximum_iteration_count: 0x100,
dump_path: "./render/".to_string(),
diff --git a/source/benoit/benoit/configuration/load.rs b/source/benoit/benoit/configuration/load.rs
index cf74548..c9f39d8 100644
--- a/source/benoit/benoit/configuration/load.rs
+++ b/source/benoit/benoit/configuration/load.rs
@@ -21,10 +21,13 @@
If not, see <https://www.gnu.org/licenses/>.
*/
+use crate::benoit::PRECISION;
use crate::benoit::configuration::Configuration;
+extern crate rug;
extern crate toml;
+use rug::Float;
use std::fs::read;
use std::str::FromStr;
use toml::{Table, Value};
@@ -50,18 +53,23 @@ impl Configuration {
let get_integer = |buffer: &mut u32, table: &Table, name: &str| {
if !table.contains_key(name) { return }
- match configuration_table[name] {
- Value::Integer(value) => *buffer = value as u32,
- _ => panic!("mismatched type for {name}"),
+ match &configuration_table[name] {
+ Value::Integer(value) => *buffer = *value as u32,
+ _ => panic!("mismatched type of {name}"),
};
};
- let get_float = |buffer: &mut f64, table: &Table, name: &str| {
+ let get_float = |buffer: &mut Float, table: &Table, name: &str| {
if !table.contains_key(name) { return }
- match configuration_table[name] {
- Value::Float(value) => *buffer = value,
- _ => panic!("mismatched type for {name}"),
+ match &configuration_table[name] {
+ Value::String(string) => {
+ *buffer = match Float::parse(string) {
+ Ok(value) => Float::with_val(PRECISION, value),
+ _ => panic!("invalid format of {name}"),
+ }
+ },
+ _ => panic!("mismatched type of {name}"),
};
};
diff --git a/source/benoit/main.rs b/source/benoit/main.rs
index a302b9f..ec24cbb 100644
--- a/source/benoit/main.rs
+++ b/source/benoit/main.rs
@@ -33,6 +33,5 @@ fn main() {
let code = application.run();
drop(application);
-
exit(code);
}