Skip to content

Commit

Permalink
small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Sep 6, 2024
1 parent 6488e81 commit 3f50462
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ impl Lolcrab {
#[doc(hidden)]
pub fn get_color(&mut self) -> Color {
if self.linear {
let position =
self.offset + self.x as f32 * self.shift_x + self.y as f32 * self.shift_y;
return self.gradient.repeat_at(position);
let t = self.offset + self.x as f32 * self.shift_x + self.y as f32 * self.shift_y;
return self.gradient.at(modulo(t, 1.0));
}
let position = self.noise.get([
self.x as f64 * self.noise_scale,
Expand Down Expand Up @@ -459,6 +458,11 @@ fn remap(t: f32, a: f32, b: f32, c: f32, d: f32) -> f32 {
(t - a) * ((d - c) / (b - a)) + c
}

#[inline]
fn modulo(x: f32, y: f32) -> f32 {
(x % y + y) % y
}

#[cfg(test)]
mod tests {
use super::Lolcrab;
Expand Down

0 comments on commit 3f50462

Please sign in to comment.