fix: remove zoom limits

This commit is contained in:
2026-09-30 10:24:20 +02:00
parent 2d01acf4d2
commit 6cdcd5c6f9
6 changed files with 439 additions and 124 deletions
+18 -7
View File
@@ -380,7 +380,7 @@ fn step(
FractalKind::Perpendicular => {
// (x^2 - y^2) - 2·x·|y| i: abs the imaginary input.
let re = &zr.sqr() - &zi.sqr() + cr;
let im = if zi.to_f64().value() < 0.0 {
let im = if *zi < Big::ZERO {
ci + ((zr * zi) << 1)
} else {
ci - ((zr * zi) << 1)
@@ -422,10 +422,10 @@ fn big_zero(precision: usize) -> Big {
Big::from(0i32).with_precision(precision).value()
}
/// Absolute value of a `Big`. The sign check via f64 is exact except for values
/// so tiny that |x| ≈ x either way — negligible against the f32 orbit storage.
/// Absolute value of a `Big`. The sign comes from the `Big` itself: through
/// f64, anything below ~1e-308 reads as ±0 and would keep its sign.
fn big_abs(x: Big) -> Big {
if x.to_f64().value() < 0.0 { -x } else { x }
if x < Big::ZERO { -x } else { x }
}
/// `(zr + i zi)^power` by repeated complex multiply at `precision` bits.
@@ -442,10 +442,10 @@ fn complex_pow(zr: &Big, zi: &Big, power: u32, precision: usize) -> (Big, Big) {
(rr, ri)
}
/// `true` if `x` is (numerically) zero. The f64 check is exact for a true
/// zero; only matters here to special-case `ln(0)`.
/// `true` if `x` is exactly zero (special-cases `ln(0)`). Not via f64,
/// which flushes values below ~1e-308 to zero.
fn is_big_zero(x: &Big) -> bool {
x.to_f64().value() == 0.0
x.repr().significand().is_zero()
}
/// `(zr + i zi)^(pr + i pi)` for a complex exponent, via the principal branch
@@ -504,6 +504,17 @@ pub fn compute_set_reference(
mod tests {
use super::*;
/// Sign and zero tests must hold far below f64's range, where
/// `to_f64` reads as ±0.
#[test]
fn sign_and_zero_below_f64_range() {
let tiny = Big::try_from(1.0_f64).unwrap().with_precision(64).value() >> 5000;
assert!(!is_big_zero(&tiny));
assert!(is_big_zero(&big_zero(64)));
assert_eq!(big_abs(-tiny.clone()), tiny);
assert_eq!(big_abs(tiny.clone()), tiny);
}
/// The high-precision reference must agree with a plain f64 iteration for a
/// shallow point (where f64 is accurate).
#[test]
+15 -4
View File
@@ -2,13 +2,14 @@
//! iterations, Julia constant, coloring) as a compact URL fragment so deep-zoom
//! locations can be shared or bookmarked.
//!
//! Format: `m=m&f=<str>&re=<dec>&im=<dec>&hh=<f64>&it=<u32>&cs=<f32>&co=<f32>` with
//! Format: `m=m&f=<str>&re=<dec>&im=<dec>&hh=<sci>&it=<u32>&cs=<f32>&co=<f32>` with
//! `m=j&jr=<f64>&ji=<f64>` added for Julia. `re`/`im` are full-precision decimal
//! strings.
//! strings; `hh` is a `Scale` in scientific notation (any exponent).
use std::collections::HashMap;
use crate::fractal::FractalKind;
use crate::view::Scale;
#[derive(Clone, Debug)]
pub struct ShareState {
@@ -18,7 +19,7 @@ pub struct ShareState {
pub power: u32,
pub center_re: String,
pub center_im: String,
pub half_height: f64,
pub half_height: Scale,
pub iterations: u32,
pub julia_c: (f64, f64),
/// Distortion constant for the Phoenix kind (ignored by others).
@@ -115,7 +116,7 @@ mod tests {
power: 5,
center_re: "-0.743643887037158704752191506114774".into(),
center_im: "0.131825904205311970493132056385139".into(),
half_height: 1.5e-20,
half_height: Scale::from_f64(1.5e-20),
iterations: 4000,
julia_c: (-0.123, 0.745),
phoenix_p: (-0.5, 0.1),
@@ -146,5 +147,15 @@ mod tests {
let d = ShareState::decode("#m=m&re=0.0&im=0.0&hh=1.25&it=256").unwrap();
assert!(!d.julia);
assert_eq!(d.iterations, 256);
assert_eq!(d.half_height, Scale::from_f64(1.25));
}
/// Zooms past f64's range survive a round trip.
#[test]
fn round_trip_past_f64_range() {
let d = ShareState::decode("#m=m&re=0.0&im=0.0&hh=1.5e-1234&it=256").unwrap();
assert_eq!(d.half_height, "1.5e-1234".parse().unwrap());
let d2 = ShareState::decode(&d.encode()).unwrap();
assert_eq!(d2.half_height, d.half_height);
}
}