cleanup
This commit is contained in:
parent
0f035ad22c
commit
2025528682
4
build.sh
4
build.sh
@ -13,13 +13,13 @@ wasm_opt() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if test "$1" == "" || test "$1" == "release"; then
|
if test "$1" == "" || test "$1" == "release"; then
|
||||||
wasm-pack build --target web --release --no-typescript
|
RUSTFLAGS=--cfg=web_sys_unstable_apis wasm-pack build --target web --release --no-typescript
|
||||||
echo "Binary size (pre-wasm_opt): $(du -sb pkg/ytbn_graphing_software_bg.wasm)"
|
echo "Binary size (pre-wasm_opt): $(du -sb pkg/ytbn_graphing_software_bg.wasm)"
|
||||||
wasm_opt #apply wasm optimizations
|
wasm_opt #apply wasm optimizations
|
||||||
echo "Binary size (pre-strip): $(du -sb pkg/ytbn_graphing_software_bg.wasm)"
|
echo "Binary size (pre-strip): $(du -sb pkg/ytbn_graphing_software_bg.wasm)"
|
||||||
llvm-strip --strip-all pkg/ytbn_graphing_software_bg.wasm
|
llvm-strip --strip-all pkg/ytbn_graphing_software_bg.wasm
|
||||||
elif test "$1" == "debug"; then
|
elif test "$1" == "debug"; then
|
||||||
wasm-pack build --target web --debug --no-typescript
|
RUSTFLAGS=--cfg=web_sys_unstable_apis wasm-pack build --target web --debug --no-typescript
|
||||||
else
|
else
|
||||||
echo "ERROR: build.sh, argument invalid"
|
echo "ERROR: build.sh, argument invalid"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@ -36,12 +36,10 @@ lazy_static::lazy_static! {
|
|||||||
/// derivatives, etc etc
|
/// derivatives, etc etc
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FunctionEntry {
|
pub struct FunctionEntry {
|
||||||
/// The `BackingFunction` instance that is used to generate `f(x)`, `f'(x)`,
|
/// The `BackingFunction` instance that is used to generate `f(x)`, `f'(x)`, and `f''(x)`
|
||||||
/// and `f''(x)`
|
|
||||||
function: BackingFunction,
|
function: BackingFunction,
|
||||||
|
|
||||||
/// Stores a function string (that hasn't been processed via
|
/// Stores a function string (that hasn't been processed via `process_func_str`) to display to the user
|
||||||
/// `process_func_str`) to display to the user
|
|
||||||
raw_func_str: String,
|
raw_func_str: String,
|
||||||
|
|
||||||
/// Minimum and Maximum values of what do display
|
/// Minimum and Maximum values of what do display
|
||||||
@ -51,8 +49,7 @@ pub struct FunctionEntry {
|
|||||||
/// If calculating/displayingintegrals are enabled
|
/// If calculating/displayingintegrals are enabled
|
||||||
pub integral: bool,
|
pub integral: bool,
|
||||||
|
|
||||||
/// If displaying derivatives are enabled (note, they are still calculated
|
/// If displaying derivatives are enabled (note, they are still calculated for other purposes)
|
||||||
/// for other purposes)
|
|
||||||
pub derivative: bool,
|
pub derivative: bool,
|
||||||
|
|
||||||
back_data: Option<Vec<Value>>,
|
back_data: Option<Vec<Value>>,
|
||||||
@ -88,8 +85,7 @@ impl Default for FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionEntry {
|
impl FunctionEntry {
|
||||||
pub fn get_func_raw(&self) -> String { self.raw_func_str.to_string() }
|
/// Create autocomplete ui and handle user input
|
||||||
|
|
||||||
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, bool, Option<String>) {
|
pub fn auto_complete(&mut self, ui: &mut egui::Ui, i: i32) -> (bool, bool, Option<String>) {
|
||||||
let (output_string, in_focus) = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
|
let (output_string, in_focus) = self.autocomplete.ui(ui, self.raw_func_str.clone(), i);
|
||||||
|
|
||||||
@ -101,8 +97,10 @@ impl FunctionEntry {
|
|||||||
(in_focus, changed, self.get_test_result())
|
(in_focus, changed, self.get_test_result())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get function's cached test result
|
||||||
pub fn get_test_result(&self) -> Option<String> { self.test_result.clone() }
|
pub fn get_test_result(&self) -> Option<String> { self.test_result.clone() }
|
||||||
|
|
||||||
|
/// Update function string and test it
|
||||||
fn update_string(&mut self, raw_func_str: &str) {
|
fn update_string(&mut self, raw_func_str: &str) {
|
||||||
let processed_func = process_func_str(raw_func_str);
|
let processed_func = process_func_str(raw_func_str);
|
||||||
let output = crate::parsing::test_func(&processed_func);
|
let output = crate::parsing::test_func(&processed_func);
|
||||||
@ -118,6 +116,7 @@ impl FunctionEntry {
|
|||||||
self.invalidate_whole();
|
self.invalidate_whole();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get function that can be used to calculate integral based on Riemann Sum type
|
||||||
fn get_sum_func(&self, sum: Riemann) -> FunctionHelper {
|
fn get_sum_func(&self, sum: Riemann) -> FunctionHelper {
|
||||||
match sum {
|
match sum {
|
||||||
Riemann::Left => {
|
Riemann::Left => {
|
||||||
@ -132,8 +131,7 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates and does the math for creating all the rectangles under the
|
/// Creates and does the math for creating all the rectangles under the graph
|
||||||
/// graph
|
|
||||||
fn integral_rectangles(
|
fn integral_rectangles(
|
||||||
&self, integral_min_x: &f64, integral_max_x: &f64, sum: &Riemann, integral_num: &usize,
|
&self, integral_min_x: &f64, integral_max_x: &f64, sum: &Riemann, integral_num: &usize,
|
||||||
) -> (Vec<(f64, f64)>, f64) {
|
) -> (Vec<(f64, f64)>, f64) {
|
||||||
@ -249,7 +247,9 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
debug_assert_eq!(back_data.len(), settings.plot_width + 1);
|
debug_assert_eq!(back_data.len(), settings.plot_width + 1);
|
||||||
|
|
||||||
self.back_data = Some(back_data);
|
self.back_data = Some(back_data);
|
||||||
|
|
||||||
if derivative_required {
|
if derivative_required {
|
||||||
@ -322,8 +322,8 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Displays the function's output on PlotUI `plot_ui` with settings
|
/// Displays the function's output on PlotUI `plot_ui` with settings `settings`.
|
||||||
/// `settings`. Returns an `Option<f64>` of the calculated integral
|
/// Returns an `Option<f64>` of the calculated integral.
|
||||||
pub fn display(
|
pub fn display(
|
||||||
&self, plot_ui: &mut PlotUi, settings: &AppSettings, main_plot_color: Color32,
|
&self, plot_ui: &mut PlotUi, settings: &AppSettings, main_plot_color: Color32,
|
||||||
) -> Option<f64> {
|
) -> Option<f64> {
|
||||||
@ -341,7 +341,7 @@ impl FunctionEntry {
|
|||||||
.clone()
|
.clone()
|
||||||
.to_line()
|
.to_line()
|
||||||
.color(main_plot_color)
|
.color(main_plot_color)
|
||||||
.name(self.get_func_raw()),
|
.name(&self.raw_func_str),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,21 +420,6 @@ impl FunctionEntry {
|
|||||||
/// Invalidate Derivative data
|
/// Invalidate Derivative data
|
||||||
pub fn invalidate_derivative(&mut self) { self.derivative_data = None; }
|
pub fn invalidate_derivative(&mut self) { self.derivative_data = None; }
|
||||||
|
|
||||||
/// Depreciated, but still used for tests
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn update(
|
|
||||||
&mut self, raw_func_str: &str, integral: bool, derivative: bool,
|
|
||||||
) -> Option<String> {
|
|
||||||
self.derivative = derivative;
|
|
||||||
self.integral = integral;
|
|
||||||
if raw_func_str != self.get_func_raw() {
|
|
||||||
self.update_string(raw_func_str);
|
|
||||||
self.get_test_result()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Runs asserts to make sure everything is the expected value
|
/// Runs asserts to make sure everything is the expected value
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn tests(
|
pub fn tests(
|
||||||
@ -468,7 +453,12 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
self.update("x^3", false, false);
|
self.update_string("x^3");
|
||||||
|
assert_eq!(&self.raw_func_str, "x^3");
|
||||||
|
|
||||||
|
self.integral = false;
|
||||||
|
self.derivative = false;
|
||||||
|
|
||||||
assert!(!self.integral);
|
assert!(!self.integral);
|
||||||
assert!(!self.derivative);
|
assert!(!self.derivative);
|
||||||
|
|
||||||
@ -541,7 +531,9 @@ mod tests {
|
|||||||
let settings = app_settings_constructor(sum, -1.0, 1.0, 10, 10);
|
let settings = app_settings_constructor(sum, -1.0, 1.0, 10, 10);
|
||||||
|
|
||||||
let mut function = FunctionEntry::default();
|
let mut function = FunctionEntry::default();
|
||||||
function.update("x^2", true, true);
|
function.update_string("x^2");
|
||||||
|
function.integral = true;
|
||||||
|
function.derivative = true;
|
||||||
|
|
||||||
function.tests(
|
function.tests(
|
||||||
settings,
|
settings,
|
||||||
|
|||||||
@ -114,8 +114,8 @@ impl AutoComplete {
|
|||||||
if clicked | apply_key {
|
if clicked | apply_key {
|
||||||
new_string += hints[self.i];
|
new_string += hints[self.i];
|
||||||
|
|
||||||
// don't need this here as it simply won't be display next
|
// don't need this here as it simply won't be display next frame in `math_app.rs`
|
||||||
// frame in `math_app.rs` ui.memory().close_popup();
|
// ui.memory().close_popup();
|
||||||
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user