Skip to content

Commit

Permalink
applied clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
DavJCosby committed Feb 9, 2024
1 parent de0635f commit 9c87cc7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/driver/buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ impl BufferContainer {
}

fn deref_option<T: Copy>(option: Option<&T>) -> Option<T> {
match option {
Some(v) => Some(*v),
None => None,
}
option.map(|v| *v)
}

impl std::ops::Index<&str> for BufferContainer {
Expand Down
2 changes: 1 addition & 1 deletion src/sled/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Sled {
let num_leds = leds.len();
let index_of_closest = leds
.iter()
.min_by(|l, r| l.distance().partial_cmp(&&r.distance()).unwrap())
.min_by(|l, r| l.distance().partial_cmp(&r.distance()).unwrap())
.unwrap()
.index() as usize;

Expand Down
20 changes: 10 additions & 10 deletions src/sled/positional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Sled {
}

pub fn get_closest(&self) -> &Led {
&self.leds[self.index_of_closest as usize]
&self.leds[self.index_of_closest]
}

pub fn get_closest_to(&self, pos: Vec2) -> &Led {
Expand All @@ -42,7 +42,7 @@ impl Sled {
}

pub fn modulate_closest<F: Fn(&Led) -> Rgb>(&mut self, color_rule: F) {
let led = &mut self.leds[self.index_of_closest as usize];
let led = &mut self.leds[self.index_of_closest];
led.color = color_rule(led);
}

Expand All @@ -53,7 +53,7 @@ impl Sled {
}

pub fn set_closest(&mut self, color: Rgb) {
self.leds[self.index_of_closest as usize].color = color;
self.leds[self.index_of_closest].color = color;
}

pub fn set_closest_to(&mut self, pos: Vec2, color: Rgb) {
Expand All @@ -68,37 +68,37 @@ impl Sled {
.vertex_indices
.iter()
.map(|i| {
let vertex_pos = self.leds[*i as usize].position();
let vertex_pos = self.leds[*i].position();
(*i, pos.distance_squared(vertex_pos))
})
.max_by(|a, b| a.1.partial_cmp(&b.1).unwrap())
.unwrap();

index_of_furthest as usize
index_of_furthest
}

pub fn get_furthest(&self) -> &Led {
&self.leds[self.index_of_furthest as usize]
&self.leds[self.index_of_furthest]
}

pub fn get_furthest_from(&self, pos: Vec2) -> &Led {
let index_of_furthest = self.get_index_of_furthest_from(pos);
&self.leds[index_of_furthest as usize]
&self.leds[index_of_furthest]
}

pub fn modulate_furthest<F: Fn(&Led) -> Rgb>(&mut self, color_rule: F) {
let led = &mut self.leds[self.index_of_furthest as usize];
let led = &mut self.leds[self.index_of_furthest];
led.color = color_rule(led);
}

pub fn modulate_furthest_from<F: Fn(&Led) -> Rgb>(&mut self, pos: Vec2, color_rule: F) {
let index_of_furthest = self.get_index_of_furthest_from(pos);
let led = &mut self.leds[index_of_furthest as usize];
let led = &mut self.leds[index_of_furthest];
led.color = color_rule(led);
}

pub fn set_furthest(&mut self, color: Rgb) {
self.leds[self.index_of_furthest as usize].color = color;
self.leds[self.index_of_furthest].color = color;
}

pub fn set_furthest_from(&mut self, pos: Vec2, color: Rgb) {
Expand Down
2 changes: 1 addition & 1 deletion src/sled/segmental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Sled {
.as_err();
}

self.leds[self.vertex_indices[vertex_index] as usize].color = color;
self.leds[self.vertex_indices[vertex_index]].color = color;
Ok(())
}

Expand Down

0 comments on commit 9c87cc7

Please sign in to comment.