diff --git a/src/encoding/packed.rs b/src/encoding/packed.rs index 7004477..e96ec3a 100644 --- a/src/encoding/packed.rs +++ b/src/encoding/packed.rs @@ -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)) } diff --git a/src/encoding/path.rs b/src/encoding/path.rs index 7d91072..760eb32 100644 --- a/src/encoding/path.rs +++ b/src/encoding/path.rs @@ -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; } diff --git a/src/encoding/resource.rs b/src/encoding/resource.rs index c980d7b..139c6a8 100644 --- a/src/encoding/resource.rs +++ b/src/encoding/resource.rs @@ -140,7 +140,7 @@ impl RampCache { } } -fn make_ramp<'a>(stops: &'a [ColorStop]) -> impl Iterator + 'a { +fn make_ramp(stops: &[ColorStop]) -> impl Iterator + '_ { 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 + '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) } diff --git a/src/engine.rs b/src/engine.rs index a823339..0c4963f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -200,7 +200,6 @@ impl Engine { count: None, } } - _ => todo!(), }) .collect::>(); 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, } } diff --git a/src/lib.rs b/src/lib.rs index dd967ec..585ec09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, diff --git a/src/render.rs b/src/render.rs index 4ae51bd..ab08a0c 100644 --- a/src/render.rs +++ b/src/render.rs @@ -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)) } diff --git a/src/shaders/preprocess.rs b/src/shaders/preprocess.rs index 7bdb32a..2981622 100644 --- a/src/shaders/preprocess.rs +++ b/src/shaders/preprocess.rs @@ -17,11 +17,10 @@ pub fn get_imports(shader_dir: &Path) -> HashMap { 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, 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(); diff --git a/src/util.rs b/src/util.rs index 07750f4..89b1c52 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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.