cargo clippy + fmt
This commit is contained in:
parent
dd377c1659
commit
bccb19cecc
@ -1,4 +0,0 @@
|
|||||||
edition = "2021"
|
|
||||||
fn_params_layout = "Compressed"
|
|
||||||
fn_single_line = true
|
|
||||||
hard_tabs = true
|
|
||||||
12
build.rs
12
build.rs
@ -8,8 +8,8 @@ use std::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use epaint::{
|
use epaint::{
|
||||||
text::{FontData, FontDefinitions, FontTweak},
|
|
||||||
FontFamily,
|
FontFamily,
|
||||||
|
text::{FontData, FontDefinitions, FontTweak},
|
||||||
};
|
};
|
||||||
|
|
||||||
use run_script::ScriptOptions;
|
use run_script::ScriptOptions;
|
||||||
@ -73,7 +73,9 @@ fn main() {
|
|||||||
println!("cargo:rerun-if-changed=.git/logs/HEAD");
|
println!("cargo:rerun-if-changed=.git/logs/HEAD");
|
||||||
println!("cargo:rerun-if-changed=assets/*");
|
println!("cargo:rerun-if-changed=assets/*");
|
||||||
|
|
||||||
shadow_rs::ShadowBuilder::builder().build().expect("Could not initialize shadow_rs");
|
shadow_rs::ShadowBuilder::builder()
|
||||||
|
.build()
|
||||||
|
.expect("Could not initialize shadow_rs");
|
||||||
|
|
||||||
let mut main_chars: Vec<char> =
|
let mut main_chars: Vec<char> =
|
||||||
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzsu0123456789?.,!(){}[]-_=+-/<>'\\ :^*`@#$%&|~;"
|
b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzsu0123456789?.,!(){}[]-_=+-/<>'\\ :^*`@#$%&|~;"
|
||||||
@ -127,14 +129,16 @@ fn main() {
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"emoji-icon-font".to_owned(),
|
"emoji-icon-font".to_owned(),
|
||||||
Arc::new(FontData::from_owned(
|
Arc::new(
|
||||||
|
FontData::from_owned(
|
||||||
font_stripper("emoji-icon-font.ttf", "emoji-icon.ttf", vec!['⚙']).unwrap(),
|
font_stripper("emoji-icon-font.ttf", "emoji-icon.ttf", vec!['⚙']).unwrap(),
|
||||||
)
|
)
|
||||||
.tweak(FontTweak {
|
.tweak(FontTweak {
|
||||||
scale: 0.8,
|
scale: 0.8,
|
||||||
y_offset_factor: 0.07,
|
y_offset_factor: 0.07,
|
||||||
y_offset: 0.0,
|
y_offset: 0.0,
|
||||||
})),
|
}),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
families: BTreeMap::from([
|
families: BTreeMap::from([
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
use crate::math_app::AppSettings;
|
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::{Checkbox, Context};
|
||||||
use egui_plot::{Bar, BarChart, PlotPoint, PlotUi};
|
use egui_plot::{Bar, BarChart, PlotPoint, PlotUi};
|
||||||
|
|
||||||
use epaint::Color32;
|
use epaint::Color32;
|
||||||
use parsing::{generate_hint, AutoComplete};
|
use parsing::{AutoComplete, generate_hint};
|
||||||
use parsing::{process_func_str, BackingFunction};
|
use parsing::{BackingFunction, process_func_str};
|
||||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer, ser::SerializeStruct};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
@ -23,7 +23,9 @@ pub enum Riemann {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for 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
|
/// `FunctionEntry` is a function that can calculate values, integrals, derivatives, etc etc
|
||||||
@ -142,7 +144,9 @@ impl Default for FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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) {
|
pub fn settings_window(&mut self, ctx: &Context) {
|
||||||
let mut invalidate_nth = false;
|
let mut invalidate_nth = false;
|
||||||
@ -172,7 +176,9 @@ impl FunctionEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get function's cached test result
|
/// 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
|
/// Update function string and test it
|
||||||
pub fn update_string(&mut self, raw_func_str: &str) {
|
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
|
/// Creates and does the math for creating all the rectangles under the graph
|
||||||
fn integral_rectangles(
|
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) {
|
) -> (Vec<(f64, f64)>, f64) {
|
||||||
let step = (integral_max_x - integral_min_x) / (integral_num as 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
|
/// Helps with processing newton's method depending on level of derivative
|
||||||
fn newtons_method_helper(
|
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> {
|
) -> Vec<PlotPoint> {
|
||||||
self.function.generate_derivative(derivative_level);
|
self.function.generate_derivative(derivative_level);
|
||||||
self.function.generate_derivative(derivative_level + 1);
|
self.function.generate_derivative(derivative_level + 1);
|
||||||
@ -244,15 +257,15 @@ impl FunctionEntry {
|
|||||||
threshold,
|
threshold,
|
||||||
range,
|
range,
|
||||||
self.back_data.as_slice(),
|
self.back_data.as_slice(),
|
||||||
&self.function.get_function_derivative(0),
|
self.function.get_function_derivative(0),
|
||||||
&self.function.get_function_derivative(1),
|
self.function.get_function_derivative(1),
|
||||||
),
|
),
|
||||||
1 => newtons_method_helper(
|
1 => newtons_method_helper(
|
||||||
threshold,
|
threshold,
|
||||||
range,
|
range,
|
||||||
self.derivative_data.as_slice(),
|
self.derivative_data.as_slice(),
|
||||||
&self.function.get_function_derivative(1),
|
self.function.get_function_derivative(1),
|
||||||
&self.function.get_function_derivative(2),
|
self.function.get_function_derivative(2),
|
||||||
),
|
),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
@ -265,7 +278,10 @@ impl FunctionEntry {
|
|||||||
|
|
||||||
/// Does the calculations and stores results in `self`
|
/// Does the calculations and stores results in `self`
|
||||||
pub fn calculate(
|
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,
|
settings: AppSettings,
|
||||||
) {
|
) {
|
||||||
if self.test_result.is_some() | self.function.is_none() {
|
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`.
|
/// Displays the function's output on PlotUI `plot_ui` with 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> {
|
||||||
if self.test_result.is_some() | self.function.is_none() {
|
if self.test_result.is_some() | self.function.is_none() {
|
||||||
return None;
|
return None;
|
||||||
@ -455,25 +474,37 @@ impl FunctionEntry {
|
|||||||
|
|
||||||
/// Invalidate `back` data
|
/// Invalidate `back` data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_back(&mut self) { self.back_data.clear(); }
|
fn clear_back(&mut self) {
|
||||||
|
self.back_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// Invalidate Integral data
|
/// Invalidate Integral data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_integral(&mut self) { self.integral_data = None; }
|
fn clear_integral(&mut self) {
|
||||||
|
self.integral_data = None;
|
||||||
|
}
|
||||||
|
|
||||||
/// Invalidate Derivative data
|
/// Invalidate Derivative data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_derivative(&mut self) { self.derivative_data.clear(); }
|
fn clear_derivative(&mut self) {
|
||||||
|
self.derivative_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// Invalidates `n`th derivative data
|
/// Invalidates `n`th derivative data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_nth(&mut self) { self.nth_derivative_data = None }
|
fn clear_nth(&mut self) {
|
||||||
|
self.nth_derivative_data = None
|
||||||
|
}
|
||||||
|
|
||||||
/// Invalidate extrema data
|
/// Invalidate extrema data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_extrema(&mut self) { self.extrema_data.clear() }
|
fn clear_extrema(&mut self) {
|
||||||
|
self.extrema_data.clear()
|
||||||
|
}
|
||||||
|
|
||||||
/// Invalidate root data
|
/// Invalidate root data
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clear_roots(&mut self) { self.root_data.clear() }
|
fn clear_roots(&mut self) {
|
||||||
|
self.root_data.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,33 +156,31 @@ impl FunctionManager {
|
|||||||
|
|
||||||
if let Some(popup_response) = Popup::menu(&re).show(|ui| {
|
if let Some(popup_response) = Popup::menu(&re).show(|ui| {
|
||||||
hints.iter().enumerate().for_each(|(i, candidate)| {
|
hints.iter().enumerate().for_each(|(i, candidate)| {
|
||||||
if ui
|
if ui.selectable_label(i == selected_i, *candidate).clicked() {
|
||||||
.selectable_label(i == selected_i, *candidate)
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
clicked = true;
|
clicked = true;
|
||||||
function.autocomplete.i = i;
|
function.autocomplete.i = i;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}) {
|
}) && clicked
|
||||||
if clicked {
|
{
|
||||||
function
|
function
|
||||||
.autocomplete
|
.autocomplete
|
||||||
.apply_hint(hints[function.autocomplete.i]);
|
.apply_hint(hints[function.autocomplete.i]);
|
||||||
movement = Movement::Complete;
|
movement = Movement::Complete;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Push cursor to end if needed
|
// Push cursor to end if needed
|
||||||
if movement == Movement::Complete {
|
if movement == Movement::Complete
|
||||||
if let Some(mut state) = TextEdit::load_state(ui.ctx(), te_id) {
|
&& let Some(mut state) = TextEdit::load_state(ui.ctx(), te_id)
|
||||||
|
{
|
||||||
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
|
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
|
||||||
state.cursor.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
state
|
||||||
|
.cursor
|
||||||
|
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
|
||||||
TextEdit::store_state(ui.ctx(), te_id, state);
|
TextEdit::store_state(ui.ctx(), te_id, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The y offset multiplier of the `buttons_area` area
|
/// The y offset multiplier of the `buttons_area` area
|
||||||
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
const BUTTONS_Y_OFFSET: f32 = 1.32;
|
||||||
@ -261,11 +259,17 @@ impl FunctionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize { self.functions.len() }
|
pub fn len(&self) -> usize {
|
||||||
|
self.functions.len()
|
||||||
#[inline]
|
}
|
||||||
pub fn get_entries_mut(&mut self) -> &mut Functions { &mut self.functions }
|
|
||||||
|
#[inline]
|
||||||
#[inline]
|
pub fn get_entries_mut(&mut self) -> &mut Functions {
|
||||||
pub fn get_entries(&self) -> &Functions { &self.functions }
|
&mut self.functions
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn get_entries(&self) -> &Functions {
|
||||||
|
&self.functions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,8 +13,8 @@ pub use crate::{
|
|||||||
function_entry::{FunctionEntry, Riemann},
|
function_entry::{FunctionEntry, Riemann},
|
||||||
math_app::AppSettings,
|
math_app::AppSettings,
|
||||||
misc::{
|
misc::{
|
||||||
hashed_storage_create, hashed_storage_read, newtons_method, option_vec_printer,
|
EguiHelper, HashBytes, hashed_storage_create, hashed_storage_read, newtons_method,
|
||||||
step_helper, EguiHelper, HashBytes,
|
option_vec_printer, step_helper,
|
||||||
},
|
},
|
||||||
unicode_helper::{to_chars_array, to_unicode_hash},
|
unicode_helper::{to_chars_array, to_unicode_hash},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
use crate::{
|
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_entry::Riemann,
|
||||||
function_manager::FunctionManager,
|
function_manager::FunctionManager,
|
||||||
misc::option_vec_printer,
|
misc::option_vec_printer,
|
||||||
};
|
};
|
||||||
use eframe::App;
|
use eframe::App;
|
||||||
use egui::{
|
use egui::{
|
||||||
Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout,
|
Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout, Panel, Ui,
|
||||||
Panel, Ui, Vec2, Window,
|
Vec2, Window,
|
||||||
};
|
};
|
||||||
use egui_plot::Plot;
|
use egui_plot::Plot;
|
||||||
|
|
||||||
use emath::{Align, Align2};
|
use emath::{Align, Align2};
|
||||||
use epaint::{CornerRadius, Margin};
|
use epaint::{CornerRadius, Margin};
|
||||||
use web_time::Instant;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use std::{io::Read, ops::BitXorAssign};
|
use std::{io::Read, ops::BitXorAssign};
|
||||||
|
use web_time::Instant;
|
||||||
|
|
||||||
/// Stores current settings/state of [`MathApp`]
|
/// Stores current settings/state of [`MathApp`]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -111,7 +111,9 @@ pub struct MathApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
fn get_localstorage() -> web_sys::Storage {
|
fn get_localstorage() -> web_sys::Storage {
|
||||||
@ -251,9 +253,7 @@ impl MathApp {
|
|||||||
fn side_panel(&mut self, ctx: &Context) {
|
fn side_panel(&mut self, ctx: &Context) {
|
||||||
// Side Panel which contains vital options to the operation of the application
|
// Side Panel which contains vital options to the operation of the application
|
||||||
// (such as adding functions and other options)
|
// (such as adding functions and other options)
|
||||||
Panel::left("side_panel")
|
Panel::left("side_panel").resizable(false).show(ctx, |ui| {
|
||||||
.resizable(false)
|
|
||||||
.show(ctx, |ui| {
|
|
||||||
let any_using_integral = self.functions.any_using_integral();
|
let any_using_integral = self.functions.any_using_integral();
|
||||||
let prev_sum = self.settings.riemann_sum;
|
let prev_sum = self.settings.riemann_sum;
|
||||||
// ComboBox for selecting what Riemann sum type to use
|
// ComboBox for selecting what Riemann sum type to use
|
||||||
@ -265,11 +265,7 @@ impl MathApp {
|
|||||||
ComboBox::from_label("Riemann Sum")
|
ComboBox::from_label("Riemann Sum")
|
||||||
.selected_text(self.settings.riemann_sum.to_string())
|
.selected_text(self.settings.riemann_sum.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
ui.selectable_value(
|
ui.selectable_value(&mut self.settings.riemann_sum, Riemann::Left, "Left");
|
||||||
&mut self.settings.riemann_sum,
|
|
||||||
Riemann::Left,
|
|
||||||
"Left",
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
ui.selectable_value(
|
||||||
&mut self.settings.riemann_sum,
|
&mut self.settings.riemann_sum,
|
||||||
Riemann::Middle,
|
Riemann::Middle,
|
||||||
@ -364,7 +360,7 @@ impl MathApp {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
{
|
{
|
||||||
tracing::info!("Saving function data");
|
tracing::info!("Saving function data");
|
||||||
use crate::misc::{hashed_storage_create, HashBytes};
|
use crate::misc::{HashBytes, hashed_storage_create};
|
||||||
let hash: HashBytes =
|
let hash: HashBytes =
|
||||||
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
|
unsafe { std::mem::transmute::<&str, HashBytes>(build::SHORT_COMMIT) };
|
||||||
let saved_data = hashed_storage_create(
|
let saved_data = hashed_storage_create(
|
||||||
|
|||||||
30
src/misc.rs
30
src/misc.rs
@ -26,10 +26,14 @@ impl EguiHelper for Vec<PlotPoint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_line(self) -> Line<'static> { Line::new("", self.to_values()) }
|
fn to_line(self) -> Line<'static> {
|
||||||
|
Line::new("", self.to_values())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_points(self) -> Points<'static> { Points::new("", self.to_values()) }
|
fn to_points(self) -> Points<'static> {
|
||||||
|
Points::new("", self.to_values())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_tuple(self) -> Vec<(f64, f64)> {
|
fn to_tuple(self) -> Vec<(f64, f64)> {
|
||||||
@ -58,9 +62,13 @@ impl Offset for Pos2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn create_id(x: u64) -> Id { unsafe { std::mem::transmute::<u64, Id>(x) } }
|
pub const fn create_id(x: u64) -> Id {
|
||||||
|
unsafe { std::mem::transmute::<u64, Id>(x) }
|
||||||
|
}
|
||||||
|
|
||||||
pub const fn get_u64_id(id: Id) -> u64 { unsafe { std::mem::transmute::<Id, u64>(id) } }
|
pub const fn get_u64_id(id: Id) -> u64 {
|
||||||
|
unsafe { std::mem::transmute::<Id, u64>(id) }
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
/// Rounds f64 to `n` decimal places
|
/// Rounds f64 to `n` decimal places
|
||||||
@ -79,7 +87,10 @@ pub fn decimal_round(x: f64, n: usize) -> f64 {
|
|||||||
/// `f_1` is f'(x) aka the derivative of f(x)
|
/// `f_1` is f'(x) aka the derivative of f(x)
|
||||||
/// The function returns a Vector of `x` values where roots occur
|
/// The function returns a Vector of `x` values where roots occur
|
||||||
pub fn newtons_method_helper(
|
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,
|
f_1: &FlatExWrapper,
|
||||||
) -> Vec<f64> {
|
) -> Vec<f64> {
|
||||||
data.iter()
|
data.iter()
|
||||||
@ -98,7 +109,10 @@ pub fn newtons_method_helper(
|
|||||||
/// `f_1` is f'(x) aka the derivative of f(x)
|
/// `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
|
/// The function returns an `Option<f64>` of the x value at which a root occurs
|
||||||
pub fn newtons_method(
|
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,
|
threshold: f64,
|
||||||
) -> Option<f64> {
|
) -> Option<f64> {
|
||||||
let mut x1: f64 = start_x;
|
let mut x1: f64 = start_x;
|
||||||
@ -197,4 +211,6 @@ pub fn random_u64() -> Result<u64, getrandom::Error> {
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/valid_chars.rs"));
|
include!(concat!(env!("OUT_DIR"), "/valid_chars.rs"));
|
||||||
|
|
||||||
pub fn is_valid_char(c: char) -> bool { c.is_alphanumeric() | VALID_EXTRA_CHARS.contains(&c) }
|
pub fn is_valid_char(c: char) -> bool {
|
||||||
|
c.is_alphanumeric() | VALID_EXTRA_CHARS.contains(&c)
|
||||||
|
}
|
||||||
|
|||||||
@ -3,7 +3,10 @@ use egui::{Id, InnerResponse};
|
|||||||
|
|
||||||
/// Creates an area ontop of a widget with an y offset
|
/// Creates an area ontop of a widget with an y offset
|
||||||
pub fn widgets_ontop<R>(
|
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,
|
add_contents: impl FnOnce(&mut egui::Ui) -> R,
|
||||||
) -> InnerResponse<R> {
|
) -> InnerResponse<R> {
|
||||||
let area = egui::Area::new(id)
|
let area = egui::Area::new(id)
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
use ytbn_graphing_software::{AppSettings, EguiHelper, FunctionEntry, Riemann};
|
use ytbn_graphing_software::{AppSettings, EguiHelper, FunctionEntry, Riemann};
|
||||||
|
|
||||||
fn app_settings_constructor(
|
fn app_settings_constructor(
|
||||||
sum: Riemann, integral_min_x: f64, integral_max_x: f64, pixel_width: usize,
|
sum: Riemann,
|
||||||
integral_num: usize, min_x: f64, max_x: f64,
|
integral_min_x: f64,
|
||||||
|
integral_max_x: f64,
|
||||||
|
pixel_width: usize,
|
||||||
|
integral_num: usize,
|
||||||
|
min_x: f64,
|
||||||
|
max_x: f64,
|
||||||
) -> AppSettings {
|
) -> AppSettings {
|
||||||
AppSettings {
|
AppSettings {
|
||||||
riemann_sum: sum,
|
riemann_sum: sum,
|
||||||
@ -253,10 +258,16 @@ fn do_test(sum: Riemann, area_target: f64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn left_function() { do_test(Riemann::Left, 0.9600000000000001); }
|
fn left_function() {
|
||||||
|
do_test(Riemann::Left, 0.9600000000000001);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn middle_function() { do_test(Riemann::Middle, 0.92); }
|
fn middle_function() {
|
||||||
|
do_test(Riemann::Middle, 0.92);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[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