11use crate :: util:: PixelData ;
22use crate :: math:: Reference ;
33use crate :: util:: FloatExtended ;
4+ use crate :: util:: ComplexFixed ;
45
56use std:: io:: prelude:: * ;
67use std:: fs:: File ;
@@ -120,24 +121,9 @@ impl DataExport {
120121 self . rgb [ k] = out;
121122 self . rgb [ k + 1 ] = out;
122123 self . rgb [ k + 2 ] = out;
123-
124- // if pixel.image_x == 960 && pixel.image_y > 540 && pixel.image_y < 740 {
125- // println!("{:?} {:?} {:?} {:?} {:?} {:?}",
126- // reference.reference_data[pixel.iteration - reference.start_iteration].z_extended,
127- // pixel.delta_current,
128- // pixel.derivative_current,
129- // temp,
130- // de,
131- // out,
132- // );
133- // }
134- }
135-
136-
124+ } ;
137125 } ;
138-
139- // self.iterations[k / 3] = pixel.iteration as u32;
140- }
126+ } ;
141127 } ,
142128 DataType :: RAW => {
143129 for pixel in pixel_data {
@@ -158,42 +144,31 @@ impl DataExport {
158144 let temp1 = reference. reference_data [ pixel. iteration - reference. start_iteration ] . z_extended + pixel. delta_current ;
159145 let temp2 = temp1. norm ( ) ;
160146
161- // let de = 2.0 * temp * (temp.mantissa.ln() + temp.exponent as f64 * 2.0f64.ln()) / pixel.derivative_current.norm();
162-
163- // let temp2 = pixel.derivative_current.mantissa.norm();
164-
165- // let temp_x = pixel.derivative_current.mantissa.re / temp2;
166- // let temp_y = pixel.derivative_current.mantissa.im / temp2;
167-
168- // // println!("{}", f16::from_f64((de / delta_pixel).to_float().tanh()));
169- // let value = (de / delta_pixel).to_float().tanh();
170-
171- // u/v is temp
172- // J is [deri_x, deri_y, -deri_y, deri_x]
173-
174- let mut deri = pixel. derivative_current ;
175- deri. mantissa *= delta_pixel. mantissa ;
176- deri. exponent += delta_pixel. exponent ;
147+ let norm_z_x = FloatExtended :: new (
148+ temp1. mantissa . re / temp2. mantissa ,
149+ temp1. exponent - temp2. exponent
150+ ) . to_float ( ) ;
177151
178- let deri = deri. to_float ( ) ;
152+ let norm_z_y = FloatExtended :: new (
153+ temp1. mantissa . im / temp2. mantissa ,
154+ temp1. exponent - temp2. exponent
155+ ) . to_float ( ) ;
179156
180- let num = 2.0 * temp2 * ( temp2. mantissa . ln ( ) + temp2. exponent as f64 * 2.0f64 . ln ( ) ) ;
157+ let jxa = FloatExtended :: new ( pixel. derivative_current . mantissa . re , pixel. derivative_current . exponent ) ;
158+ let jya = FloatExtended :: new ( pixel. derivative_current . mantissa . im , pixel. derivative_current . exponent ) ;
181159
182- let mut norm_u = temp1;
183- let temp3 = temp1. norm ( ) ;
184- norm_u. mantissa /= temp3. mantissa ;
185- norm_u. exponent -= temp3. exponent ;
160+ let scaled_jxa = ( jxa * delta_pixel) . to_float ( ) ;
161+ let scaled_jya = ( jya * delta_pixel) . to_float ( ) ;
186162
187- let norm_u = norm_u . to_float ( ) ;
163+ let num = ( temp2 * ( temp2 . mantissa . ln ( ) + temp2 . exponent as f64 * 2.0f64 . ln ( ) ) ) . to_float ( ) ;
188164
189- let mut den = deri;
190- den. re = norm_u. re * deri. re + norm_u. im * deri. im ;
191- den. im = -norm_u. re * deri. im + norm_u. im * deri. re ;
165+ let den_1 = norm_z_x * scaled_jxa + norm_z_y * scaled_jya;
166+ let den_2 = norm_z_x * -1.0 * scaled_jya + norm_z_y * scaled_jxa;
192167
193- self . distance_x [ k] = f16:: from_f64 ( num. to_float ( ) / den. re ) ;
194- self . distance_y [ k] = f16:: from_f64 ( num. to_float ( ) / den. im ) ;
168+ let output = num / ComplexFixed :: new ( den_1, den_2) ;
195169
196- // println!("{} {} {} {}", temp_x * value, temp_y * value, value, ((temp_x * value).powi(2) + (temp_y * value).powi(2)).sqrt());
170+ self . distance_x [ k] = f16:: from_f64 ( output. re ) ;
171+ self . distance_y [ k] = f16:: from_f64 ( output. im ) ;
197172 }
198173 }
199174 } ,
0 commit comments