cleanup
This commit is contained in:
parent
ad494d633b
commit
76876eefac
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -364,16 +364,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "console_error_panic_hook"
|
|
||||||
version = "0.1.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 1.0.0",
|
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "const_format"
|
name = "const_format"
|
||||||
version = "0.2.23"
|
version = "0.2.23"
|
||||||
@ -672,7 +662,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#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
@ -692,7 +682,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"epaint",
|
"epaint",
|
||||||
@ -703,7 +693,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#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arboard",
|
"arboard",
|
||||||
"egui",
|
"egui",
|
||||||
@ -716,7 +706,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "egui_glow"
|
name = "egui_glow"
|
||||||
version = "0.18.1"
|
version = "0.18.1"
|
||||||
source = "git+https://github.com/Titaniumtown/egui.git#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
@ -736,7 +726,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#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"serde",
|
"serde",
|
||||||
@ -745,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#60ddecba50026cb36679a87cf0fd2595f94e3e93"
|
source = "git+https://github.com/Titaniumtown/egui.git#8e62055679973f91ee58fe91cf6495ad28fae2f7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"ahash",
|
"ahash",
|
||||||
@ -2779,7 +2769,6 @@ dependencies = [
|
|||||||
"bincode",
|
"bincode",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"console_error_panic_hook",
|
|
||||||
"const_format",
|
"const_format",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
|
|||||||
@ -77,10 +77,8 @@ tracing-subscriber = "0.3"
|
|||||||
rayon = { version = "1.5", optional = true }
|
rayon = { version = "1.5", optional = true }
|
||||||
async-lock = { version = "2.5", optional = true }
|
async-lock = { version = "2.5", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
instant = { version = "0.1", features = ["wasm-bindgen"] }
|
||||||
console_error_panic_hook = "0.1"
|
|
||||||
wee_alloc = "0.4"
|
wee_alloc = "0.4"
|
||||||
wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
|
wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
|
||||||
web-sys = "0.3"
|
web-sys = "0.3"
|
||||||
|
|||||||
2
build.sh
2
build.sh
@ -24,7 +24,7 @@ wasm-bindgen target/wasm32-unknown-unknown/${TYPE}/ytbn_graphing_software.wasm -
|
|||||||
|
|
||||||
if test "$TYPE" == "release"; then
|
if test "$TYPE" == "release"; then
|
||||||
echo "running wasm-opt..."
|
echo "running wasm-opt..."
|
||||||
time wasm-opt --converge -Oz --dae --dce --code-folding --const-hoisting --coalesce-locals-learning --vacuum --merge-locals --merge-blocks --fast-math --traps-never-happen --precompute --rse --low-memory-unused --ignore-implicit-traps --traps-never-happen -o pkg/ytbn_graphing_software_bg_2.wasm pkg/ytbn_graphing_software_bg.wasm
|
time wasm-opt --converge -Oz --dae --dce --code-folding --const-hoisting --coalesce-locals-learning --vacuum --merge-locals --merge-blocks --fast-math --precompute --rse --low-memory-unused --traps-never-happen --ignore-implicit-traps -o pkg/ytbn_graphing_software_bg_2.wasm pkg/ytbn_graphing_software_bg.wasm
|
||||||
mv pkg/ytbn_graphing_software_bg_2.wasm pkg/ytbn_graphing_software_bg.wasm
|
mv pkg/ytbn_graphing_software_bg_2.wasm pkg/ytbn_graphing_software_bg.wasm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@ -180,7 +180,7 @@ impl FunctionEntry {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.raw_func_str = raw_func_str.to_string();
|
self.raw_func_str = raw_func_str.to_owned();
|
||||||
let processed_func = process_func_str(raw_func_str);
|
let processed_func = process_func_str(raw_func_str);
|
||||||
let new_func_result = BackingFunction::new(&processed_func);
|
let new_func_result = BackingFunction::new(&processed_func);
|
||||||
|
|
||||||
@ -304,13 +304,8 @@ impl FunctionEntry {
|
|||||||
} else if min_max_changed && !self.back_data.is_empty() {
|
} else if min_max_changed && !self.back_data.is_empty() {
|
||||||
partial_regen = true;
|
partial_regen = true;
|
||||||
|
|
||||||
let x_data: SteppedVector = self
|
let x_data_1: Vec<f64> = self.back_data.iter().map(|ele| ele.x).collect::<Vec<f64>>();
|
||||||
.back_data
|
let x_data: SteppedVector = x_data_1.as_slice().into();
|
||||||
.iter()
|
|
||||||
.map(|ele| ele.x)
|
|
||||||
.collect::<Vec<f64>>()
|
|
||||||
.as_slice()
|
|
||||||
.into();
|
|
||||||
|
|
||||||
let (back_data, derivative_data_1): (Vec<Value>, Vec<Option<Value>>) =
|
let (back_data, derivative_data_1): (Vec<Value>, Vec<Option<Value>>) =
|
||||||
dyn_iter(&resolution_iter)
|
dyn_iter(&resolution_iter)
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(const_convert)]
|
#![feature(const_convert)]
|
||||||
#![feature(const_default_impls)]
|
#![feature(const_default_impls)]
|
||||||
|
#![feature(const_fn_floating_point_arithmetic)]
|
||||||
|
#![feature(const_assume)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate static_assertions;
|
extern crate static_assertions;
|
||||||
@ -39,15 +41,8 @@ cfg_if::cfg_if! {
|
|||||||
#[wasm_bindgen(start)]
|
#[wasm_bindgen(start)]
|
||||||
pub fn start() -> Result<(), wasm_bindgen::JsValue> {
|
pub fn start() -> Result<(), wasm_bindgen::JsValue> {
|
||||||
tracing::info!("Initializing...");
|
tracing::info!("Initializing...");
|
||||||
|
|
||||||
// Used in order to hook into `panic!()` to log in the browser's console
|
// Used in order to hook into `panic!()` to log in the browser's console
|
||||||
tracing::info!("Initializing panic hooks...");
|
|
||||||
console_error_panic_hook::set_once();
|
|
||||||
tracing_wasm::set_as_global_default();
|
tracing_wasm::set_as_global_default();
|
||||||
tracing::info!("Initialized panic hooks!");
|
|
||||||
|
|
||||||
tracing::info!("Finished initializing!");
|
|
||||||
|
|
||||||
tracing::info!("Starting App...");
|
tracing::info!("Starting App...");
|
||||||
eframe::start_web("canvas", Box::new(|cc| Box::new(math_app::MathApp::new(cc))))
|
eframe::start_web("canvas", Box::new(|cc| Box::new(math_app::MathApp::new(cc))))
|
||||||
}
|
}
|
||||||
|
|||||||
66
src/misc.rs
66
src/misc.rs
@ -1,6 +1,6 @@
|
|||||||
use std::intrinsics::assume;
|
use std::intrinsics::assume;
|
||||||
|
|
||||||
use eframe::egui::plot::{Line, Points, Value as EguiValue, Values};
|
use eframe::egui::plot::{Line, Points, Value, Values};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
#[cfg(threading)]
|
#[cfg(threading)]
|
||||||
@ -75,9 +75,9 @@ impl<'a> FunctionHelper<'a> {
|
|||||||
/// moving horizontally without zoom in `FunctionEntry`. Before this struct, the
|
/// moving horizontally without zoom in `FunctionEntry`. Before this struct, the
|
||||||
/// index was calculated with `.iter().position(....` which was horribly
|
/// index was calculated with `.iter().position(....` which was horribly
|
||||||
/// inefficient
|
/// inefficient
|
||||||
pub struct SteppedVector {
|
pub struct SteppedVector<'a> {
|
||||||
/// Actual data being referenced. HAS to be sorted from minimum to maximum
|
/// Actual data being referenced. HAS to be sorted from minimum to maximum
|
||||||
data: Vec<f64>,
|
data: &'a [f64],
|
||||||
|
|
||||||
/// Minimum value
|
/// Minimum value
|
||||||
min: f64,
|
min: f64,
|
||||||
@ -89,7 +89,7 @@ pub struct SteppedVector {
|
|||||||
step: f64,
|
step: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SteppedVector {
|
impl<'a> SteppedVector<'a> {
|
||||||
/// Returns `Option<usize>` with index of element with value `x`. and `None` if `x` does not exist in `data`
|
/// Returns `Option<usize>` with index of element with value `x`. and `None` if `x` does not exist in `data`
|
||||||
pub fn get_index(&self, x: &f64) -> Option<usize> {
|
pub fn get_index(&self, x: &f64) -> Option<usize> {
|
||||||
// If `x` is outside range, just go ahead and return `None` as it *shouldn't* be in `data`
|
// If `x` is outside range, just go ahead and return `None` as it *shouldn't* be in `data`
|
||||||
@ -125,16 +125,14 @@ impl SteppedVector {
|
|||||||
pub const fn get_max(&self) -> f64 { self.max }
|
pub const fn get_max(&self) -> f64 { self.max }
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn get_data(&self) -> &Vec<f64> { &self.data }
|
pub fn get_data(&self) -> &'a [f64] { &self.data }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert `&[f64]` into [`SteppedVector`]
|
// Convert `&[f64]` into [`SteppedVector`]
|
||||||
impl From<&[f64]> for SteppedVector {
|
impl<'a> From<&'a [f64]> for SteppedVector<'a> {
|
||||||
fn from(data: &[f64]) -> SteppedVector {
|
fn from(data: &'a [f64]) -> SteppedVector {
|
||||||
// Ensure data is of correct length
|
// Ensure data is of correct length
|
||||||
if data.len() < 2 {
|
debug_assert!(data.len() > 2);
|
||||||
panic!("SteppedVector: data should have a length longer than 2");
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
assume(data.len() > 2);
|
assume(data.len() > 2);
|
||||||
@ -145,22 +143,14 @@ impl From<&[f64]> for SteppedVector {
|
|||||||
let max: f64 = data[data.len() - 1]; // The max value should be the first element
|
let max: f64 = data[data.len() - 1]; // The max value should be the first element
|
||||||
let min: f64 = data[0]; // The minimum value should be the last element
|
let min: f64 = data[0]; // The minimum value should be the last element
|
||||||
|
|
||||||
if min > max {
|
debug_assert!(max > min);
|
||||||
panic!("SteppedVector: min is larger than max");
|
|
||||||
/*
|
|
||||||
tracing::debug!("SteppedVector: min is larger than max, sorting.");
|
|
||||||
data.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap());
|
|
||||||
max = data[data_i_length];
|
|
||||||
min = data[0];
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the step between elements
|
// Calculate the step between elements
|
||||||
let step = (max - min).abs() / (data.len() as f64);
|
let step = (max - min).abs() / (data.len() as f64);
|
||||||
|
|
||||||
// Create and return the struct
|
// Create and return the struct
|
||||||
SteppedVector {
|
SteppedVector {
|
||||||
data: data.to_vec(),
|
data,
|
||||||
min,
|
min,
|
||||||
max,
|
max,
|
||||||
step,
|
step,
|
||||||
@ -180,7 +170,7 @@ pub trait EguiHelper {
|
|||||||
fn to_tuple(&self) -> Vec<(f64, f64)>;
|
fn to_tuple(&self) -> Vec<(f64, f64)>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EguiHelper for Vec<EguiValue> {
|
impl EguiHelper for Vec<Value> {
|
||||||
fn to_line(&self) -> Line { Line::new(Values::from_values(self.clone())) }
|
fn to_line(&self) -> Line { Line::new(Values::from_values(self.clone())) }
|
||||||
|
|
||||||
fn to_points(&self) -> Points { Points::new(Values::from_values(self.clone())) }
|
fn to_points(&self) -> Points { Points::new(Values::from_values(self.clone())) }
|
||||||
@ -203,9 +193,16 @@ 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: &[EguiValue], f: &dyn Fn(f64) -> f64,
|
threshold: &f64, range: &std::ops::Range<f64>, data: &[Value], f: &dyn Fn(f64) -> f64,
|
||||||
f_1: &dyn Fn(f64) -> f64,
|
f_1: &dyn Fn(f64) -> f64,
|
||||||
) -> Vec<f64> {
|
) -> Vec<f64> {
|
||||||
|
debug_assert!(!data.is_empty());
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
assume(!data.is_empty());
|
||||||
|
assume(data.len() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
data.iter()
|
data.iter()
|
||||||
.tuple_windows()
|
.tuple_windows()
|
||||||
.filter(|(prev, curr)| !prev.y.is_nan() && !curr.y.is_nan())
|
.filter(|(prev, curr)| !prev.y.is_nan() && !curr.y.is_nan())
|
||||||
@ -254,6 +251,13 @@ pub fn option_vec_printer<T: ToString>(data: &[Option<T>]) -> String
|
|||||||
where
|
where
|
||||||
T: ToString,
|
T: ToString,
|
||||||
{
|
{
|
||||||
|
debug_assert!(!data.is_empty());
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
assume(!data.is_empty());
|
||||||
|
assume(data.len() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
let max_i: i32 = (data.len() as i32) - 1;
|
let max_i: i32 = (data.len() as i32) - 1;
|
||||||
[
|
[
|
||||||
"[",
|
"[",
|
||||||
@ -302,13 +306,15 @@ pub fn hashed_storage_create(hash: &[u8], data: &[u8]) -> String {
|
|||||||
assume(data.len() > 0);
|
assume(data.len() > 0);
|
||||||
assume(!data.is_empty());
|
assume(!data.is_empty());
|
||||||
assume(hash.len() == HASH_LENGTH);
|
assume(hash.len() == HASH_LENGTH);
|
||||||
|
assume(!hash.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_data = [hash, data].concat();
|
|
||||||
debug_assert_eq!(new_data.len(), data.len() + hash.len());
|
|
||||||
|
|
||||||
// cannot use `from_utf8` seems to break on wasm. no clue why
|
// cannot use `from_utf8` seems to break on wasm. no clue why
|
||||||
new_data.iter().map(|b| *b as char).collect::<String>()
|
[hash, data]
|
||||||
|
.concat()
|
||||||
|
.iter()
|
||||||
|
.map(|b| *b as char)
|
||||||
|
.collect::<String>()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -326,6 +332,14 @@ pub fn hashed_storage_read(data: String) -> (String, Vec<u8>) {
|
|||||||
debug_assert_eq!(hash.len(), HASH_LENGTH);
|
debug_assert_eq!(hash.len(), HASH_LENGTH);
|
||||||
debug_assert!(cached_data.len() > 0);
|
debug_assert!(cached_data.len() > 0);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
assume(!cached_data.is_empty());
|
||||||
|
assume(cached_data.len() > 0);
|
||||||
|
|
||||||
|
assume(!hash.is_empty());
|
||||||
|
assume(hash.len() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
hash.iter().map(|c| *c as char).collect::<String>(),
|
hash.iter().map(|c| *c as char).collect::<String>(),
|
||||||
cached_data.to_vec(),
|
cached_data.to_vec(),
|
||||||
|
|||||||
@ -115,7 +115,8 @@ fn format_bytes() {
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use ytbn_graphing_software::format_bytes;
|
use ytbn_graphing_software::format_bytes;
|
||||||
|
|
||||||
let values: HashMap<usize, &str> = HashMap::from([(1000, "1000 B"), (10000, "10.00 KB")]);
|
let values: HashMap<usize, &str> =
|
||||||
|
HashMap::from([(1000, "1000 B"), (10000, "10.00 KB"), (1100000, "1.10 MB")]);
|
||||||
|
|
||||||
for (key, value) in values {
|
for (key, value) in values {
|
||||||
assert_eq!(format_bytes(key), value);
|
assert_eq!(format_bytes(key), value);
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
|
<meta name="theme-color" media="(prefers-color-scheme: light)" content="white">
|
||||||
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
|
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#404040">
|
||||||
|
|
||||||
<link rel="manifest" href="/manifest.json">
|
<link rel="manifest" href="/manifest.json">
|
||||||
|
|
||||||
<!--Register Service Worker-->
|
<!--Register Service Worker-->
|
||||||
<script>
|
<script>
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user