Skip to content

Commit 241e429

Browse files
committed
Merge branch 'development' of https://github.com/jackyarndley/rust-fractal into development
2 parents ace4780 + ee3c0da commit 241e429

File tree

12 files changed

+256
-206
lines changed

12 files changed

+256
-206
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust_fractal"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
authors = ["jackyarndley <34801340+jackyarndley@users.noreply.github.com>"]
55
description = "Fast, efficient mandelbrot set renderer."
66
edition = "2018"

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Investigate why j22522 is not rendering coorrectly

default.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
image_width = 1000
22
image_height = 1000
3-
frames = 50
3+
frames = 99999

j22522.toml

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

src/math/perturbation.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ use crate::math::reference::Reference;
66
pub struct Perturbation {}
77

88
impl Perturbation {
9-
pub fn iterate(pixel_data: &mut Vec<PixelData>, reference: &Reference, reference_current_iteration: usize) {
9+
pub fn iterate(pixel_data: &mut Vec<PixelData>, reference: &Reference) {
1010
pixel_data.par_chunks_mut(8)
1111
.for_each(|pixel_data| {
1212
for pixel in pixel_data {
1313
let mut scaled_iterations = 0;
1414
let mut scaled_scale_factor_1 = 1.0f64.ldexp(pixel.delta_current.exponent);
1515
let mut scaled_delta_reference = 1.0f64.ldexp(pixel.delta_reference.exponent - pixel.delta_current.exponent) * pixel.delta_reference.mantissa;
1616

17-
while pixel.iteration < reference_current_iteration {
17+
while pixel.iteration < reference.current_iteration {
1818
let delta_current_float = scaled_scale_factor_1 * pixel.delta_current.mantissa;
1919

2020
if pixel.delta_current.exponent > -500 {
21-
let z_norm = (reference.data[pixel.iteration - reference.start_iteration].z_fixed + delta_current_float).norm_sqr();
21+
let z_norm = (reference.perturbation_data[pixel.iteration - reference.start_iteration].z_fixed + delta_current_float).norm_sqr();
2222
// let z_norm = (reference.data[pixel.iteration - reference.start_iteration].z_fixed + pixel.delta_current.to_float()).norm_sqr();
2323

24-
if z_norm < reference.data[pixel.iteration - reference.start_iteration].z_tolerance {
24+
if z_norm < reference.perturbation_data[pixel.iteration - reference.start_iteration].z_tolerance {
2525
pixel.glitched = true;
2626
break;
2727
}
@@ -34,7 +34,7 @@ impl Perturbation {
3434
}
3535
}
3636

37-
match reference.data[pixel.iteration - reference.start_iteration].z_extended {
37+
match reference.perturbation_data[pixel.iteration - reference.start_iteration].z_extended {
3838
// If the reference is small, use the slow extended method
3939
Some(z_extended) => {
4040
// do the slow
@@ -53,13 +53,15 @@ impl Perturbation {
5353
None => {
5454
// pixel.delta_current.mantissa = 2.0 * reference.data[pixel.iteration - reference.start_iteration].z_fixed * pixel.delta_current.mantissa + temp * pixel.delta_current.mantissa + scaled_delta_reference;
5555

56-
pixel.delta_current.mantissa *= 2.0 * reference.data[pixel.iteration - reference.start_iteration].z_fixed + delta_current_float;
56+
pixel.delta_current.mantissa *= 2.0 * reference.perturbation_data[pixel.iteration - reference.start_iteration].z_fixed + delta_current_float;
5757
pixel.delta_current.mantissa += scaled_delta_reference;
5858

5959
scaled_iterations += 1;
6060

6161
// check the counter, if it is > 250, do a normalisation
6262
if scaled_iterations > 250 {
63+
pixel.delta_current.reduce();
64+
6365
scaled_scale_factor_1 = 1.0f64.ldexp(pixel.delta_current.exponent);
6466
scaled_delta_reference = 1.0f64.ldexp(pixel.delta_reference.exponent - pixel.delta_current.exponent) * pixel.delta_reference.mantissa;
6567

src/math/reference.rs

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
use crate::util::{ComplexArbitrary, ComplexFixed, ComplexExtended, to_fixed, to_extended};
22

3+
#[derive(Clone)]
34
pub struct Reference {
45
pub start_iteration: usize,
56
pub current_iteration: usize,
67
pub maximum_iteration: usize,
78
pub z: ComplexArbitrary,
89
pub c: ComplexArbitrary,
9-
pub data: Vec<ReferenceIteration>
10+
pub perturbation_data: Vec<ReferenceIteration>,
11+
pub approximation_data: Vec<ComplexExtended>,
12+
// This is for every 100th iteration, when we do glitch correction the new references will be spawed from these values
13+
// Storing every iteration is memory intensive.
14+
pub high_precision_data: Vec<ComplexArbitrary>
1015
}
1116

17+
#[derive(Clone)]
1218
pub struct ReferenceIteration {
1319
pub z_fixed: ComplexFixed<f64>,
1420
pub z_extended: Option<ComplexExtended>,
@@ -23,7 +29,9 @@ impl Reference {
2329
maximum_iteration,
2430
z,
2531
c,
26-
data: Vec::with_capacity(1000)
32+
perturbation_data: Vec::with_capacity(1000),
33+
approximation_data: Vec::with_capacity(1000),
34+
high_precision_data: Vec::with_capacity(1000)
2735
}
2836
}
2937

@@ -35,20 +43,21 @@ impl Reference {
3543
let z_fixed = to_fixed(&self.z);
3644
let z_tolerance = 1e-6 * z_fixed.norm_sqr();
3745

46+
let mut z_extended = to_extended(&self.z);
47+
z_extended.reduce();
48+
3849
// This is if we need to use the extended precision for the reference
3950
if z_fixed.re.abs() < 1e-300 && z_fixed.im.abs() < 1e-300 {
4051
// println!("found slow at: {}", self.current_iteration);
41-
let mut temp = to_extended(&self.z);
42-
temp.reduce();
43-
self.data.push(
52+
self.perturbation_data.push(
4453
ReferenceIteration {
4554
z_fixed,
46-
z_extended: Some(temp),
55+
z_extended: Some(z_extended),
4756
z_tolerance
4857
}
4958
)
5059
} else {
51-
self.data.push(
60+
self.perturbation_data.push(
5261
ReferenceIteration {
5362
z_fixed,
5463
z_extended: None,
@@ -57,27 +66,32 @@ impl Reference {
5766
)
5867
}
5968

69+
self.approximation_data.push(z_extended);
70+
6071
// If the value is not small we do the escape check, otherwise it has not escaped
6172
// as we do the check for 65536 on the perturbation, we need this to be more than that squared
6273
z_fixed.norm_sqr() <= 1e256
6374
}
6475

6576

66-
pub fn run(&mut self) -> bool {
77+
pub fn run(&mut self) {
6778
let z_fixed = to_fixed(&self.z);
6879
let z_tolerance = 1e-6 * z_fixed.norm_sqr();
6980

81+
let mut z_extended = to_extended(&self.z);
82+
z_extended.reduce();
83+
7084
// This is if we need to use the extended precision for the reference
7185
if z_fixed.re.abs() < 1e-300 && z_fixed.im.abs() < 1e-300 {
72-
self.data.push(
86+
self.perturbation_data.push(
7387
ReferenceIteration {
7488
z_fixed,
75-
z_extended: Some(to_extended(&self.z)),
89+
z_extended: Some(z_extended),
7690
z_tolerance
7791
}
7892
)
7993
} else {
80-
self.data.push(
94+
self.perturbation_data.push(
8195
ReferenceIteration {
8296
z_fixed,
8397
z_extended: None,
@@ -86,13 +100,28 @@ impl Reference {
86100
)
87101
}
88102

89-
while self.current_iteration < self.maximum_iteration {
90-
if !self.step() {
91-
break;
92-
}
93-
};
103+
// only needed on central reference
104+
self.approximation_data.push(z_extended);
105+
106+
if self.start_iteration == 1 {
107+
// Add the first value for iterations 0-100
108+
self.high_precision_data.push(self.z.clone());
94109

95-
self.current_iteration == self.maximum_iteration
110+
while self.current_iteration < self.maximum_iteration {
111+
if !self.step() {
112+
break;
113+
};
114+
if self.current_iteration % 100 == 1 {
115+
self.high_precision_data.push(self.z.clone());
116+
}
117+
};
118+
} else {
119+
while self.current_iteration < self.maximum_iteration {
120+
if !self.step() {
121+
break;
122+
};
123+
};
124+
}
96125
}
97126
}
98127

0 commit comments

Comments
 (0)