Skip to content

use shorthand initialization and remove redundant variables #822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,13 @@ pub fn rgb_to_hsl(color: Color) -> (f32, f32, f32) {
}
}

let mut h: f32;
let s: f32;
let l: f32;

let Color { r, g, b, .. } = color;

let max = max(max(r, g), b);
let min = min(min(r, g), b);

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

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

// it's not gray
if l < 0.5 {
s = delta / (max + min);
let s = if l < 0.5 {
delta / (max + min)
} else {
s = delta / (2.0 - max - min);
}
delta / (2.0 - max - min)
};

// Hue
let r2 = (((max - r) / 6.0) + (delta / 2.0)) / delta;
let g2 = (((max - g) / 6.0) + (delta / 2.0)) / delta;
let b2 = (((max - b) / 6.0) + (delta / 2.0)) / delta;

h = match max {
let mut h = match max {
x if x == r => b2 - g2,
x if x == g => (1.0 / 3.0) + r2 - b2,
_ => (2.0 / 3.0) + g2 - r2,
Expand Down
4 changes: 1 addition & 3 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ pub fn mouse_delta_position() -> Vec2 {
let last_position = context.last_mouse_position.unwrap_or(current_position);

// Calculate the delta
let delta = last_position - current_position;

delta
last_position - current_position
}

/// This is set to true by default, meaning touches will raise mouse events in addition to raising touch events.
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
last_frame_time: f64,
frame_time: f64,

#[cfg(one_screenshot)]

Check warning on line 217 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 217 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-unknown-linux-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 217 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, wasm32-unknown-unknown)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 217 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 217 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition name: `one_screenshot`
counter: usize,

camera_stack: Vec<camera::CameraState>,
Expand Down Expand Up @@ -356,7 +356,7 @@
last_frame_time: miniquad::date::now(),
frame_time: 1. / 60.,

#[cfg(one_screenshot)]

Check warning on line 359 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 359 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-unknown-linux-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 359 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, wasm32-unknown-unknown)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 359 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 359 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition name: `one_screenshot`
counter: 0,
unwind: false,
recovery_future: None,
Expand Down Expand Up @@ -406,7 +406,7 @@

get_quad_context().commit_frame();

#[cfg(one_screenshot)]

Check warning on line 409 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (macos-latest, x86_64-apple-darwin)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 409 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-unknown-linux-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 409 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, wasm32-unknown-unknown)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 409 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (ubuntu-latest, x86_64-pc-windows-gnu)

unexpected `cfg` condition name: `one_screenshot`

Check warning on line 409 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Cross-compile (windows-latest, x86_64-pc-windows-msvc)

unexpected `cfg` condition name: `one_screenshot`
{
get_context().counter += 1;
if get_context().counter == 3 {
Expand Down Expand Up @@ -720,7 +720,7 @@

fn maybe_unwind(unwind: bool, f: impl FnOnce() + Sized + panic::UnwindSafe) -> bool {
if unwind {
panic::catch_unwind(|| f()).is_ok()
panic::catch_unwind(f).is_ok()
} else {
f();
true
Expand Down
4 changes: 2 additions & 2 deletions src/math/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Circle {

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

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

/// Translate `Circle` origin by `offset` vector
Expand Down
10 changes: 5 additions & 5 deletions src/quad_gl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ impl MagicSnapshotter {
..
} = ctx.texture_params(texture);
let color_img = ctx.new_render_texture(TextureParams {
width: width,
height: height,
format: format,
width,
height,
format,
..Default::default()
});

Expand Down Expand Up @@ -597,7 +597,7 @@ impl QuadGl {
draw_calls_count: 0,
start_time: miniquad::date::now(),

white_texture: white_texture,
white_texture,
batch_vertex_buffer: Vec::with_capacity(max_vertices),
batch_index_buffer: Vec::with_capacity(max_indices),
max_vertices,
Expand Down Expand Up @@ -748,7 +748,7 @@ impl QuadGl {
.state
.snapshotter
.screen_texture
.unwrap_or_else(|| white_texture);
.unwrap_or(white_texture);
bindings
.images
.resize(2 + pipeline.textures.len(), white_texture);
Expand Down
6 changes: 3 additions & 3 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ pub fn draw_texture_ex(
let mut x = x;
let mut y = y;
if params.flip_x {
x = x + w;
x += w;
w = -w;
}
if params.flip_y {
y = y + h;
y += h;
h = -h;
}

Expand Down Expand Up @@ -558,7 +558,7 @@ pub fn draw_texture_ex(
];
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];

context.gl.texture(Some(&texture));
context.gl.texture(Some(texture));
context.gl.draw_mode(DrawMode::Triangles);
context.gl.geometry(&vertices, &indices);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/widgets/editbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'a> Editbox<'a> {
*context.input_focus = None;
}

let mut state = context
let state = context
.storage_any
.get_or_default::<EditboxState>(hash!(self.id, "cursor"));

Expand Down Expand Up @@ -350,7 +350,7 @@ impl<'a> Editbox<'a> {
&mut context.input.input_buffer,
&mut *context.clipboard,
&mut text_vec,
&mut state,
state,
);
}
// draw rect in parent window
Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'a> Slider<'a> {
Slider {
id: self.id,
range: self.range,
label: label,
label,
}
}

Expand Down
Loading