aboutsummaryrefslogtreecommitdiff
path: root/src/math/operation.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-01-18 18:29:10 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-01-18 18:29:10 +0100
commit1713618d4cc0194674f91fd2d24ef2de88f21784 (patch)
tree1cb39a43019c071ca127cb9f609c045327798de3 /src/math/operation.rs
parent670c1881af4680ce7c248498528d14b98210af3f (diff)
create small iced demo
Diffstat (limited to 'src/math/operation.rs')
-rw-r--r--src/math/operation.rs32
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)),
+ )*]
+ };
+}