random stuff
This commit is contained in:
parent
aef2b9c24c
commit
dea39589ad
@ -1,6 +1,6 @@
|
|||||||
use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTION_ENTRY};
|
use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTION_ENTRY};
|
||||||
use crate::misc::{debug_log, digits_precision, log_helper};
|
use crate::misc::{debug_log, digits_precision, log_helper};
|
||||||
use crate::parsing::{add_asterisks, test_func};
|
use crate::parsing::{process_func_str, test_func};
|
||||||
|
|
||||||
use const_format::formatc;
|
use const_format::formatc;
|
||||||
use eframe::{egui, epi};
|
use eframe::{egui, epi};
|
||||||
@ -404,7 +404,7 @@ impl MathApp {
|
|||||||
ui.text_edit_singleline(&mut self.func_strs[i]);
|
ui.text_edit_singleline(&mut self.func_strs[i]);
|
||||||
});
|
});
|
||||||
|
|
||||||
let proc_func_str = add_asterisks(self.func_strs[i].clone());
|
let proc_func_str = process_func_str(self.func_strs[i].clone());
|
||||||
if integral_toggle
|
if integral_toggle
|
||||||
| derivative_toggle
|
| derivative_toggle
|
||||||
| max_x_changed
|
| max_x_changed
|
||||||
|
|||||||
@ -40,9 +40,9 @@ lazy_static::lazy_static! {
|
|||||||
/*
|
/*
|
||||||
EXTREMELY Janky function that tries to put asterisks in the proper places to be parsed. This is so cursed. But it works, and I hopefully won't ever have to touch it again.
|
EXTREMELY Janky function that tries to put asterisks in the proper places to be parsed. This is so cursed. But it works, and I hopefully won't ever have to touch it again.
|
||||||
One limitation though, variables with multiple characters like `pi` cannot be multiplied (like `pipipipi` won't result in `pi*pi*pi*pi`). But that's such a niche use case (and that same thing could be done by using exponents) that it doesn't really matter.
|
One limitation though, variables with multiple characters like `pi` cannot be multiplied (like `pipipipi` won't result in `pi*pi*pi*pi`). But that's such a niche use case (and that same thing could be done by using exponents) that it doesn't really matter.
|
||||||
In the future I may want to completely rewrite this or implement this natively into mevel-rs (which would probably be good to do)
|
In the future I may want to completely rewrite this or implement this natively in exmex.
|
||||||
*/
|
*/
|
||||||
pub fn add_asterisks(function_in: String) -> String {
|
pub fn process_func_str(function_in: String) -> String {
|
||||||
let function = function_in.replace("log10(", "log(").replace("pi", "π"); // pi -> π and log10 -> log
|
let function = function_in.replace("log10(", "log(").replace("pi", "π"); // pi -> π and log10 -> log
|
||||||
let function_chars: Vec<char> = function.chars().collect();
|
let function_chars: Vec<char> = function.chars().collect();
|
||||||
let mut output_string: String = String::new();
|
let mut output_string: String = String::new();
|
||||||
@ -133,7 +133,7 @@ pub fn test_func(function_string: &str) -> Option<String> {
|
|||||||
// Used for testing: passes function to `add_asterisks` before running `test_func`
|
// Used for testing: passes function to `add_asterisks` before running `test_func`
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn test_func_helper(function_string: &str) -> Option<String> {
|
fn test_func_helper(function_string: &str) -> Option<String> {
|
||||||
test_func(&add_asterisks(function_string.to_string()))
|
test_func(&process_func_str(function_string.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -155,31 +155,34 @@ fn test_func_test() {
|
|||||||
|
|
||||||
// Tests to make sure my cursed function works as intended
|
// Tests to make sure my cursed function works as intended
|
||||||
#[test]
|
#[test]
|
||||||
fn asterisk_test() {
|
fn func_process_test() {
|
||||||
assert_eq!(&add_asterisks("2x".to_string()), "2*x");
|
assert_eq!(&process_func_str("2x".to_string()), "2*x");
|
||||||
assert_eq!(&add_asterisks("x2".to_string()), "x*2");
|
assert_eq!(&process_func_str("x2".to_string()), "x*2");
|
||||||
assert_eq!(&add_asterisks("x(1+3)".to_string()), "x*(1+3)");
|
assert_eq!(&process_func_str("x(1+3)".to_string()), "x*(1+3)");
|
||||||
assert_eq!(&add_asterisks("(1+3)x".to_string()), "(1+3)*x");
|
assert_eq!(&process_func_str("(1+3)x".to_string()), "(1+3)*x");
|
||||||
assert_eq!(&add_asterisks("sin(x)".to_string()), "sin(x)");
|
assert_eq!(&process_func_str("sin(x)".to_string()), "sin(x)");
|
||||||
assert_eq!(&add_asterisks("2sin(x)".to_string()), "2*sin(x)");
|
assert_eq!(&process_func_str("2sin(x)".to_string()), "2*sin(x)");
|
||||||
assert_eq!(&add_asterisks("max(x)".to_string()), "max(x)");
|
assert_eq!(&process_func_str("max(x)".to_string()), "max(x)");
|
||||||
assert_eq!(&add_asterisks("2e^x".to_string()), "2*e^x");
|
assert_eq!(&process_func_str("2e^x".to_string()), "2*e^x");
|
||||||
assert_eq!(&add_asterisks("2max(x)".to_string()), "2*max(x)");
|
assert_eq!(&process_func_str("2max(x)".to_string()), "2*max(x)");
|
||||||
assert_eq!(&add_asterisks("cos(sin(x))".to_string()), "cos(sin(x))");
|
assert_eq!(&process_func_str("cos(sin(x))".to_string()), "cos(sin(x))");
|
||||||
assert_eq!(&add_asterisks("x^(1+2x)".to_string()), "x^(1+2*x)");
|
assert_eq!(&process_func_str("x^(1+2x)".to_string()), "x^(1+2*x)");
|
||||||
assert_eq!(&add_asterisks("(x+2)x(1+3)".to_string()), "(x+2)*x*(1+3)");
|
assert_eq!(
|
||||||
assert_eq!(&add_asterisks("(x+2)(1+3)".to_string()), "(x+2)*(1+3)");
|
&process_func_str("(x+2)x(1+3)".to_string()),
|
||||||
assert_eq!(&add_asterisks("xxx".to_string()), "x*x*x");
|
"(x+2)*x*(1+3)"
|
||||||
assert_eq!(&add_asterisks("eee".to_string()), "e*e*e");
|
);
|
||||||
assert_eq!(&add_asterisks("pi(x+2)".to_string()), "π*(x+2)");
|
assert_eq!(&process_func_str("(x+2)(1+3)".to_string()), "(x+2)*(1+3)");
|
||||||
assert_eq!(&add_asterisks("(x)pi".to_string()), "(x)*π");
|
assert_eq!(&process_func_str("xxx".to_string()), "x*x*x");
|
||||||
assert_eq!(&add_asterisks("2e".to_string()), "2*e");
|
assert_eq!(&process_func_str("eee".to_string()), "e*e*e");
|
||||||
assert_eq!(&add_asterisks("2log10(x)".to_string()), "2*log(x)");
|
assert_eq!(&process_func_str("pi(x+2)".to_string()), "π*(x+2)");
|
||||||
assert_eq!(&add_asterisks("2log(x)".to_string()), "2*log(x)");
|
assert_eq!(&process_func_str("(x)pi".to_string()), "(x)*π");
|
||||||
assert_eq!(&add_asterisks("x!".to_string()), "x!");
|
assert_eq!(&process_func_str("2e".to_string()), "2*e");
|
||||||
assert_eq!(&add_asterisks("pipipipipipi".to_string()), "π*π*π*π*π*π");
|
assert_eq!(&process_func_str("2log10(x)".to_string()), "2*log(x)");
|
||||||
assert_eq!(&add_asterisks("10pi".to_string()), "10*π");
|
assert_eq!(&process_func_str("2log(x)".to_string()), "2*log(x)");
|
||||||
assert_eq!(&add_asterisks("pi10".to_string()), "π*10");
|
assert_eq!(&process_func_str("x!".to_string()), "x!");
|
||||||
|
assert_eq!(&process_func_str("pipipipipipi".to_string()), "π*π*π*π*π*π");
|
||||||
|
assert_eq!(&process_func_str("10pi".to_string()), "10*π");
|
||||||
|
assert_eq!(&process_func_str("pi10".to_string()), "π*10");
|
||||||
|
|
||||||
// Need to fix these checks, maybe I need to rewrite the whole asterisk adding system... (or just implement these changes into meval-rs, idk)
|
// Need to fix these checks, maybe I need to rewrite the whole asterisk adding system... (or just implement these changes into meval-rs, idk)
|
||||||
// assert_eq!(&add_asterisks("emax(x)".to_string()), "e*max(x)");
|
// assert_eq!(&add_asterisks("emax(x)".to_string()), "e*max(x)");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user