diff --git a/nexrad-browser/src/command.rs b/nexrad-browser/src/command.rs index aab9e80..bf8d8c5 100644 --- a/nexrad-browser/src/command.rs +++ b/nexrad-browser/src/command.rs @@ -4,7 +4,7 @@ use crate::rendering::scope::ScopeState; pub fn should_newline(state: &mut ScopeState) -> bool { - state.command_buf.starts_with("MODE SET") || state.command_buf.starts_with("ELEVATION SET") + state.command_buf.starts_with("MODE SET") || state.command_buf.starts_with("ELEVATION SET") || state.command_buf.starts_with("FCS SET") } pub fn exec(state: &mut ScopeState, command: String) { @@ -15,6 +15,26 @@ pub fn exec(state: &mut ScopeState, command: String) { state.command_buf = "SYSTEM PROCESSING".to_string(); state.command_buf_response_mode = true; loadar2("file"); + } else if command == "FCS" { + state.command_buf = state.prefs.fcs.to_string(); + state.command_buf_response_mode = true; + return; + } else if command.starts_with("FCS SET") { + if tokens.len() < 3 { + state.command_buf = "ARGUMENT INVALID".to_string(); + state.command_buf_response_mode = true; + return; + } + let new_val: f32 = match tokens[2].parse() { + Ok(v) => v, + Err(_) => { + state.command_buf = "ARGUMENT INVALID".to_string(); + state.command_buf_response_mode = true; + return; + } + }; + state.prefs.fcs = new_val; + return; } else if command.starts_with("MODE SET") { if tokens.len() < 3 { state.command_buf = "ARGUMENT INVALID".to_string(); diff --git a/nexrad-browser/src/rendering/scope.rs b/nexrad-browser/src/rendering/scope.rs index fe2494f..44c0f27 100644 --- a/nexrad-browser/src/rendering/scope.rs +++ b/nexrad-browser/src/rendering/scope.rs @@ -267,53 +267,20 @@ impl ScopeState { // ACTUAL DATA RENDERING if let Some(ar2) = &self.ar2 { - let px_per_km = 1.0 / 50.0; - let xc = 0.0; - let yc = 0.0; + let px_per_km = 1.0 / (250.0 * 2.0); let radials = ar2.elevations.get(&self.selected_elevation).unwrap(); - let first_gate_px = (radials[0] - .available_data - .get("REF") - .expect("reflectivity is missing!") - .gdm - .data_moment_range) as f32 - / 1000.0 - * px_per_km; - let gate_interval_km = (radials[0] - .available_data - .get("REF") - .expect("reflectivity is missing!") - .gdm - .data_moment_range_sample_interval) as f32 - / 1000.0; - let gate_width_px = gate_interval_km * px_per_km; - for radial in radials { - /* weird rounding stolen from go-nexrad */ - let mut azimuth_angle = (radial.header.azimuth_angle as f64) - 90.0; - if azimuth_angle < 0.0 { - azimuth_angle = 360.0 + azimuth_angle; - } + let distance_firstgate_km = (radial.available_data.get(self.scope_mode.rname()).expect("selected mode is missing!").gdm.data_moment_range as f64) / 1000.0; + let distance_gatespacing_km = (radials[0].available_data.get(self.scope_mode.rname()).expect("selected mode is missing!").gdm.data_moment_range_sample_interval as f64) / 1000.0; - let mut azimuth = azimuth_angle.floor(); + let mut azimuth = radial.header.azimuth_angle as f64; let azimuth_spacing = match radial.header.azimuth_resolution_spacing { 1 => 0.5, _ => 1.0, }; - if (azimuth_angle + azimuth_spacing).floor() > azimuth { - azimuth += azimuth_spacing; - } - /* conclude the weird rounding stolen from go-nexrad */ - - // Angles specified clockwise in radians - let start_angle = azimuth * (PI / 180.0); - let end_angle = azimuth_spacing * (PI / 180.0); - - let mut distance_x = first_gate_px; - let mut distance_y = first_gate_px; // line width // line cap @@ -328,10 +295,16 @@ impl ScopeState { for (num, value) in gates.iter().enumerate() { if *value != MOMENT_DATA_BELOW_THRESHOLD { - let x0 = 1.0 / (start_angle.cos() * distance_x as f64); - let y0 = 1.0 / (start_angle.sin() * distance_y as f64); - let x1 = 1.0 / (distance_x as f64); - let y1 = 1.0 / (distance_y as f64); + let distance_gate_km = distance_firstgate_km + (distance_gatespacing_km * num as f64); + let az = azimuth * (PI / 180.0); + let bz = (azimuth + azimuth_spacing) * (PI / 180.0); + + let d_gateend = distance_gate_km + distance_gatespacing_km; + + let a = [(distance_gate_km * az.cos()) as f32 * px_per_km, (distance_gate_km * az.sin()) as f32 * px_per_km, 0.0]; + let b = [(distance_gate_km * bz.cos()) as f32 * px_per_km, (distance_gate_km * bz.sin()) as f32 * px_per_km, 0.0]; + let c = [(d_gateend * az.cos()) as f32 * px_per_km, (d_gateend * az.sin()) as f32 * px_per_km, 0.0]; + let d = [(d_gateend * bz.cos()) as f32 * px_per_km, (d_gateend * bz.sin()) as f32 * px_per_km, 0.0]; // C--D // | | @@ -343,10 +316,10 @@ impl ScopeState { */ - let vertex_a = Vertex { position: [x0 as f32, y0 as f32, 0.0], color: color_scheme(self.scope_mode, *value) }; - let vertex_b = Vertex { position: [x1 as f32, y0 as f32, 0.0], color: color_scheme(self.scope_mode, *value) }; - let vertex_c = Vertex { position: [x0 as f32, y1 as f32, 0.0], color: color_scheme(self.scope_mode, *value) }; - let vertex_d = Vertex { position: [x1 as f32, y1 as f32, 0.0], color: color_scheme(self.scope_mode, *value) }; + let vertex_a = Vertex { position: a, color: color_scheme(self.scope_mode, *value) }; + let vertex_b = Vertex { position: b, color: color_scheme(self.scope_mode, *value) }; + let vertex_c = Vertex { position: c, color: color_scheme(self.scope_mode, *value) }; + let vertex_d = Vertex { position: d, color: color_scheme(self.scope_mode, *value) }; let vindex_a = verticies.len(); verticies.push(vertex_a); @@ -412,9 +385,6 @@ impl ScopeState { */ } - distance_x += gate_width_px; - distance_y += gate_width_px; - azimuth += azimuth_spacing; } }