Merge pull request #249 from simbleau/clippy

Clippy fixes
This commit is contained in:
Spencer C. Imbleau, M.Sc. (he/him) 2023-01-14 11:14:20 -05:00 committed by GitHub
commit c428e650d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 23 additions and 27 deletions

View file

@ -208,5 +208,5 @@ fn size_to_words(byte_size: usize) -> u32 {
}
fn align_up(len: usize, alignment: u32) -> usize {
len + (len.wrapping_neg() & alignment as usize - 1)
len + (len.wrapping_neg() & (alignment as usize - 1))
}

View file

@ -155,7 +155,7 @@ impl Monoid for PathMonoid {
c.pathseg_offset = a & 0xff;
c.path_ix = (tag_word & (PathTag::PATH.0 as u32 * 0x1010101)).count_ones();
c.linewidth_ix = (tag_word & (PathTag::LINEWIDTH.0 as u32 * 0x1010101)).count_ones();
return c;
c
}
/// Monoid combination.
@ -326,10 +326,8 @@ impl<'a> PathEncoder<'a> {
tag.set_subpath_end();
self.tags.push(tag);
self.n_encoded_segments += 1;
} else {
if let Some(tag) = self.tags.last_mut() {
tag.set_subpath_end();
}
} else if let Some(tag) = self.tags.last_mut() {
tag.set_subpath_end();
}
self.state = PathState::Start;
}

View file

@ -140,7 +140,7 @@ impl RampCache {
}
}
fn make_ramp<'a>(stops: &'a [ColorStop]) -> impl Iterator<Item = u32> + 'a {
fn make_ramp(stops: &[ColorStop]) -> impl Iterator<Item = u32> + '_ {
let mut last_u = 0.0;
let mut last_c = ColorF64::from_color(stops[0].color);
let mut this_u = last_u;
@ -165,7 +165,7 @@ fn make_ramp<'a>(stops: &'a [ColorStop]) -> impl Iterator<Item = u32> + 'a {
} else {
last_c.lerp(&this_c, (u - last_u) / du)
};
c.to_premul_u32()
c.as_premul_u32()
})
}
@ -194,11 +194,11 @@ impl ColorF64 {
])
}
fn to_premul_u32(&self) -> u32 {
let a = self.0[3].min(1.0).max(0.0);
let r = ((self.0[0] * a).min(1.0).max(0.0) * 255.0) as u32;
let g = ((self.0[1] * a).min(1.0).max(0.0) * 255.0) as u32;
let b = ((self.0[2] * a).min(1.0).max(0.0) * 255.0) as u32;
fn as_premul_u32(&self) -> u32 {
let a = self.0[3].clamp(0.0, 1.0);
let r = ((self.0[0] * a).clamp(0.0, 1.0) * 255.0) as u32;
let g = ((self.0[1] * a).clamp(0.0, 1.0) * 255.0) as u32;
let b = ((self.0[2] * a).clamp(0.0, 1.0) * 255.0) as u32;
let a = (a * 255.0) as u32;
r | (g << 8) | (b << 16) | (a << 24)
}

View file

@ -200,7 +200,6 @@ impl Engine {
count: None,
}
}
_ => todo!(),
})
.collect::<Vec<_>>();
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
@ -260,7 +259,7 @@ impl Engine {
Command::UploadImage(image_proxy, bytes) => {
let buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
contents: &bytes,
contents: bytes,
usage: wgpu::BufferUsages::COPY_SRC,
});
let texture = device.create_texture(&wgpu::TextureDescriptor {
@ -442,14 +441,14 @@ impl ResourceProxy {
pub fn as_buf(&self) -> Option<&BufProxy> {
match self {
Self::Buf(proxy) => Some(&proxy),
Self::Buf(proxy) => Some(proxy),
_ => None,
}
}
pub fn as_image(&self) -> Option<&ImageProxy> {
match self {
Self::Image(proxy) => Some(&proxy),
Self::Image(proxy) => Some(proxy),
_ => None,
}
}

View file

@ -78,7 +78,7 @@ impl Renderer {
width: u32,
height: u32,
) -> Result<()> {
let (recording, target) = render::render_full(&scene, &self.shaders, width, height);
let (recording, target) = render::render_full(scene, &self.shaders, width, height);
let external_resources = [ExternalResource::Image(
*target.as_image().unwrap(),
texture,

View file

@ -136,7 +136,7 @@ pub fn render_full(
width: u32,
height: u32,
) -> (Recording, ResourceProxy) {
render_encoding_full(&scene.data(), shaders, width, height)
render_encoding_full(scene.data(), shaders, width, height)
}
pub fn render_encoding_full(
@ -149,7 +149,7 @@ pub fn render_encoding_full(
let mut recording = Recording::default();
let mut resources = ResourceCache::new();
let mut packed = PackedEncoding::default();
packed.pack(&encoding, &mut resources);
packed.pack(encoding, &mut resources);
let (ramp_data, ramps_width, ramps_height) = resources.ramps(packed.resources).unwrap();
let gradient_image = if encoding.patches.is_empty() {
ResourceProxy::new_image(1, 1, ImageFormat::Rgba8)
@ -399,5 +399,5 @@ pub fn render_encoding_full(
}
pub fn align_up(len: usize, alignment: u32) -> usize {
len + (len.wrapping_neg() & alignment as usize - 1)
len + (len.wrapping_neg() & (alignment as usize - 1))
}

View file

@ -17,11 +17,10 @@ pub fn get_imports(shader_dir: &Path) -> HashMap<String, String> {
let file_name = entry.file_name();
if let Some(name) = file_name.to_str() {
let suffix = ".wgsl";
if name.ends_with(suffix) {
let import_name = name[..(name.len() - suffix.len())].to_owned();
let contents = fs::read_to_string(imports_dir.join(file_name))
if let Some(import_name) = name.strip_suffix(suffix) {
let contents = fs::read_to_string(imports_dir.join(&file_name))
.expect("Could read shader {import_name} contents");
imports.insert(import_name, contents);
imports.insert(import_name.to_owned(), contents);
}
}
}
@ -94,7 +93,7 @@ pub fn preprocess(input: &str, defines: &HashSet<String>, imports: &HashMap<&str
continue 'all_lines;
}
"endif" => {
if let None = stack.pop() {
if stack.pop().is_none() {
eprintln!("Mismatched endif (line {line_number})");
}
let remainder = directive_start[directive_len..].trim();

View file

@ -91,7 +91,7 @@ impl RenderContext {
if compatible.is_none() {
return self.new_device(compatible_surface).await;
}
return compatible;
compatible
}
/// Creates a compatible device handle id.