11use crate :: util:: { ComplexArbitrary , ComplexFixed , ComplexExtended , to_fixed, to_extended} ;
22
3+ #[ derive( Clone ) ]
34pub 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 ) ]
1218pub 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