Skip to content

Commit 2a8dae4

Browse files
committed
start of ucalc support
1 parent 8de9145 commit 2a8dae4

5 files changed

Lines changed: 197 additions & 42 deletions

File tree

Cargo.lock

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ wasm-opt = false
2929

3030
[features]
3131
default=["skia-vulkan", "rug","fastnum", "vulkano-x11","x11", "wayland", "rayon", "bincode", "arboard"]
32+
#default=["skia-vulkan", "ucalc", "vulkano-x11", "x11", "wayland", "rayon", "arboard"]
3233
#default=["egui","rug","fastnum","rayon", "bincode", "arboard"]
3334
#default=["skia-vulkan","rug","fastnum","wayland", "rayon", "bincode", "arboard"]
3435
#default=["skia","rug","fastnum","wayland","softbuffer","softbuffer-wayland", "rayon", "bincode", "arboard"]
@@ -51,6 +52,7 @@ softbuffer-wayland=["softbuffer/wayland"]
5152
rug=["kalc-lib/rug","kalc-lib"]
5253
fastnum=["kalc-lib/fastnum","kalc-lib"]
5354
kalc-lib=["dep:kalc-lib"]
55+
ucalc=["dep:ucalc_lib"]
5456
wasm=["dep:wasm-bindgen", "rupl/wasm", "dep:lz4_flex", "dep:base64"]
5557
wasm-draw=["rupl/wasm-draw", "wasm", "rupl/winit", "dep:winit"]
5658
wee=["dep:wee_alloc"]
@@ -67,6 +69,7 @@ bitcode = {version="0.6.9",features = ["serde"],optional = true}
6769
serde = {version = "1.0.228", features = ["derive"], optional = true}
6870
rupl={version = "0.1.2",path="../rupl",default-features = false}
6971
kalc-lib={version="1.5.1",default-features=false,path="../kalc-lib",optional = true, features = ["fastrand"]}
72+
ucalc_lib = {version="0.0.2", path = "../ucalc/ucalc_lib", default-features = false, features=["f64", "complex"], optional = true}
7073
wasm-bindgen = {version="0.2.108",optional = true}
7174
console_error_panic_hook = { version = "0.1.7", optional = true }
7275
wee_alloc = {version = "0.4.5", optional = true}

src/app.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,17 @@ impl App {
148148
window: None,
149149
}
150150
}
151-
#[cfg(not(feature = "kalc-lib"))]
152-
pub(crate) fn new(_function: String) -> Self {
151+
#[cfg(feature = "ucalc")]
152+
pub(crate) fn new(function: String) -> Self {
153153
let options = crate::data::Options::default();
154154
let mut data = Data {
155-
data: vec![Some(crate::data::Plot {
156-
graph_type: crate::data::Type {
157-
val: crate::data::Val::Num(None),
158-
how: crate::data::HowGraphing {
159-
graph: true,
160-
x: true,
161-
y: true,
162-
w: false,
163-
},
164-
inv: None,
165-
},
166-
})],
155+
data: Vec::new(),
167156
blacklist: Vec::new(),
168157
options,
158+
vars: Default::default(),
169159
var: rupl::types::Vec2::new(options.xr.0, options.xr.1),
170160
count_changed: false,
161+
funs: Default::default(),
171162
};
172163
let mut graph = Vec::new();
173164
let complex = data.generate_3d(
@@ -180,8 +171,7 @@ impl App {
180171
None,
181172
&mut graph,
182173
);
183-
let names = &[(Vec::new(), "sin(1/z)".to_string())];
184-
let names = get_names(&graph, names);
174+
let names = get_names(&graph, &[(Vec::new(), String::new())]);
185175
let mut plot = Graph::new(graph, names, complex, options.xr.0, options.xr.1);
186176
#[cfg(feature = "bincode")]
187177
{
@@ -200,11 +190,12 @@ impl App {
200190
window: None,
201191
#[cfg(any(feature = "skia", feature = "tiny-skia"))]
202192
#[cfg(not(feature = "wasm"))]
193+
#[cfg(not(feature = "skia-vulkan"))]
203194
surface_state: None,
204195
#[cfg(any(feature = "skia", feature = "tiny-skia", feature = "wasm-draw"))]
205196
input_state: rupl::types::InputState::default(),
206197
#[cfg(any(feature = "skia", feature = "tiny-skia", feature = "wasm-draw"))]
207-
name: _function,
198+
name: function,
208199
#[cfg(any(feature = "skia", feature = "tiny-skia", feature = "wasm-draw"))]
209200
touch_positions: Default::default(),
210201
#[cfg(any(feature = "skia", feature = "tiny-skia", feature = "wasm-draw"))]

src/data.rs

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ use rayon::iter::ParallelIterator;
3030
use rupl::types::{Bound, Complex, Graph, GraphData, Prec};
3131
#[cfg(feature = "bincode")]
3232
use serde::{Deserialize, Serialize};
33+
#[cfg(feature = "ucalc")]
34+
use ucalc_lib::Number;
35+
#[cfg(feature = "ucalc")]
36+
use ucalc_lib::{Functions, Tokens, Variables};
3337
#[cfg(not(feature = "kalc-lib"))]
3438
#[derive(Default, Copy, Clone, Debug, PartialEq)]
3539
#[cfg_attr(feature = "bincode", derive(Serialize, Deserialize))]
@@ -124,6 +128,8 @@ pub(crate) struct Plot {
124128
#[cfg(feature = "kalc-lib")]
125129
#[allow(clippy::type_complexity)]
126130
pub(crate) funcvar: Vec<(String, Vec<NumStr<I, F, C>>)>,
131+
#[cfg(feature = "ucalc")]
132+
pub(crate) tokens: Tokens,
127133
pub(crate) graph_type: Type,
128134
}
129135

@@ -156,21 +162,18 @@ pub(crate) struct Data {
156162
pub(crate) options: Options,
157163
#[cfg(feature = "kalc-lib")]
158164
pub(crate) vars: Vec<Variable<I, F, C>>,
165+
#[cfg(feature = "ucalc")]
166+
pub(crate) vars: Variables,
167+
#[cfg(feature = "ucalc")]
168+
pub(crate) funs: Functions,
159169
pub(crate) blacklist: Vec<usize>,
160170
pub(crate) var: rupl::types::Vec2,
161171
pub(crate) count_changed: bool,
162172
}
163173
impl Data {
164174
pub(crate) fn update(&mut self, plot: &mut Graph) -> Option<String> {
165-
#[cfg(feature = "kalc-lib")]
166175
let mut names = None;
167-
#[cfg(feature = "kalc-lib")]
168176
let mut ret = None;
169-
#[cfg(not(feature = "kalc-lib"))]
170-
let names = None;
171-
#[cfg(not(feature = "kalc-lib"))]
172-
let ret = None;
173-
#[cfg(feature = "kalc-lib")]
174177
if plot.is_name_modified() {
175178
self.update_name(plot, &mut names, &mut ret);
176179
}
@@ -306,6 +309,38 @@ impl Data {
306309
Bound::Width(_, _, _) => unreachable!(),
307310
}
308311
}
312+
#[cfg(feature = "ucalc")]
313+
pub(crate) fn update_name(
314+
&mut self,
315+
plot: &mut Graph,
316+
_names: &mut Option<Vec<(Vec<String>, String)>>,
317+
_ret: &mut Option<String>,
318+
) {
319+
if !self.data.is_empty() {
320+
self.data.pop();
321+
}
322+
if let Some(n) = plot.names.first() {
323+
let item = Tokens::infix(
324+
n.name.as_str(),
325+
&mut self.vars,
326+
&mut self.funs,
327+
&["x"],
328+
false,
329+
10,
330+
)
331+
.ok()
332+
.flatten()
333+
.map(|a| Plot {
334+
tokens: a,
335+
graph_type: Type {
336+
val: Val::Num(None),
337+
how: Default::default(),
338+
inv: None,
339+
},
340+
});
341+
self.data.push(item);
342+
}
343+
}
309344
#[cfg(feature = "kalc-lib")]
310345
pub(crate) fn update_name(
311346
&mut self,
@@ -446,7 +481,7 @@ impl Data {
446481
let mut modifiedvars = place_funcvar(data.funcvar.clone(), "y", y);
447482
#[cfg(feature = "kalc-lib")]
448483
simplify(&mut modified, &mut modifiedvars, self.options);
449-
let mut data = Vec::with_capacity(lenx + 1);
484+
let mut vec = Vec::with_capacity(lenx + 1);
450485
for i in 0..=lenx {
451486
let x = startx + i as f64 * dx;
452487
#[cfg(feature = "kalc-lib")]
@@ -466,9 +501,9 @@ impl Data {
466501
};
467502
#[cfg(not(feature = "kalc-lib"))]
468503
let v = f3(x, y);
469-
data.push(v)
504+
vec.push(v)
470505
}
471-
data
506+
vec
472507
})
473508
.collect::<Vec<Complex>>();
474509
#[cfg(feature = "kalc-lib")]
@@ -924,7 +959,11 @@ impl Data {
924959
Complex::Complex(f64::NAN, f64::NAN)
925960
}
926961
#[cfg(not(feature = "kalc-lib"))]
927-
f(x)
962+
let c = data
963+
.tokens
964+
.compute(&[Number::from(x)], &self.funs, &self.vars);
965+
#[cfg(not(feature = "kalc-lib"))]
966+
Complex::Complex(c.real.0, c.imag.0)
928967
})
929968
.collect::<Vec<Complex>>();
930969
#[cfg(feature = "kalc-lib")]
@@ -1333,7 +1372,7 @@ pub(crate) fn init(
13331372
for _ in split.len()..b.len() {
13341373
split.push(Vec::new());
13351374
}
1336-
for (b, a) in b.iter().zip(split.into_iter()) {
1375+
for (b, a) in b.iter().zip(split) {
13371376
v.push((a, b.to_string()));
13381377
}
13391378
Ok((a, v, how))

0 commit comments

Comments
 (0)