clippy fixes

This commit is contained in:
Spencer C. Imbleau 2023-01-14 11:07:07 -05:00
parent eec111c633
commit 4fc94a1d4b
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 { 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.pathseg_offset = a & 0xff;
c.path_ix = (tag_word & (PathTag::PATH.0 as u32 * 0x1010101)).count_ones(); 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(); c.linewidth_ix = (tag_word & (PathTag::LINEWIDTH.0 as u32 * 0x1010101)).count_ones();
return c; c
} }
/// Monoid combination. /// Monoid combination.
@ -326,11 +326,9 @@ impl<'a> PathEncoder<'a> {
tag.set_subpath_end(); tag.set_subpath_end();
self.tags.push(tag); self.tags.push(tag);
self.n_encoded_segments += 1; self.n_encoded_segments += 1;
} else { } else if let Some(tag) = self.tags.last_mut() {
if let Some(tag) = self.tags.last_mut() {
tag.set_subpath_end(); tag.set_subpath_end();
} }
}
self.state = PathState::Start; 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_u = 0.0;
let mut last_c = ColorF64::from_color(stops[0].color); let mut last_c = ColorF64::from_color(stops[0].color);
let mut this_u = last_u; let mut this_u = last_u;
@ -165,7 +165,7 @@ fn make_ramp<'a>(stops: &'a [ColorStop]) -> impl Iterator<Item = u32> + 'a {
} else { } else {
last_c.lerp(&this_c, (u - last_u) / du) 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 { fn as_premul_u32(&self) -> u32 {
let a = self.0[3].min(1.0).max(0.0); let a = self.0[3].clamp(0.0, 1.0);
let r = ((self.0[0] * a).min(1.0).max(0.0) * 255.0) as u32; let r = ((self.0[0] * a).clamp(0.0, 1.0) * 255.0) as u32;
let g = ((self.0[1] * a).min(1.0).max(0.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).min(1.0).max(0.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; let a = (a * 255.0) as u32;
r | (g << 8) | (b << 16) | (a << 24) r | (g << 8) | (b << 16) | (a << 24)
} }

View file

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

View file

@ -78,7 +78,7 @@ impl Renderer {
width: u32, width: u32,
height: u32, height: u32,
) -> Result<()> { ) -> 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( let external_resources = [ExternalResource::Image(
*target.as_image().unwrap(), *target.as_image().unwrap(),
texture, texture,

View file

@ -136,7 +136,7 @@ pub fn render_full(
width: u32, width: u32,
height: u32, height: u32,
) -> (Recording, ResourceProxy) { ) -> (Recording, ResourceProxy) {
render_encoding_full(&scene.data(), shaders, width, height) render_encoding_full(scene.data(), shaders, width, height)
} }
pub fn render_encoding_full( pub fn render_encoding_full(
@ -149,7 +149,7 @@ pub fn render_encoding_full(
let mut recording = Recording::default(); let mut recording = Recording::default();
let mut resources = ResourceCache::new(); let mut resources = ResourceCache::new();
let mut packed = PackedEncoding::default(); 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 (ramp_data, ramps_width, ramps_height) = resources.ramps(packed.resources).unwrap();
let gradient_image = if encoding.patches.is_empty() { let gradient_image = if encoding.patches.is_empty() {
ResourceProxy::new_image(1, 1, ImageFormat::Rgba8) 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 { 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(); let file_name = entry.file_name();
if let Some(name) = file_name.to_str() { if let Some(name) = file_name.to_str() {
let suffix = ".wgsl"; let suffix = ".wgsl";
if name.ends_with(suffix) { if let Some(import_name) = name.strip_suffix(suffix) {
let import_name = name[..(name.len() - suffix.len())].to_owned(); let contents = fs::read_to_string(imports_dir.join(&file_name))
let contents = fs::read_to_string(imports_dir.join(file_name))
.expect("Could read shader {import_name} contents"); .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; continue 'all_lines;
} }
"endif" => { "endif" => {
if let None = stack.pop() { if stack.pop().is_none() {
eprintln!("Mismatched endif (line {line_number})"); eprintln!("Mismatched endif (line {line_number})");
} }
let remainder = directive_start[directive_len..].trim(); let remainder = directive_start[directive_len..].trim();

View file

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