Skip to content

Commit

Permalink
fix: Line now always includes points at start and end
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin-Niederman committed Nov 20, 2023
1 parent 1c2951a commit aad169f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion shark-visualizer-interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion shark-visualizer/src/shader_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 2 additions & 5 deletions shark-visualizer/src/visualization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion shark/src/point/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ pub mod tests {

let points: Vec<Point> = points.collect();
}
}
}
8 changes: 6 additions & 2 deletions shark/src/point/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ impl Iterator for Line {
type Item = Point;

fn next(&mut self) -> Option<Self::Item> {
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 {
Expand All @@ -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)
}
}
2 changes: 1 addition & 1 deletion shark/src/shader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<F: Fragment> {
type Output: IntoColor<LinSrgb<f64>>;
Expand Down

0 comments on commit aad169f

Please sign in to comment.