diff options
author | Gabriel Bjørnager Jensen | 2024-07-29 12:34:36 +0200 |
---|---|---|
committer | Gabriel Bjørnager Jensen | 2024-07-29 12:36:44 +0200 |
commit | 84a362cab7ac936794b0bd3bd0b73f3b8ebdb269 (patch) | |
tree | e9903c425eabae98bfaffb92e75ca10fdca77f97 | |
parent | d269ce57e84bb9270b14feba53a95dc06c6b1c83 (diff) |
-rw-r--r-- | CHANGELOG.md | 6 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | benoit/src/render/render/generate.rs | 30 |
3 files changed, 25 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dd1612..eae682c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 3.0.5 + +## `benoit` + +* Fix non-square renders + # 3.0.4 ## `benoit` @@ -7,7 +7,7 @@ members = [ resolver = "2" [workspace.package] -version = "3.0.4" +version = "3.0.5" authors = ["Gabriel Bjørnager Jensen"] homepage = "https://achernar.dk/html/benoit.html" repository = "https://mandelbrot.dk/benoit" diff --git a/benoit/src/render/render/generate.rs b/benoit/src/render/render/generate.rs index b11ddbd..f323788 100644 --- a/benoit/src/render/render/generate.rs +++ b/benoit/src/render/render/generate.rs @@ -86,10 +86,20 @@ impl Render { // // At default zoom (i.e. a factor of one), the // width of the entire set is (4) in natural units. - // In pixels, this corresponds to render width (e. - // g. 256 pixel). - let x_factor = 4.0 / f64::from(self.size.0) * width_ratio; - let y_factor = 4.0 / f64::from(self.size.1) * height_ratio; + // In pixels, this corresponds to the render width + // (e.g. 256 pixel). + // + // Also Remember that pixel coordinates grow "down- + // wards," whilst euclidian coordinates grop up- + // wards. + let x_factor = 4.0 / f64::from(self.size.0) * width_ratio; + let y_factor = -4.0 / f64::from(self.size.1) * height_ratio; + + // Offset the pixel origin so that it by default + // lies on (-2+2i) instead of the natural origin + // (0). + let x_offset = -2.0 * width_ratio; + let y_offset = 2.0 * height_ratio; data .par_iter_mut() @@ -99,9 +109,9 @@ impl Render { let x = u32::try_from(index % self.size.0 as usize).unwrap(); let y = u32::try_from(index / self.size.0 as usize).unwrap(); - // Convert the pixel coordinates to natural units. - let x = f64::from(x).mul_add(x_factor, -2.0); - let y = f64::from(y).mul_add(y_factor, -2.0); + // Map pixel coordinate to natural units. + let x = f64::from(x).mul_add(x_factor, x_offset); + let y = f64::from(y).mul_add(y_factor, y_offset); *point = generate_at_pixel(x, y, &cache); @@ -120,12 +130,8 @@ fn generate_at_pixel(x: f64, y: f64, cache: &GenerationCache) -> RawElement { let mut c = Complex::with_val(PRECISION, x / cache.zoom, y / cache.zoom); - // Remember that pixel coordinates grow "down- - // wards," whilst euclidian coordinates grop up- - // wards. - c.real += &cache.centre.real; - c.imag -= &cache.centre.imag; + c.imag += &cache.centre.imag; if cache.inverse { let factor = Float::with_val(PRECISION, &c.real * &c.real + &c.imag * &c.imag).recip(); |