Compare commits

..

No commits in common. "d592c746549d7436e20fe53a7f1be5f6d745565c" and "d641610fbfec5b35fcf6b508b09aae61805590d8" have entirely different histories.

7 changed files with 92 additions and 91 deletions

51
Cargo.lock generated
View File

@ -136,12 +136,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]] [[package]]
name = "bincode" name = "bincode"
version = "1.3.3" version = "1.3.3"
@ -1220,9 +1214,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.81" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@ -2916,9 +2910,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.104" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@ -2927,25 +2921,11 @@ dependencies = [
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.54" version = "0.4.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@ -2956,9 +2936,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.104" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -2966,22 +2946,22 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.104" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [ dependencies = [
"bumpalo",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.104" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -3110,9 +3090,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.81" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -3700,7 +3680,6 @@ dependencies = [
name = "ytbn_graphing_software" name = "ytbn_graphing_software"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"base64",
"bincode", "bincode",
"cfg-if", "cfg-if",
"const_format", "const_format",

View File

@ -57,7 +57,6 @@ static_assertions = "1.1"
bincode = "1.3" bincode = "1.3"
serde = "1" serde = "1"
log = "0.4" log = "0.4"
base64 = "0.22"
# Note: benchmarks are in a separate crate - run with: # Note: benchmarks are in a separate crate - run with:
# cd benchmarks && cargo bench # cd benchmarks && cargo bench
@ -90,8 +89,7 @@ wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
web-sys = "0.3" web-sys = "0.3"
tracing-wasm = "0.2" tracing-wasm = "0.2"
getrandom = { version = "0.3", features = ["wasm_js"] } getrandom = { version = "0.3", features = ["wasm_js"] }
# pinned to 0.4.54 because nix provides up to 0.2.104 wasm-bindgen-cli wasm-bindgen-futures = "0.4"
wasm-bindgen-futures = "=0.4.54"
[package.metadata.cargo-all-features] [package.metadata.cargo-all-features]
skip_optional_dependencies = true #don't test optional dependencies, only features skip_optional_dependencies = true #don't test optional dependencies, only features

8
flake.lock generated
View File

@ -65,17 +65,17 @@
"simon-egui": { "simon-egui": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1764740756, "lastModified": 1764730109,
"narHash": "sha256-CX0v82hDmLSEx5uFViWvfJaeADFJKR0G+MJYFFQcxng=", "narHash": "sha256-vNETC0oq6tKJKF8KOGQKKIWRom38m0RwGgi3MPBrRx8=",
"owner": "Titaniumtown", "owner": "Titaniumtown",
"repo": "egui", "repo": "egui",
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369", "rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "Titaniumtown", "owner": "Titaniumtown",
"repo": "egui", "repo": "egui",
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369", "rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
"type": "github" "type": "github"
} }
}, },

View File

@ -9,21 +9,13 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
simon-egui = { simon-egui = {
url = "github:Titaniumtown/egui/217d3f250c499ae88c02930b26cacb945c4a2369"; url = "github:Titaniumtown/egui/b63c21d70150f1b414370f0f9a8af56e886662f4";
flake = false; flake = false;
}; };
}; };
outputs = outputs = { self, nixpkgs, flake-utils, rust-overlay, simon-egui }:
{ flake-utils.lib.eachDefaultSystem (system:
self,
nixpkgs,
flake-utils,
rust-overlay,
simon-egui,
}:
flake-utils.lib.eachDefaultSystem (
system:
let let
overlays = [ (import rust-overlay) ]; overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { pkgs = import nixpkgs {
@ -31,7 +23,7 @@
}; };
# Use nightly rust with wasm32 target # Use nightly rust with wasm32 target
rustToolchain = pkgs.rust-bin.stable.latest.default.override { rustToolchain = pkgs.rust-bin.nightly."2025-05-01".default.override {
targets = [ "wasm32-unknown-unknown" ]; targets = [ "wasm32-unknown-unknown" ];
}; };
@ -40,6 +32,28 @@
rustc = rustToolchain; rustc = rustToolchain;
}; };
# Build wasm-bindgen-cli matching the version in Cargo.lock (0.2.106)
wasm-bindgen-cli = rustPlatform.buildRustPackage rec {
pname = "wasm-bindgen-cli";
version = "0.2.106";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-M6WuGl7EruNopHZbqBpucu4RWz44/MSdv6f0zkYw+44=";
};
cargoHash = "sha256-ElDatyOwdKwHg3bNH/1pcxKI7LXkhsotlDPQjiLHBwA=";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.curl
pkgs.darwin.apple_sdk.frameworks.Security
];
# Tests require network access
doCheck = false;
};
# Create a combined source with the main project and dependencies # Create a combined source with the main project and dependencies
combinedSrc = pkgs.stdenv.mkDerivation { combinedSrc = pkgs.stdenv.mkDerivation {
name = "ytbn-combined-src"; name = "ytbn-combined-src";
@ -111,9 +125,9 @@
src = ./.; src = ./.;
nativeBuildInputs = with pkgs; [ nativeBuildInputs = [
wasm-bindgen-cli wasm-bindgen-cli
binaryen pkgs.binaryen
]; ];
buildPhase = '' buildPhase = ''
@ -197,17 +211,14 @@
zstd zstd
]; ];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath ( LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [
with pkgs; libxkbcommon
[ libGL
libxkbcommon wayland
libGL xorg.libX11
wayland xorg.libXcursor
xorg.libX11 xorg.libXi
xorg.libXcursor ]);
xorg.libXi
]
);
}; };
} }
); );

View File

@ -1,5 +1,8 @@
use crate::{ use crate::{
consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop, consts::COLORS,
function_entry::FunctionEntry,
misc::{create_id, get_u64_id, random_u64},
widgets::widgets_ontop,
}; };
use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText}; use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText};
use emath::vec2; use emath::vec2;
@ -19,7 +22,7 @@ impl Default for FunctionManager {
fn default() -> Self { fn default() -> Self {
let mut vec: Functions = Vec::with_capacity(COLORS.len()); let mut vec: Functions = Vec::with_capacity(COLORS.len());
vec.push(( vec.push((
Id::NULL.with(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64() create_id(11414819524356497634), // Random number here to avoid call to crate::misc::random_u64()
FunctionEntry::default(), FunctionEntry::default(),
)); ));
Self { functions: vec } Self { functions: vec }
@ -37,8 +40,8 @@ impl Serialize for FunctionManager {
&self &self
.functions .functions
.iter() .iter()
.map(|(id, func)| (*id, func.clone())) .map(|(id, func)| (get_u64_id(*id), func.clone()))
.collect::<Vec<(Id, FunctionEntry)>>(), .collect::<Vec<(u64, FunctionEntry)>>(),
)?; )?;
s.end() s.end()
} }
@ -50,12 +53,17 @@ impl<'de> Deserialize<'de> for FunctionManager {
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
#[derive(Deserialize)] #[derive(Deserialize)]
struct Helper(Vec<(Id, FunctionEntry)>); struct Helper(Vec<(u64, FunctionEntry)>);
let helper = Helper::deserialize(deserializer)?; let helper = Helper::deserialize(deserializer)?;
Ok(FunctionManager { Ok(FunctionManager {
functions: helper.0.to_vec(), functions: helper
.0
.iter()
.cloned()
.map(|(id, func)| (create_id(id), func))
.collect::<Vec<(Id, FunctionEntry)>>(),
}) })
} }
} }
@ -196,7 +204,7 @@ impl FunctionManager {
const BUTTONS_Y_OFFSET: f32 = 1.32; const BUTTONS_Y_OFFSET: f32 = 1.32;
const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET; const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET;
widgets_ontop(ui, Id::NULL.with(i), &re, Y_OFFSET, |ui| { widgets_ontop(ui, create_id(i as u64), &re, Y_OFFSET, |ui| {
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
@ -319,7 +327,7 @@ impl FunctionManager {
/// Create and push new empty function entry /// Create and push new empty function entry
pub fn push_empty(&mut self) { pub fn push_empty(&mut self) {
self.functions.push(( self.functions.push((
Id::NULL.with(random_u64().expect("unable to generate random id")), create_id(random_u64().expect("unable to generate random id")),
FunctionEntry::default(), FunctionEntry::default(),
)); ));
} }
@ -329,7 +337,7 @@ impl FunctionManager {
// Reset settings_opened so the cloned function doesn't have settings open // Reset settings_opened so the cloned function doesn't have settings open
entry.settings_opened = false; entry.settings_opened = false;
self.functions.push(( self.functions.push((
Id::NULL.with(random_u64().expect("unable to generate random id")), create_id(random_u64().expect("unable to generate random id")),
entry, entry,
)); ));
} }

View File

@ -176,7 +176,6 @@ impl MathApp {
// TODO: stabilize FunctionManager serialize so it can persist across builds // TODO: stabilize FunctionManager serialize so it can persist across builds
let (commit, func_data) = crate::misc::hashed_storage_read(&data)?; let (commit, func_data) = crate::misc::hashed_storage_read(&data)?;
let func_data: &[u8] = &func_data;
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } { if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {

View File

@ -1,3 +1,4 @@
use egui::Id;
use egui_plot::{Line, PlotPoint, PlotPoints, Points}; use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2; use emath::Pos2;
use itertools::Itertools; use itertools::Itertools;
@ -61,6 +62,14 @@ impl Offset for Pos2 {
} }
} }
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) }
}
/* /*
/// Rounds f64 to `n` decimal places /// Rounds f64 to `n` decimal places
pub fn decimal_round(x: f64, n: usize) -> f64 { pub fn decimal_round(x: f64, n: usize) -> f64 {
@ -170,27 +179,24 @@ pub type HashBytes = [u8; HASH_LENGTH];
#[allow(dead_code)] #[allow(dead_code)]
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String { pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
// Use base64 encoding to safely store binary data in localStorage unsafe { std::mem::transmute::<Vec<u8>, String>([hashbytes.to_vec(), data.to_vec()].concat()) }
let combined: Vec<u8> = [hashbytes.to_vec(), data.to_vec()].concat();
base64::encode(combined)
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, Vec<u8>)> { pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, &[u8])> {
// Decode base64 data
let decoded = base64::decode(data).ok()?;
// Make sure data is long enough to decode // Make sure data is long enough to decode
if HASH_LENGTH >= decoded.len() { if HASH_LENGTH >= data.len() {
return None; return None;
} }
// Extract hash and data // Transmute data into slice
let mut hash: HashBytes = [0u8; HASH_LENGTH]; let decoded_1: &[u8] = unsafe { std::mem::transmute::<&str, &[u8]>(data) };
hash.copy_from_slice(&decoded[..HASH_LENGTH]);
let data_part = decoded[HASH_LENGTH..].to_vec();
Some((hash, data_part)) // Return hash and decoded data
Some((
unsafe { *(decoded_1[..HASH_LENGTH].as_ptr() as *const HashBytes) },
&decoded_1[HASH_LENGTH..],
))
} }
/// Creates and returns random u64 /// Creates and returns random u64