-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use complex_rs::complex::Complex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::fractal::Fractal; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)] | ||
pub struct NovaNewtonRaphsonZ3 {} | ||
|
||
impl NovaNewtonRaphsonZ3 { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
fn fz(&self, z: Complex) -> Complex { | ||
z * z * z - Complex::new(1.0, 0.0) | ||
} | ||
|
||
fn dfz(&self, z: Complex) -> Complex { | ||
Complex::new(3.0, 0.0) * z * z | ||
} | ||
} | ||
|
||
impl Fractal for NovaNewtonRaphsonZ3 { | ||
fn generate(&self, max_iterations: u32, x: f64, y: f64) -> (f64, f64) { | ||
let c = Complex::new(x, y); | ||
let mut z = Complex::new(1.0, 0.0); | ||
let mut zn_next; | ||
let epsilon = 1e-6; | ||
let mut i = 0; | ||
|
||
loop { | ||
zn_next = z - (self.fz(z) / self.dfz(z)) + c; | ||
if (zn_next - z).arg_sq() < epsilon || i >= max_iterations { | ||
break; | ||
} | ||
z = zn_next; | ||
i += 1; | ||
} | ||
|
||
return (0.0, i as f64); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use complex_rs::complex::Complex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::fractal::Fractal; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)] | ||
pub struct NovaNewtonRaphsonZ4 {} | ||
|
||
impl NovaNewtonRaphsonZ4 { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
fn fz(&self, z: Complex) -> Complex { | ||
z * z * z * z - Complex::new(1.0, 0.0) | ||
} | ||
|
||
fn dfz(&self, z: Complex) -> Complex { | ||
Complex::new(4.0, 0.0) * z * z * z | ||
} | ||
} | ||
|
||
impl Fractal for NovaNewtonRaphsonZ4 { | ||
fn generate(&self, max_iterations: u32, x: f64, y: f64) -> (f64, f64) { | ||
let c = Complex::new(x, y); | ||
let mut z = Complex::new(1.0, 0.0); | ||
let mut zn_next; | ||
let epsilon = 1e-6; | ||
let mut i = 0; | ||
|
||
loop { | ||
zn_next = z - (self.fz(z) / self.dfz(z)) + c; | ||
if (zn_next - z).arg_sq() < epsilon || i >= max_iterations { | ||
break; | ||
} | ||
z = zn_next; | ||
i += 1; | ||
} | ||
|
||
return (0.0, i as f64); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters