From 61df1e725c5383b4bba5dd51eaa7ab5aa8022bb6 Mon Sep 17 00:00:00 2001 From: core Date: Sat, 31 May 2025 11:15:36 -0400 Subject: [PATCH] csr rendering v2 --- .idea/workspace.xml | 38 +++++++++++++++++++++++++++++--------- Cargo.lock | 18 ++++++++++++++++++ client/package.json | 3 ++- client/src/lib/Map.svelte | 23 +++++++++++------------ crates/pal/Cargo.toml | 13 ++++++++++++- crates/pal/src/lib.rs | 2 ++ crates/pal/src/wasm.rs | 7 +++++++ 7 files changed, 81 insertions(+), 23 deletions(-) create mode 100644 crates/pal/src/wasm.rs diff --git a/.idea/workspace.xml b/.idea/workspace.xml index aa75ef4..6b74e62 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -8,16 +8,13 @@ - - + + - - - - - + + - + + diff --git a/Cargo.lock b/Cargo.lock index cf10be2..75f86b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1759,6 +1759,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bb71e1b3fa6ca1c61f383464aaf2bb0e2f8e772a1f01d486832464de363b951" dependencies = [ "num-traits", + "rand 0.8.5", + "serde", ] [[package]] @@ -2103,6 +2105,7 @@ dependencies = [ "libc", "rand_chacha 0.3.1", "rand_core 0.6.4", + "serde", ] [[package]] @@ -2143,6 +2146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.15", + "serde", ] [[package]] @@ -2505,6 +2509,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_derive" version = "1.0.219" @@ -3717,7 +3732,10 @@ name = "wxbox-pal" version = "0.1.0" dependencies = [ "ordered-float 4.6.0", + "serde", + "serde-wasm-bindgen", "thiserror 1.0.69", + "wasm-bindgen", ] [[package]] diff --git a/client/package.json b/client/package.json index 8a03fd6..6f1f43e 100644 --- a/client/package.json +++ b/client/package.json @@ -12,7 +12,8 @@ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "format": "prettier --write .", "lint": "prettier --check . && eslint .", - "protobuf:update": "protoc --ts_out src/lib/generated_interop --proto_path ../crates/interchange/src/ ../crates/interchange/src/*.proto" + "update:protobuf": "protoc --ts_out src/lib/generated_interop --proto_path ../crates/interchange/src/ ../crates/interchange/src/*.proto", + "update:wxbox-pal": "cd ../crates/pal && wasm-pack build --target web --features wasm && rm -rf ../../client/src/lib/map/pal && mv pkg ../../client/src/lib/map/pal" }, "devDependencies": { "@eslint/compat": "^1.2.5", diff --git a/client/src/lib/Map.svelte b/client/src/lib/Map.svelte index 074646f..99f2666 100644 --- a/client/src/lib/Map.svelte +++ b/client/src/lib/Map.svelte @@ -214,7 +214,7 @@ if (radial.product && radial.product.data && radial.product.data.data) { const angle_a = radial.azimuthAngleDegrees; - const angle_b = angle_a + 2*radial.azimuthSpacingDegrees; + const angle_b = angle_a + radial.azimuthSpacingDegrees * 1.2; const start_range = radial.product.data.startRange; // m const sample_interval = radial.product.data.sampleInterval; // m @@ -222,17 +222,16 @@ const range = sample_interval * number_of_samples + start_range; // m // add an extra sample for good measure const padded_range = range + sample_interval; // m - // calculate the two points - const [pointALat, pointALong] = forwardGeodesic(degToRad(angle_a), degToRad(lat), degToRad(long), padded_range); - const pointA = maplibregl.MercatorCoordinate.fromLngLat({ - lng: radToDeg(pointALong), - lat: radToDeg(pointALat) - }); - const [pointBLat, pointBLong] = forwardGeodesic(degToRad(angle_b), degToRad(lat), degToRad(long), padded_range); - const pointB = maplibregl.MercatorCoordinate.fromLngLat({ - lng: radToDeg(pointBLong), - lat: radToDeg(pointBLat) - }); + + const in_weird_mercator_units = padded_range / radarCoordinate.meterInMercatorCoordinateUnits(); + const pointAX = radarCoordinate.x + in_weird_mercator_units * Math.sin(degToRad(-angle_a + 180)); + const pointAY = radarCoordinate.y + in_weird_mercator_units * Math.cos(degToRad(-angle_a + 180)); + const pointA = new maplibregl.MercatorCoordinate(pointAX, pointAY, 0); + + const pointBX = radarCoordinate.x + in_weird_mercator_units * Math.sin(degToRad(-angle_b + 180)); + const pointBY = radarCoordinate.y + in_weird_mercator_units * Math.cos(degToRad(-angle_b + 180)); + const pointB = new maplibregl.MercatorCoordinate(pointBX, pointBY, 0); + vertexData.push(radarCoordinate.x); vertexData.push(radarCoordinate.y); vertexData.push(pointA.x); diff --git a/crates/pal/Cargo.toml b/crates/pal/Cargo.toml index 2947c56..32cbc37 100644 --- a/crates/pal/Cargo.toml +++ b/crates/pal/Cargo.toml @@ -3,6 +3,17 @@ name = "wxbox-pal" version = "0.1.0" edition = "2021" +[lib] +crate-type = ["rlib", "cdylib"] + [dependencies] thiserror = "1" -ordered-float = "4" \ No newline at end of file +ordered-float = "4" + +wasm-bindgen = { version = "0.2", optional = true } +serde = { version = "1", features = ["derive"], optional = true } +serde-wasm-bindgen = { version = "0.6", optional = true } + +[features] +default = [] +wasm = ["dep:wasm-bindgen", "dep:serde", "dep:serde-wasm-bindgen", "ordered-float/serde"] \ No newline at end of file diff --git a/crates/pal/src/lib.rs b/crates/pal/src/lib.rs index de3ed4d..8cef220 100644 --- a/crates/pal/src/lib.rs +++ b/crates/pal/src/lib.rs @@ -1,9 +1,11 @@ pub mod default_palettes; pub mod parser; +mod wasm; pub use ordered_float::OrderedFloat; #[derive(Copy, Clone, Debug, PartialEq)] +#[cfg_attr(feature = "wasm", derive(::serde::Serialize))] pub struct Color { pub red: u8, pub green: u8, diff --git a/crates/pal/src/wasm.rs b/crates/pal/src/wasm.rs new file mode 100644 index 0000000..491b331 --- /dev/null +++ b/crates/pal/src/wasm.rs @@ -0,0 +1,7 @@ +use wasm_bindgen::prelude::*; +use crate::parser::parse; + +#[wasm_bindgen] +pub fn parse_palette(pal_str: &str) -> JsValue { + serde_wasm_bindgen::to_value(&parse(pal_str).ok()).unwrap() +} \ No newline at end of file