From aad169f761a5817355d4b32c678cef6b8ce6b419 Mon Sep 17 00:00:00 2001 From: Gavin-Niederman Date: Mon, 20 Nov 2023 14:17:01 -0800 Subject: [PATCH] fix: Line now always includes points at start and end --- shark-visualizer-interface/src/lib.rs | 2 +- shark-visualizer/src/shader_compiler.rs | 4 +++- shark-visualizer/src/visualization.rs | 7 ++----- shark/src/point/mod.rs | 2 +- shark/src/point/primitives.rs | 8 ++++++-- shark/src/shader/mod.rs | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/shark-visualizer-interface/src/lib.rs b/shark-visualizer-interface/src/lib.rs index cc2164e..ad52600 100644 --- a/shark-visualizer-interface/src/lib.rs +++ b/shark-visualizer-interface/src/lib.rs @@ -1,8 +1,8 @@ use palette::{IntoColor, LinSrgb}; use shark::point::Point; -use shark::shader::{Fragment, Shader}; #[cfg(target_arch = "wasm32")] use shark::shader::FragThree; +use shark::shader::{Fragment, Shader}; #[repr(C)] #[derive(Clone)] diff --git a/shark-visualizer/src/shader_compiler.rs b/shark-visualizer/src/shader_compiler.rs index 8b8d5b6..4027ba4 100644 --- a/shark-visualizer/src/shader_compiler.rs +++ b/shark-visualizer/src/shader_compiler.rs @@ -11,7 +11,9 @@ use shark::shader::{FragThree, Fragment}; use shark_visualizer_interface::VisualizationExports; use crate::{ - ui::ErrorMessageEvent, user_config::{UserConfigState, RespawnLedsEvent}, visualization::VisualizationState, + ui::ErrorMessageEvent, + user_config::{RespawnLedsEvent, UserConfigState}, + visualization::VisualizationState, }; #[derive(Event)] diff --git a/shark-visualizer/src/visualization.rs b/shark-visualizer/src/visualization.rs index 67630df..5cc044f 100644 --- a/shark-visualizer/src/visualization.rs +++ b/shark-visualizer/src/visualization.rs @@ -3,9 +3,7 @@ pub use bevy::{prelude::*, window::CursorGrabMode}; use shark::shader::{FragThree, Shader}; use crate::{ - shader_compiler::VisualizationExportsWrapper, - user_config::RespawnLedsEvent, - PlayBackState, + shader_compiler::VisualizationExportsWrapper, user_config::RespawnLedsEvent, PlayBackState, }; pub struct VisualizationPlugin; @@ -84,8 +82,7 @@ fn respawn_leds( for entity in leds.iter() { commands.entity(entity).despawn(); } - - + info!("Spawning LEDs"); let led_root = root.single(); for led in state.exports.as_ref().unwrap().points() { diff --git a/shark/src/point/mod.rs b/shark/src/point/mod.rs index fc138b9..7b048b9 100644 --- a/shark/src/point/mod.rs +++ b/shark/src/point/mod.rs @@ -83,4 +83,4 @@ pub mod tests { let points: Vec = points.collect(); } -} \ No newline at end of file +} diff --git a/shark/src/point/primitives.rs b/shark/src/point/primitives.rs index d8a11ac..27b4142 100644 --- a/shark/src/point/primitives.rs +++ b/shark/src/point/primitives.rs @@ -21,8 +21,12 @@ impl Iterator for Line { type Item = Point; fn next(&mut self) -> Option { + if self.num_points == 0 { + return None; + } + if self.current_point < self.num_points { - let t = self.current_point as f64 / self.num_points as f64; + let t = self.current_point as f64 / (self.num_points - 1) as f64; self.current_point += 1; Some((1.0 - t) * self.a + t * self.b) } else { @@ -33,4 +37,4 @@ impl Iterator for Line { pub fn line(a: Point, b: Point, num_points: usize) -> Line { Line::new(a, b, num_points) -} \ No newline at end of file +} diff --git a/shark/src/shader/mod.rs b/shark/src/shader/mod.rs index f66c7ce..a908d46 100644 --- a/shark/src/shader/mod.rs +++ b/shark/src/shader/mod.rs @@ -2,11 +2,11 @@ pub mod primitives; use core::slice; +use palette::{IntoColor, LinSrgb}; use primitives::{ checkerboard, extrude, mix, mod_position, mod_time, rotate_hue, Checkerboard, Extrude, Interpolate, ModPosition, ModTime, RotateHue, }; -use palette::{IntoColor, LinSrgb}; pub trait Shader { type Output: IntoColor>;