cleanup
This commit is contained in:
parent
e170dee22a
commit
73e3760a8b
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -663,7 +663,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "eframe"
|
name = "eframe"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
@ -683,7 +683,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"epaint",
|
"epaint",
|
||||||
@ -694,7 +694,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "egui-winit"
|
name = "egui-winit"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arboard",
|
"arboard",
|
||||||
"egui",
|
"egui",
|
||||||
@ -707,7 +707,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "egui_glow"
|
name = "egui_glow"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
@ -727,7 +727,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "emath"
|
name = "emath"
|
||||||
version = "0.18.0"
|
version = "0.18.0"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
]
|
]
|
||||||
@ -735,7 +735,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "epaint"
|
name = "epaint"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#ffef46110abfe2d0c9891d3e457eccb1b8a75842"
|
source = "git+https://github.com/Titaniumtown/egui.git#16d09cfe61bd5c961d0eabdc964e91569d870979"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"ahash",
|
"ahash",
|
||||||
@ -1959,7 +1959,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "ruzstd"
|
name = "ruzstd"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
source = "git+https://github.com/Titaniumtown/zstd-rs.git?branch=ringbuffer#d7f5caaf23146cd525a2a215241661ecf0aa073a"
|
source = "git+https://github.com/Titaniumtown/zstd-rs.git?branch=ringbuffer#5acbe502b4047eb1d02c8a338d725ead806635de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"twox-hash",
|
"twox-hash",
|
||||||
|
|||||||
@ -11,7 +11,7 @@ fn compare_len_reverse_alpha(a: &String, b: &String) -> Ordering {
|
|||||||
|
|
||||||
/// Generates hashmap (well really a vector of tuple of strings that are then turned into a hashmap by phf)
|
/// Generates hashmap (well really a vector of tuple of strings that are then turned into a hashmap by phf)
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
|
pub(crate) fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
|
||||||
let mut seen = HashSet::new();
|
let mut seen = HashSet::new();
|
||||||
|
|
||||||
let tuple_list_1: Vec<(String, String)> = data
|
let tuple_list_1: Vec<(String, String)> = data
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
#![feature(const_default_impls)]
|
||||||
|
|
||||||
pub mod parsing;
|
pub mod parsing;
|
||||||
pub mod suggestions;
|
pub mod suggestions;
|
||||||
|
|||||||
@ -8,44 +8,33 @@ pub struct FlatExWrapper {
|
|||||||
impl FlatExWrapper {
|
impl FlatExWrapper {
|
||||||
const EMPTY: FlatExWrapper = FlatExWrapper { func: None };
|
const EMPTY: FlatExWrapper = FlatExWrapper { func: None };
|
||||||
|
|
||||||
fn new(f: FlatEx<f64>) -> Self { Self { func: Some(f) } }
|
const fn new(f: FlatEx<f64>) -> Self { Self { func: Some(f) } }
|
||||||
|
|
||||||
fn eval(&self, x: &[f64]) -> f64 {
|
fn eval(&self, x: &[f64]) -> f64 {
|
||||||
if let Some(ref f) = self.func {
|
self.func
|
||||||
f.eval(x).unwrap_or(f64::NAN)
|
.as_ref()
|
||||||
} else {
|
.map(|f| f.eval(x).unwrap_or(f64::NAN))
|
||||||
f64::NAN
|
.unwrap_or(f64::NAN)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn partial(&self, x: usize) -> Self {
|
fn partial(&self, x: usize) -> Self {
|
||||||
if let Some(ref f) = self.func {
|
self.func
|
||||||
match f.partial(x) {
|
.as_ref()
|
||||||
Ok(a) => Self::new(a),
|
.map(|f| f.partial(x).map(|a| Self::new(a)).unwrap_or(Self::EMPTY))
|
||||||
Err(_) => Self::EMPTY,
|
.unwrap_or(Self::EMPTY)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Self::EMPTY
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_string(&self) -> &str {
|
fn get_string(&self) -> &str { self.func.as_ref().map(|f| f.unparse()).unwrap_or("") }
|
||||||
if let Some(ref f) = self.func {
|
|
||||||
f.unparse()
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn partial_iter(&self, x: &[usize]) -> Self {
|
fn partial_iter(&self, x: &[usize]) -> Self {
|
||||||
if let Some(ref f) = self.func {
|
self.func
|
||||||
match f.partial_iter(x.iter()) {
|
.as_ref()
|
||||||
Ok(a) => Self::new(a),
|
.map(|f| {
|
||||||
Err(_) => Self::EMPTY,
|
f.partial_iter(x.iter())
|
||||||
}
|
.map(|a| Self::new(a))
|
||||||
} else {
|
.unwrap_or(Self::EMPTY)
|
||||||
Self::EMPTY
|
})
|
||||||
}
|
.unwrap_or(Self::EMPTY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,18 +47,23 @@ impl const Default for FlatExWrapper {
|
|||||||
pub struct BackingFunction {
|
pub struct BackingFunction {
|
||||||
/// f(x)
|
/// f(x)
|
||||||
function: FlatExWrapper,
|
function: FlatExWrapper,
|
||||||
|
|
||||||
/// f'(x)
|
/// f'(x)
|
||||||
derivative_1: FlatExWrapper,
|
derivative_1: FlatExWrapper,
|
||||||
|
|
||||||
/// Mathematical representation of f'(x)
|
/// Mathematical representation of f'(x)
|
||||||
derivative_1_str: String,
|
derivative_1_str: String,
|
||||||
|
|
||||||
/// f''(x)
|
/// f''(x)
|
||||||
derivative_2: FlatExWrapper,
|
derivative_2: FlatExWrapper,
|
||||||
|
|
||||||
|
/// Temporary cache for nth derivative
|
||||||
nth_derivative: Option<(usize, FlatExWrapper, String)>,
|
nth_derivative: Option<(usize, FlatExWrapper, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackingFunction {
|
impl BackingFunction {
|
||||||
const EMPTY: BackingFunction = BackingFunction {
|
/// Empty [`BackingFunction`] instance
|
||||||
|
pub const EMPTY: BackingFunction = BackingFunction {
|
||||||
function: FlatExWrapper::EMPTY,
|
function: FlatExWrapper::EMPTY,
|
||||||
derivative_1: FlatExWrapper::EMPTY,
|
derivative_1: FlatExWrapper::EMPTY,
|
||||||
derivative_1_str: String::new(),
|
derivative_1_str: String::new(),
|
||||||
@ -139,6 +133,7 @@ impl BackingFunction {
|
|||||||
/// Calculate f''(x)
|
/// Calculate f''(x)
|
||||||
pub fn get_derivative_2(&self, x: f64) -> f64 { self.derivative_2.eval(&[x]) }
|
pub fn get_derivative_2(&self, x: f64) -> f64 { self.derivative_2.eval(&[x]) }
|
||||||
|
|
||||||
|
/// Get string relating to the nth derivative
|
||||||
pub fn get_nth_derivative_str(&self) -> &str { &self.nth_derivative.as_ref().unwrap().2 }
|
pub fn get_nth_derivative_str(&self) -> &str { &self.nth_derivative.as_ref().unwrap().2 }
|
||||||
|
|
||||||
pub fn get_nth_derivative(&mut self, n: usize, x: f64) -> f64 {
|
pub fn get_nth_derivative(&mut self, n: usize, x: f64) -> f64 {
|
||||||
@ -168,7 +163,7 @@ impl BackingFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prettyify_function_str(func: &str) -> String {
|
fn prettyify_function_str(func: &str) -> String {
|
||||||
let new_str = func.to_owned().replace("{x}", "x");
|
let new_str = func.replace("{x}", "x");
|
||||||
|
|
||||||
if &new_str == "0/0" {
|
if &new_str == "0/0" {
|
||||||
"Undefined".to_owned()
|
"Undefined".to_owned()
|
||||||
@ -177,10 +172,10 @@ fn prettyify_function_str(func: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const VALID_VARIABLES: [char; 5] = ['x', 'X', 'e', 'E', 'π'];
|
pub const VALID_VARIABLES: [char; 3] = ['x', 'e', 'π'];
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_variable(c: &char) -> bool { VALID_VARIABLES.contains(&c) }
|
pub fn is_variable(c: &char) -> bool { VALID_VARIABLES.contains(&c.to_ascii_lowercase()) }
|
||||||
|
|
||||||
/// Adds asterisks where needed in a function
|
/// Adds asterisks where needed in a function
|
||||||
pub fn process_func_str(function_in: &str) -> String {
|
pub fn process_func_str(function_in: &str) -> String {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ pub fn split_function(input: &str) -> Vec<String> {
|
|||||||
&input
|
&input
|
||||||
.replace("pi", "π") // replace "pi" text with pi symbol
|
.replace("pi", "π") // replace "pi" text with pi symbol
|
||||||
.replace("**", "^") // support alternate manner of expressing exponents
|
.replace("**", "^") // support alternate manner of expressing exponents
|
||||||
.replace("exp", "\u{1fc93}") //stop-gap solution to fix the `exp` function
|
.replace("exp", "\u{1fc93}") // stop-gap solution to fix the `exp` function
|
||||||
.chars()
|
.chars()
|
||||||
.collect::<Vec<char>>(),
|
.collect::<Vec<char>>(),
|
||||||
)
|
)
|
||||||
@ -64,7 +64,7 @@ pub fn split_function_chars(chars: &[char]) -> Vec<String> {
|
|||||||
let isnumber = c.is_ascii_digit();
|
let isnumber = c.is_ascii_digit();
|
||||||
let isvariable = is_variable(c);
|
let isvariable = is_variable(c);
|
||||||
Self {
|
Self {
|
||||||
closing_parens: c == &')',
|
closing_parens: *c == ')',
|
||||||
number: isnumber,
|
number: isnumber,
|
||||||
letter: c.is_ascii_alphabetic(),
|
letter: c.is_ascii_alphabetic(),
|
||||||
variable: isvariable,
|
variable: isvariable,
|
||||||
|
|||||||
@ -30,11 +30,6 @@ 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) }
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
/// Represents a "default" instance of `FunctionEntry`
|
|
||||||
pub static ref DEFAULT_FUNCTION_ENTRY: FunctionEntry = FunctionEntry::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `FunctionEntry` is a function that can calculate values, integrals, derivatives, etc etc
|
/// `FunctionEntry` is a function that can calculate values, integrals, derivatives, etc etc
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct FunctionEntry {
|
pub struct FunctionEntry {
|
||||||
@ -71,11 +66,11 @@ pub struct FunctionEntry {
|
|||||||
pub settings_opened: bool,
|
pub settings_opened: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FunctionEntry {
|
impl const Default for FunctionEntry {
|
||||||
/// Creates default FunctionEntry instance (which is empty)
|
/// Creates default FunctionEntry instance (which is empty)
|
||||||
fn default() -> FunctionEntry {
|
fn default() -> FunctionEntry {
|
||||||
FunctionEntry {
|
FunctionEntry {
|
||||||
function: BackingFunction::new("").unwrap(),
|
function: BackingFunction::EMPTY,
|
||||||
raw_func_str: String::new(),
|
raw_func_str: String::new(),
|
||||||
min_x: -1.0,
|
min_x: -1.0,
|
||||||
max_x: 1.0,
|
max_x: 1.0,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use crate::consts::is_mobile;
|
use crate::consts::is_mobile;
|
||||||
use crate::function_entry::{FunctionEntry, DEFAULT_FUNCTION_ENTRY};
|
use crate::function_entry::FunctionEntry;
|
||||||
use crate::widgets::{move_cursor_to_end, widgets_ontop, Movement};
|
use crate::widgets::{move_cursor_to_end, widgets_ontop, Movement};
|
||||||
use egui::{Button, Key, Modifiers, RichText, WidgetText};
|
use egui::{Button, Key, Modifiers, WidgetText};
|
||||||
use emath::vec2;
|
use emath::vec2;
|
||||||
use parsing::suggestions::Hint;
|
use parsing::suggestions::Hint;
|
||||||
use std::ops::BitXorAssign;
|
use std::ops::BitXorAssign;
|
||||||
@ -14,11 +14,16 @@ pub struct FunctionManager {
|
|||||||
impl Default for FunctionManager {
|
impl Default for FunctionManager {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
functions: vec![(Uuid::new_v4(), DEFAULT_FUNCTION_ENTRY.clone())],
|
functions: vec![(Uuid::new_v4(), FunctionEntry::default())],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Function that creates button that's used with the `button_area`
|
||||||
|
const fn button_area_button(text: impl Into<WidgetText>) -> Button {
|
||||||
|
Button::new(text).frame(false)
|
||||||
|
}
|
||||||
|
|
||||||
impl FunctionManager {
|
impl FunctionManager {
|
||||||
pub fn display_entries(&mut self, ui: &mut egui::Ui) {
|
pub fn display_entries(&mut self, ui: &mut egui::Ui) {
|
||||||
// ui.label("Functions:");
|
// ui.label("Functions:");
|
||||||
@ -127,11 +132,6 @@ impl FunctionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Function that creates button that's used with the `button_area`
|
|
||||||
const fn button_area_button(text: String) -> Button {
|
|
||||||
Button::new_const(WidgetText::RichText(RichText::new_const(text))).frame(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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;
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ impl FunctionManager {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// There's more than 1 function! Functions can now be deleted
|
// There's more than 1 function! Functions can now be deleted
|
||||||
if ui
|
if ui
|
||||||
.add_enabled(can_remove, button_area_button("✖".to_owned()))
|
.add_enabled(can_remove, button_area_button("✖"))
|
||||||
.on_hover_text("Delete Function")
|
.on_hover_text("Delete Function")
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
@ -153,7 +153,7 @@ impl FunctionManager {
|
|||||||
|
|
||||||
// Toggle integral being enabled or not
|
// Toggle integral being enabled or not
|
||||||
function.integral.bitxor_assign(
|
function.integral.bitxor_assign(
|
||||||
ui.add(button_area_button("∫".to_owned()))
|
ui.add(button_area_button("∫"))
|
||||||
.on_hover_text(match function.integral {
|
.on_hover_text(match function.integral {
|
||||||
true => "Don't integrate",
|
true => "Don't integrate",
|
||||||
false => "Integrate",
|
false => "Integrate",
|
||||||
@ -163,7 +163,7 @@ impl FunctionManager {
|
|||||||
|
|
||||||
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
// Toggle showing the derivative (even though it's already calculated this option just toggles if it's displayed or not)
|
||||||
function.derivative.bitxor_assign(
|
function.derivative.bitxor_assign(
|
||||||
ui.add(button_area_button("d/dx".to_owned()))
|
ui.add(button_area_button("d/dx"))
|
||||||
.on_hover_text(match function.derivative {
|
.on_hover_text(match function.derivative {
|
||||||
true => "Don't Differentiate",
|
true => "Don't Differentiate",
|
||||||
false => "Differentiate",
|
false => "Differentiate",
|
||||||
@ -194,7 +194,7 @@ impl FunctionManager {
|
|||||||
|
|
||||||
pub fn new_function(&mut self) {
|
pub fn new_function(&mut self) {
|
||||||
self.functions
|
self.functions
|
||||||
.push((Uuid::new_v4(), DEFAULT_FUNCTION_ENTRY.clone()));
|
.push((Uuid::new_v4(), FunctionEntry::default()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn any_using_integral(&self) -> bool {
|
pub fn any_using_integral(&self) -> bool {
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
#![feature(const_convert)]
|
||||||
|
#![feature(const_default_impls)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
|
|||||||
@ -63,7 +63,7 @@ pub struct AppSettings {
|
|||||||
pub plot_width: usize,
|
pub plot_width: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppSettings {
|
impl const Default for AppSettings {
|
||||||
/// Default implementation of `AppSettings`, this is how the application
|
/// Default implementation of `AppSettings`, this is how the application
|
||||||
/// starts up
|
/// starts up
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -88,7 +88,7 @@ struct Opened {
|
|||||||
pub welcome: bool,
|
pub welcome: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Opened {
|
impl const Default for Opened {
|
||||||
fn default() -> Opened {
|
fn default() -> Opened {
|
||||||
Self {
|
Self {
|
||||||
help: false,
|
help: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user