bunch of changes
This commit is contained in:
parent
8191852f17
commit
133998ff63
@ -35,6 +35,7 @@ lazy_static = "1.4.0"
|
|||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
ruzstd = { git = "https://github.com/KillingSpark/zstd-rs.git" }
|
ruzstd = { git = "https://github.com/KillingSpark/zstd-rs.git" }
|
||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
|
tracing = "0.1.32"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
shadow-rs = "0.11.0"
|
shadow-rs = "0.11.0"
|
||||||
@ -51,3 +52,4 @@ wasm-bindgen = { version = "0.2.79", default-features = false, features = [
|
|||||||
"std",
|
"std",
|
||||||
] }
|
] }
|
||||||
web-sys = "0.3.56"
|
web-sys = "0.3.56"
|
||||||
|
tracing-wasm = "0.2.1"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTION_ENTRY};
|
use crate::function::{FunctionEntry, RiemannSum, EMPTY_FUNCTION_ENTRY};
|
||||||
use crate::misc::{debug_log, log_helper, JsonFileOutput, SerdeValueHelper};
|
use crate::misc::{JsonFileOutput, SerdeValueHelper};
|
||||||
use crate::parsing::{process_func_str, test_func};
|
use crate::parsing::{process_func_str, test_func};
|
||||||
|
|
||||||
use const_format::formatc;
|
use const_format::formatc;
|
||||||
@ -91,7 +91,7 @@ lazy_static::lazy_static! {
|
|||||||
static ref ASSETS: Assets = {
|
static ref ASSETS: Assets = {
|
||||||
let start = instant::Instant::now();
|
let start = instant::Instant::now();
|
||||||
|
|
||||||
log_helper("Loading assets...");
|
tracing::info!("Loading assets...");
|
||||||
let mut tar_file_data = Vec::new();
|
let mut tar_file_data = Vec::new();
|
||||||
let _ = ruzstd::StreamingDecoder::new(&mut include_bytes!("../assets.tar.zst").as_slice()).expect("failed to decompress assets").read_to_end(&mut tar_file_data).expect("failed to read assets");
|
let _ = ruzstd::StreamingDecoder::new(&mut include_bytes!("../assets.tar.zst").as_slice()).expect("failed to decompress assets").read_to_end(&mut tar_file_data).expect("failed to read assets");
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ lazy_static::lazy_static! {
|
|||||||
let mut text_data: Option<JsonFileOutput> = None;
|
let mut text_data: Option<JsonFileOutput> = None;
|
||||||
|
|
||||||
|
|
||||||
log_helper("Reading assets...");
|
tracing::info!("Reading assets...");
|
||||||
// Iterate through all entries in the tarball
|
// Iterate through all entries in the tarball
|
||||||
for file in tar_archive.entries().unwrap() {
|
for file in tar_archive.entries().unwrap() {
|
||||||
let mut file = file.unwrap();
|
let mut file = file.unwrap();
|
||||||
@ -115,7 +115,7 @@ lazy_static::lazy_static! {
|
|||||||
let path = file.header().path().unwrap();
|
let path = file.header().path().unwrap();
|
||||||
let path_string = path.to_string_lossy();
|
let path_string = path.to_string_lossy();
|
||||||
|
|
||||||
debug_log(&format!("Loading file: {}", path_string));
|
tracing::debug!("Loading file: {}", path_string);
|
||||||
|
|
||||||
// Match the file extention
|
// Match the file extention
|
||||||
if path_string.ends_with(".ttf") {
|
if path_string.ends_with(".ttf") {
|
||||||
@ -151,7 +151,7 @@ lazy_static::lazy_static! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log_helper(&format!("Done loading assets! Took: {:?}", start.elapsed()));
|
tracing::info!("Done loading assets! Took: {:?}", start.elapsed());
|
||||||
|
|
||||||
let mut font_data: BTreeMap<String, FontData> = BTreeMap::new();
|
let mut font_data: BTreeMap<String, FontData> = BTreeMap::new();
|
||||||
let mut families = BTreeMap::new();
|
let mut families = BTreeMap::new();
|
||||||
@ -340,7 +340,7 @@ impl MathApp {
|
|||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
stop_loading();
|
stop_loading();
|
||||||
|
|
||||||
log_helper("egui app initialized.");
|
tracing::info!("egui app initialized.");
|
||||||
Self::default() // initialize `MathApp`
|
Self::default() // initialize `MathApp`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::function_output::FunctionOutput;
|
use crate::function_output::FunctionOutput;
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use crate::misc::{debug_log, newtons_method, SteppedVector};
|
use crate::misc::{newtons_method, SteppedVector};
|
||||||
|
|
||||||
use crate::egui_app::{DEFAULT_FUNCION, DEFAULT_RIEMANN};
|
use crate::egui_app::{DEFAULT_FUNCION, DEFAULT_RIEMANN};
|
||||||
use crate::parsing::BackingFunction;
|
use crate::parsing::BackingFunction;
|
||||||
|
|||||||
14
src/lib.rs
14
src/lib.rs
@ -9,7 +9,6 @@ mod parsing;
|
|||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
if #[cfg(target_arch = "wasm32")] {
|
||||||
use misc::log_helper;
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
@ -17,16 +16,17 @@ cfg_if::cfg_if! {
|
|||||||
|
|
||||||
#[wasm_bindgen(start)]
|
#[wasm_bindgen(start)]
|
||||||
pub fn start() -> Result<(), wasm_bindgen::JsValue> {
|
pub fn start() -> Result<(), wasm_bindgen::JsValue> {
|
||||||
log_helper("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
|
||||||
log_helper("Initializing panic hooks...");
|
tracing::info!("Initializing panic hooks...");
|
||||||
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
console_error_panic_hook::set_once();
|
||||||
log_helper("Initialized panic hooks!");
|
tracing_wasm::set_as_global_default();
|
||||||
|
tracing::info!("Initialized panic hooks!");
|
||||||
|
|
||||||
log_helper("Finished initializing!");
|
tracing::info!("Finished initializing!");
|
||||||
|
|
||||||
log_helper("Starting App...");
|
tracing::info!("Starting App...");
|
||||||
eframe::start_web("canvas", Box::new(|cc| Box::new(egui_app::MathApp::new(cc))))
|
eframe::start_web("canvas", Box::new(|cc| Box::new(egui_app::MathApp::new(cc))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
src/misc.rs
48
src/misc.rs
@ -1,47 +1,5 @@
|
|||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
// Handles logging based on if the target is wasm (or not) and if
|
|
||||||
// `debug_assertions` is enabled or not
|
|
||||||
cfg_if::cfg_if! {
|
|
||||||
if #[cfg(target_arch = "wasm32")] {
|
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
#[wasm_bindgen]
|
|
||||||
extern "C" {
|
|
||||||
// `console.log(...)`
|
|
||||||
#[wasm_bindgen(js_namespace = console)]
|
|
||||||
fn log(s: &str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used for logging normal messages
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn log_helper(s: &str) {
|
|
||||||
log(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used for debug messages, only does anything if `debug_assertions` is enabled
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
pub fn debug_log(s: &str) {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
log(s);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/// Used for logging normal messages
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn log_helper(s: &str) {
|
|
||||||
println!("{}", s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Used for debug messages, only does anything if `debug_assertions` is enabled
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[allow(unused_variables)]
|
|
||||||
pub fn debug_log(s: &str) {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
println!("{}", s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `SteppedVector` is used in order to efficiently sort through an ordered
|
/// `SteppedVector` is used in order to efficiently sort through an ordered
|
||||||
/// `Vec<f64>` Used in order to speedup the processing of cached data when
|
/// `Vec<f64>` Used in order to speedup the processing of cached data when
|
||||||
/// moving horizontally without zoom in `FunctionEntry`. Before this struct, the
|
/// moving horizontally without zoom in `FunctionEntry`. Before this struct, the
|
||||||
@ -106,7 +64,7 @@ impl From<Vec<f64>> for SteppedVector {
|
|||||||
// length of data
|
// length of data
|
||||||
let data_length = data.len();
|
let data_length = data.len();
|
||||||
// length of data subtracted by 1 (represents the maximum index value)
|
// length of data subtracted by 1 (represents the maximum index value)
|
||||||
let data_i_length = data.len() - 1;
|
let data_i_length = data_length - 1;
|
||||||
|
|
||||||
// Ensure data is of correct length
|
// Ensure data is of correct length
|
||||||
if data_length < 2 {
|
if data_length < 2 {
|
||||||
@ -118,12 +76,14 @@ impl From<Vec<f64>> for SteppedVector {
|
|||||||
|
|
||||||
// if min is bigger than max, sort the input data
|
// if min is bigger than max, sort the input data
|
||||||
if min > max {
|
if min > max {
|
||||||
|
tracing::debug!("SteppedVector: min is larger than max, sorting.");
|
||||||
data.sort_unstable_by(|a, b| b.partial_cmp(a).unwrap());
|
data.sort_unstable_by(|a, b| b.partial_cmp(a).unwrap());
|
||||||
max = data[0];
|
max = data[0];
|
||||||
min = data[data_i_length];
|
min = data[data_i_length];
|
||||||
}
|
}
|
||||||
|
|
||||||
let step = (max - min).abs() / (data_i_length as f64); // Calculate the step between elements
|
// Calculate the step between elements
|
||||||
|
let step = (max - min).abs() / (data_i_length as f64);
|
||||||
|
|
||||||
// Create and return the struct
|
// Create and return the struct
|
||||||
SteppedVector {
|
SteppedVector {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user