@@ -30,6 +30,10 @@ use rayon::iter::ParallelIterator;
3030use rupl:: types:: { Bound , Complex , Graph , GraphData , Prec } ;
3131#[ cfg( feature = "bincode" ) ]
3232use 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}
163173impl 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