diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-18 18:29:10 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2024-01-18 18:29:10 +0100 |
| commit | 1713618d4cc0194674f91fd2d24ef2de88f21784 (patch) | |
| tree | 1cb39a43019c071ca127cb9f609c045327798de3 /src/math/operation.rs | |
| parent | 670c1881af4680ce7c248498528d14b98210af3f (diff) | |
create small iced demo
Diffstat (limited to 'src/math/operation.rs')
| -rw-r--r-- | src/math/operation.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/math/operation.rs b/src/math/operation.rs new file mode 100644 index 0000000..bcf6510 --- /dev/null +++ b/src/math/operation.rs @@ -0,0 +1,32 @@ +use crate::math::complex::Complex; + +pub type Operator = fn(Complex, Complex) -> Complex; + +#[derive(Clone)] +pub struct Operation { + sign: char, + func: Operator +} + +impl Operation { + pub fn new(sign: char, func: Operator) -> Self { + Self { sign, func } + } + + pub fn sign(&self) -> char { + self.sign + } + + pub fn evaluate(&self, a: Complex, b: Complex) -> Complex { + (self.func)(a, b) + } +} + +#[macro_export] +macro_rules! operations { + {$($x:expr => $y:expr), *} => { + vec![$( + Operation::new($x, Box::new($y)), + )*] + }; +} |