cargo clippy + fmt
This commit is contained in:
parent
5a92020dae
commit
aa07631296
@ -1,4 +0,0 @@
|
||||
edition = "2021"
|
||||
fn_params_layout = "Compressed"
|
||||
fn_single_line = true
|
||||
hard_tabs = true
|
||||
2
build.rs
2
build.rs
@ -7,8 +7,8 @@ use std::{
|
||||
};
|
||||
|
||||
use epaint::{
|
||||
text::{FontData, FontDefinitions, FontTweak},
|
||||
FontFamily,
|
||||
text::{FontData, FontDefinitions, FontTweak},
|
||||
};
|
||||
|
||||
use run_script::ScriptOptions;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use crate::math_app::AppSettings;
|
||||
use crate::misc::{newtons_method_helper, step_helper, EguiHelper};
|
||||
use crate::misc::{EguiHelper, newtons_method_helper, step_helper};
|
||||
use egui::{Checkbox, Context};
|
||||
use egui_plot::{Bar, BarChart, PlotPoint, PlotUi};
|
||||
|
||||
use epaint::Color32;
|
||||
use parsing::{generate_hint, AutoComplete};
|
||||
use parsing::{process_func_str, BackingFunction};
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use parsing::{AutoComplete, generate_hint};
|
||||
use parsing::{BackingFunction, process_func_str};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer, ser::SerializeStruct};
|
||||
use std::{
|
||||
fmt::{self, Debug},
|
||||
hash::{Hash, Hasher},
|
||||
@ -23,7 +23,9 @@ pub enum Riemann {
|
||||
}
|
||||
|
||||
impl fmt::Display for Riemann {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self) }
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
/// `FunctionEntry` is a function that can calculate values, integrals, derivatives, etc etc
|
||||
@ -142,7 +144,9 @@ impl Default for FunctionEntry {
|
||||
}
|
||||
|
||||
impl FunctionEntry {
|
||||
pub const fn is_some(&self) -> bool { !self.function.is_none() }
|
||||
pub const fn is_some(&self) -> bool {
|
||||
!self.function.is_none()
|
||||
}
|
||||
|
||||
pub fn settings_window(&mut self, ctx: &Context) {
|
||||
let mut invalidate_nth = false;
|
||||
@ -172,7 +176,9 @@ impl FunctionEntry {
|
||||
}
|
||||
|
||||
/// Get function's cached test result
|
||||
pub fn get_test_result(&self) -> &Option<String> { &self.test_result }
|
||||
pub fn get_test_result(&self) -> &Option<String> {
|
||||
&self.test_result
|
||||
}
|
||||
|
||||
/// Update function string and test it
|
||||
pub fn update_string(&mut self, raw_func_str: &str) {
|
||||
@ -198,7 +204,11 @@ impl FunctionEntry {
|
||||
|
||||
/// Creates and does the math for creating all the rectangles under the graph
|
||||
fn integral_rectangles(
|
||||
&mut self, integral_min_x: f64, integral_max_x: f64, sum: Riemann, integral_num: usize,
|
||||
&mut self,
|
||||
integral_min_x: f64,
|
||||
integral_max_x: f64,
|
||||
sum: Riemann,
|
||||
integral_num: usize,
|
||||
) -> (Vec<(f64, f64)>, f64) {
|
||||
let step = (integral_max_x - integral_min_x) / (integral_num as f64);
|
||||
|
||||
@ -235,7 +245,10 @@ impl FunctionEntry {
|
||||
|
||||
/// Helps with processing newton's method depending on level of derivative
|
||||
fn newtons_method_helper(
|
||||
&mut self, threshold: f64, derivative_level: usize, range: &std::ops::Range<f64>,
|
||||
&mut self,
|
||||
threshold: f64,
|
||||
derivative_level: usize,
|
||||
range: &std::ops::Range<f64>,
|
||||
) -> Vec<PlotPoint> {
|
||||
self.function.generate_derivative(derivative_level);
|
||||
self.function.generate_derivative(derivative_level + 1);
|
||||
@ -244,15 +257,15 @@ impl FunctionEntry {
|
||||
threshold,
|
||||
range,
|
||||
self.back_data.as_slice(),
|
||||
&self.function.get_function_derivative(0),
|
||||
&self.function.get_function_derivative(1),
|
||||
self.function.get_function_derivative(0),
|
||||
self.function.get_function_derivative(1),
|
||||
),
|
||||
1 => newtons_method_helper(
|
||||
threshold,
|
||||
range,
|
||||
self.derivative_data.as_slice(),
|
||||
&self.function.get_function_derivative(1),
|
||||
&self.function.get_function_derivative(2),
|
||||
self.function.get_function_derivative(1),
|
||||
self.function.get_function_derivative(2),
|
||||
),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@ -265,7 +278,10 @@ impl FunctionEntry {
|
||||
|
||||
/// Does the calculations and stores results in `self`
|
||||
pub fn calculate(
|
||||
&mut self, width_changed: bool, min_max_changed: bool, did_zoom: bool,
|
||||
&mut self,
|
||||
width_changed: bool,
|
||||
min_max_changed: bool,
|
||||
did_zoom: bool,
|
||||
settings: AppSettings,
|
||||
) {
|
||||
if self.test_result.is_some() | self.function.is_none() {
|
||||
@ -353,7 +369,10 @@ impl FunctionEntry {
|
||||
/// Displays the function's output on PlotUI `plot_ui` with settings `settings`.
|
||||
/// Returns an `Option<f64>` of the calculated integral.
|
||||
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> {
|
||||
if self.test_result.is_some() | self.function.is_none() {
|
||||
return None;
|
||||
@ -455,25 +474,37 @@ impl FunctionEntry {
|
||||
|
||||
/// Invalidate `back` data
|
||||
#[inline]
|
||||
fn clear_back(&mut self) { self.back_data.clear(); }
|
||||
fn clear_back(&mut self) {
|
||||
self.back_data.clear();
|
||||
}
|
||||
|
||||
/// Invalidate Integral data
|
||||
#[inline]
|
||||
fn clear_integral(&mut self) { self.integral_data = None; }
|
||||
fn clear_integral(&mut self) {
|
||||
self.integral_data = None;
|
||||
}
|
||||
|
||||
/// Invalidate Derivative data
|
||||
#[inline]
|
||||
fn clear_derivative(&mut self) { self.derivative_data.clear(); }
|
||||
fn clear_derivative(&mut self) {
|
||||
self.derivative_data.clear();
|
||||
}
|
||||
|
||||
/// Invalidates `n`th derivative data
|
||||
#[inline]
|
||||
fn clear_nth(&mut self) { self.nth_derivative_data = None }
|
||||
fn clear_nth(&mut self) {
|
||||
self.nth_derivative_data = None
|
||||
}
|
||||
|
||||
/// Invalidate extrema data
|
||||
#[inline]
|
||||
fn clear_extrema(&mut self) { self.extrema_data.clear() }
|
||||
fn clear_extrema(&mut self) {
|
||||
self.extrema_data.clear()
|
||||
}
|
||||
|
||||
/// Invalidate root data
|
||||
#[inline]
|
||||
fn clear_roots(&mut self) { self.root_data.clear() }
|
||||
fn clear_roots(&mut self) {
|
||||
self.root_data.clear()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
use crate::{
|
||||
consts::COLORS,
|
||||
function_entry::FunctionEntry,
|
||||
misc::{random_u64},
|
||||
widgets::widgets_ontop,
|
||||
consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop,
|
||||
};
|
||||
use egui::{Button, Id, Key, Modifiers, TextEdit, WidgetText};
|
||||
use emath::vec2;
|
||||
@ -22,14 +19,13 @@ impl Default for FunctionManager {
|
||||
fn default() -> Self {
|
||||
let mut vec: Functions = Vec::with_capacity(COLORS.len());
|
||||
vec.push((
|
||||
Id::new(11414819524356497634 as u64), // Random number here to avoid call to crate::misc::random_u64()
|
||||
Id::new(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64()
|
||||
FunctionEntry::default(),
|
||||
));
|
||||
Self { functions: vec }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Serialize for FunctionManager {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@ -151,7 +147,7 @@ impl FunctionManager {
|
||||
|
||||
let autocomplete_popup_id = Id::new("autocomplete popup");
|
||||
|
||||
egui::popup_below_widget(ui, autocomplete_popup_id.clone(), &re, |ui| {
|
||||
egui::popup_below_widget(ui, autocomplete_popup_id, &re, |ui| {
|
||||
hints.iter().enumerate().for_each(|(i, candidate)| {
|
||||
if ui
|
||||
.selectable_label(i == function.autocomplete.i, *candidate)
|
||||
@ -170,7 +166,7 @@ impl FunctionManager {
|
||||
|
||||
movement = Movement::Complete;
|
||||
} else {
|
||||
ui.memory_mut(|x| x.open_popup(autocomplete_popup_id.clone()));
|
||||
ui.memory_mut(|x| x.open_popup(autocomplete_popup_id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,12 +257,17 @@ impl FunctionManager {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize { self.functions.len() }
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn get_entries_mut(&mut self) -> &mut Functions { &mut self.functions }
|
||||
|
||||
#[inline]
|
||||
pub fn get_entries(&self) -> &Functions { &self.functions }
|
||||
pub fn len(&self) -> usize {
|
||||
self.functions.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_entries_mut(&mut self) -> &mut Functions {
|
||||
&mut self.functions
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_entries(&self) -> &Functions {
|
||||
&self.functions
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@ pub use crate::{
|
||||
function_entry::{FunctionEntry, Riemann},
|
||||
math_app::AppSettings,
|
||||
misc::{
|
||||
hashed_storage_create, hashed_storage_read, newtons_method, option_vec_printer,
|
||||
step_helper, EguiHelper, HashBytes,
|
||||
EguiHelper, HashBytes, hashed_storage_create, hashed_storage_read, newtons_method,
|
||||
option_vec_printer, step_helper,
|
||||
},
|
||||
unicode_helper::{to_chars_array, to_unicode_hash},
|
||||
};
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
consts::{build, BUILD_INFO, COLORS, DEFAULT_INTEGRAL_NUM, DEFAULT_MAX_X, DEFAULT_MIN_X},
|
||||
consts::{BUILD_INFO, COLORS, DEFAULT_INTEGRAL_NUM, DEFAULT_MAX_X, DEFAULT_MIN_X, build},
|
||||
function_entry::Riemann,
|
||||
function_manager::FunctionManager,
|
||||
misc::option_vec_printer,
|
||||
};
|
||||
use eframe::App;
|
||||
use egui::{
|
||||
style::Margin, Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout,
|
||||
SidePanel, TopBottomPanel, Ui, Vec2, Window,
|
||||
Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout, SidePanel,
|
||||
TopBottomPanel, Ui, Vec2, Window, style::Margin,
|
||||
};
|
||||
use egui_plot::Plot;
|
||||
|
||||
@ -111,7 +111,9 @@ pub struct MathApp {
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn get_window() -> web_sys::Window { web_sys::window().expect("Could not get web_sys window") }
|
||||
fn get_window() -> web_sys::Window {
|
||||
web_sys::window().expect("Could not get web_sys window")
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn get_localstorage() -> web_sys::Storage {
|
||||
@ -176,8 +178,11 @@ impl MathApp {
|
||||
|
||||
fn decompress_fonts() -> epaint::text::FontDefinitions {
|
||||
let mut data = Vec::new();
|
||||
let _ = ruzstd::StreamingDecoder::new(
|
||||
&mut const { include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice() },
|
||||
let _ =
|
||||
ruzstd::StreamingDecoder::new(
|
||||
&mut const {
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice()
|
||||
},
|
||||
)
|
||||
.expect("unable to decode compressed data")
|
||||
.read_to_end(&mut data)
|
||||
@ -357,7 +362,7 @@ impl MathApp {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
tracing::info!("Saving function data");
|
||||
use crate::misc::{hashed_storage_create, HashBytes};
|
||||
use crate::misc::{HashBytes, hashed_storage_create};
|
||||
let hash: HashBytes =
|
||||
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
|
||||
let saved_data = hashed_storage_create(
|
||||
|
||||
12
src/misc.rs
12
src/misc.rs
@ -1,4 +1,4 @@
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
|
||||
use emath::Pos2;
|
||||
use getrandom::getrandom;
|
||||
@ -80,7 +80,10 @@ pub fn decimal_round(x: f64, n: usize) -> f64 {
|
||||
/// `f_1` is f'(x) aka the derivative of f(x)
|
||||
/// The function returns a Vector of `x` values where roots occur
|
||||
pub fn newtons_method_helper(
|
||||
threshold: f64, range: &std::ops::Range<f64>, data: &[PlotPoint], f: &FlatExWrapper,
|
||||
threshold: f64,
|
||||
range: &std::ops::Range<f64>,
|
||||
data: &[PlotPoint],
|
||||
f: &FlatExWrapper,
|
||||
f_1: &FlatExWrapper,
|
||||
) -> Vec<f64> {
|
||||
data.iter()
|
||||
@ -99,7 +102,10 @@ pub fn newtons_method_helper(
|
||||
/// `f_1` is f'(x) aka the derivative of f(x)
|
||||
/// The function returns an `Option<f64>` of the x value at which a root occurs
|
||||
pub fn newtons_method(
|
||||
f: &FlatExWrapper, f_1: &FlatExWrapper, start_x: f64, range: &std::ops::Range<f64>,
|
||||
f: &FlatExWrapper,
|
||||
f_1: &FlatExWrapper,
|
||||
start_x: f64,
|
||||
range: &std::ops::Range<f64>,
|
||||
threshold: f64,
|
||||
) -> Option<f64> {
|
||||
let mut x1: f64 = start_x;
|
||||
|
||||
@ -3,7 +3,10 @@ use egui::{Id, InnerResponse};
|
||||
|
||||
/// Creates an area ontop of a widget with an y offset
|
||||
pub fn widgets_ontop<R>(
|
||||
ui: &egui::Ui, id: Id, re: &egui::Response, y_offset: f32,
|
||||
ui: &egui::Ui,
|
||||
id: Id,
|
||||
re: &egui::Response,
|
||||
y_offset: f32,
|
||||
add_contents: impl FnOnce(&mut egui::Ui) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
let area = egui::Area::new(id)
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
use ytbn_graphing_software::{AppSettings, EguiHelper, FunctionEntry, Riemann};
|
||||
|
||||
fn app_settings_constructor(
|
||||
sum: Riemann, integral_min_x: f64, integral_max_x: f64, pixel_width: usize,
|
||||
integral_num: usize, min_x: f64, max_x: f64,
|
||||
sum: Riemann,
|
||||
integral_min_x: f64,
|
||||
integral_max_x: f64,
|
||||
pixel_width: usize,
|
||||
integral_num: usize,
|
||||
min_x: f64,
|
||||
max_x: f64,
|
||||
) -> AppSettings {
|
||||
AppSettings {
|
||||
riemann_sum: sum,
|
||||
@ -253,10 +258,16 @@ fn do_test(sum: Riemann, area_target: f64) {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn left_function() { do_test(Riemann::Left, 0.9600000000000001); }
|
||||
fn left_function() {
|
||||
do_test(Riemann::Left, 0.9600000000000001);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn middle_function() { do_test(Riemann::Middle, 0.92); }
|
||||
fn middle_function() {
|
||||
do_test(Riemann::Middle, 0.92);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn right_function() { do_test(Riemann::Right, 0.8800000000000001); }
|
||||
fn right_function() {
|
||||
do_test(Riemann::Right, 0.8800000000000001);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user