Skip to content

Commit 44cad5d

Browse files
cyrganinot-fl3
authored andcommitted
use shorthand initialization and remove redundant variables
1 parent 2e48cf9 commit 44cad5d

File tree

8 files changed

+21
-27
lines changed

8 files changed

+21
-27
lines changed

src/color.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,13 @@ pub fn rgb_to_hsl(color: Color) -> (f32, f32, f32) {
221221
}
222222
}
223223

224-
let mut h: f32;
225-
let s: f32;
226-
let l: f32;
227-
228224
let Color { r, g, b, .. } = color;
229225

230226
let max = max(max(r, g), b);
231227
let min = min(min(r, g), b);
232228

233229
// Luminosity is the average of the max and min rgb color intensities.
234-
l = (max + min) / 2.0;
230+
let l = (max + min) / 2.0;
235231

236232
// Saturation
237233
let delta: f32 = max - min;
@@ -241,18 +237,18 @@ pub fn rgb_to_hsl(color: Color) -> (f32, f32, f32) {
241237
}
242238

243239
// it's not gray
244-
if l < 0.5 {
245-
s = delta / (max + min);
240+
let s = if l < 0.5 {
241+
delta / (max + min)
246242
} else {
247-
s = delta / (2.0 - max - min);
248-
}
243+
delta / (2.0 - max - min)
244+
};
249245

250246
// Hue
251247
let r2 = (((max - r) / 6.0) + (delta / 2.0)) / delta;
252248
let g2 = (((max - g) / 6.0) + (delta / 2.0)) / delta;
253249
let b2 = (((max - b) / 6.0) + (delta / 2.0)) / delta;
254250

255-
h = match max {
251+
let mut h = match max {
256252
x if x == r => b2 - g2,
257253
x if x == g => (1.0 / 3.0) + r2 - b2,
258254
_ => (2.0 / 3.0) + g2 - r2,

src/input.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ pub fn mouse_delta_position() -> Vec2 {
7272
let last_position = context.last_mouse_position.unwrap_or(current_position);
7373

7474
// Calculate the delta
75-
let delta = last_position - current_position;
76-
77-
delta
75+
last_position - current_position
7876
}
7977

8078
/// This is set to true by default, meaning touches will raise mouse events in addition to raising touch events.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl EventHandler for Stage {
720720

721721
fn maybe_unwind(unwind: bool, f: impl FnOnce() + Sized + panic::UnwindSafe) -> bool {
722722
if unwind {
723-
panic::catch_unwind(|| f()).is_ok()
723+
panic::catch_unwind(f).is_ok()
724724
} else {
725725
f();
726726
true

src/math/circle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Circle {
3333

3434
/// Checks whether the `Circle` contains a `Point`
3535
pub fn contains(&self, pos: &Vec2) -> bool {
36-
return pos.distance(vec2(self.x, self.y)) < self.r;
36+
pos.distance(vec2(self.x, self.y)) < self.r
3737
}
3838

3939
/// Checks whether the `Circle` overlaps a `Circle`
@@ -54,7 +54,7 @@ impl Circle {
5454
let lhs = dist_x - rect.w / 2.0;
5555
let rhs = dist_y - rect.h / 2.0;
5656
let dist_sq = (lhs * lhs) + (rhs * rhs);
57-
return dist_sq <= self.r * self.r;
57+
dist_sq <= self.r * self.r
5858
}
5959

6060
/// Translate `Circle` origin by `offset` vector

src/quad_gl.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ impl MagicSnapshotter {
206206
..
207207
} = ctx.texture_params(texture);
208208
let color_img = ctx.new_render_texture(TextureParams {
209-
width: width,
210-
height: height,
211-
format: format,
209+
width,
210+
height,
211+
format,
212212
..Default::default()
213213
});
214214

@@ -597,7 +597,7 @@ impl QuadGl {
597597
draw_calls_count: 0,
598598
start_time: miniquad::date::now(),
599599

600-
white_texture: white_texture,
600+
white_texture,
601601
batch_vertex_buffer: Vec::with_capacity(max_vertices),
602602
batch_index_buffer: Vec::with_capacity(max_indices),
603603
max_vertices,
@@ -748,7 +748,7 @@ impl QuadGl {
748748
.state
749749
.snapshotter
750750
.screen_texture
751-
.unwrap_or_else(|| white_texture);
751+
.unwrap_or(white_texture);
752752
bindings
753753
.images
754754
.resize(2 + pipeline.textures.len(), white_texture);

src/texture.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,11 @@ pub fn draw_texture_ex(
514514
let mut x = x;
515515
let mut y = y;
516516
if params.flip_x {
517-
x = x + w;
517+
x += w;
518518
w = -w;
519519
}
520520
if params.flip_y {
521-
y = y + h;
521+
y += h;
522522
h = -h;
523523
}
524524

@@ -558,7 +558,7 @@ pub fn draw_texture_ex(
558558
];
559559
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
560560

561-
context.gl.texture(Some(&texture));
561+
context.gl.texture(Some(texture));
562562
context.gl.draw_mode(DrawMode::Triangles);
563563
context.gl.geometry(&vertices, &indices);
564564
}

src/ui/widgets/editbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a> Editbox<'a> {
305305
*context.input_focus = None;
306306
}
307307

308-
let mut state = context
308+
let state = context
309309
.storage_any
310310
.get_or_default::<EditboxState>(hash!(self.id, "cursor"));
311311

@@ -350,7 +350,7 @@ impl<'a> Editbox<'a> {
350350
&mut context.input.input_buffer,
351351
&mut *context.clipboard,
352352
&mut text_vec,
353-
&mut state,
353+
state,
354354
);
355355
}
356356
// draw rect in parent window

src/ui/widgets/slider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a> Slider<'a> {
2424
Slider {
2525
id: self.id,
2626
range: self.range,
27-
label: label,
27+
label,
2828
}
2929
}
3030

0 commit comments

Comments
 (0)