aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-01-19 19:06:09 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-01-19 19:06:09 +0100
commit52e4dfc10616accaa6e4dcdbfc4a706e94dbcdc9 (patch)
tree3f6c7d7886774f1c10b77e7782b071aca7d4d31a /src/main.rs
parent22c656d0be6dd5356f8839fae716174a9fe474c7 (diff)
math: pregenerate eval tree
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 34adc14..534d634 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -47,11 +47,12 @@ impl Application for Graph {
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
+ let ctx = Context::commonsense();
(
Graph {
input_state: "f(x) = x^2".to_string(),
- func: ExpressionFunction::from_string("f(x) = x^2".to_string()),
- ctx: Context::commonsense(),
+ func: ExpressionFunction::from_string("f(x) = x^2".to_string(), ctx.operations()),
+ ctx,
..Default::default()
},
Command::none(),
@@ -68,7 +69,7 @@ impl Application for Graph {
self.input_state = s;
}
Message::UpdateScreen => {
- self.func = ExpressionFunction::from_string(self.input_state.clone());
+ self.func = ExpressionFunction::from_string(self.input_state.clone(), self.ctx.operations());
self.graph.clear();
}
}
@@ -137,26 +138,26 @@ impl canvas::Program<Message, Renderer> for Graph {
let unitline = Stroke {
width: 2.0,
style: stroke::Style::Solid(Color::new(0.0, 0.0, 0.0, 1.0)),
- line_cap: LineCap::Square,
+ line_cap: LineCap::Round,
..Stroke::default()
};
let unitline_whole = Stroke {
width: 1.0,
style: stroke::Style::Solid(Color::new(0.5, 0.5, 0.5, 1.0)),
- line_cap: LineCap::Square,
+ line_cap: LineCap::Round,
..Stroke::default()
};
let zeroline = Stroke {
width: 3.0,
style: stroke::Style::Solid(Color::new(0.0, 0.0, 0.8, 1.0)),
- line_cap: LineCap::Square,
+ line_cap: LineCap::Round,
..Stroke::default()
};
let graphline = Stroke {
width: 3.0,
style: stroke::Style::Solid(Color::new(0.8, 0.0, 0.0, 1.0)),
- line_cap: LineCap::Square,
+ line_cap: LineCap::Round,
..Stroke::default()
};
@@ -230,7 +231,7 @@ impl canvas::Program<Message, Renderer> for Graph {
let mut y1 = self
.func
.eval(
- FunctionArgument::new(vec![Complex::new(start_x as f64, 0.0)]),
+ &FunctionArgument::from_values(vec![Complex::new(start_x as f64, 0.0)]),
&self.ctx,
)
.unwrap()
@@ -243,7 +244,7 @@ impl canvas::Program<Message, Renderer> for Graph {
let y2 = self
.func
.eval(
- FunctionArgument::new(vec![Complex::new(x2 as f64, 0.0)]),
+ &FunctionArgument::from_values(vec![Complex::new(x2 as f64, 0.0)]),
&self.ctx,
)
.unwrap()