Fix clippy lints (#1327)

* Fix clippy lints

* Update formatting

* Remove unsafe send impls

* New type for Rc<NodeContainer>
This commit is contained in:
0HyperCube 2023-07-19 16:38:23 +01:00 committed by Keavon Chambers
parent 743803ce04
commit 80cc5bee73
80 changed files with 549 additions and 445 deletions

View file

@ -26,7 +26,7 @@ dyn-any = { path = "../../libraries/dyn-any", features = [
"glam",
], optional = true, default-features = false }
spirv-std = { version = "0.7", optional = true }
spirv-std = { version = "0.8", optional = true }
bytemuck = { version = "1.8", features = ["derive"] }
async-trait = { version = "0.1", optional = true }
serde = { version = "1.0", features = [
@ -40,16 +40,16 @@ kurbo = { git = "https://github.com/linebender/kurbo.git", features = [
"serde",
], optional = true }
spin = "0.9.2"
glam = { version = "^0.22", default-features = false, features = [
glam = { version = "0.24", default-features = false, features = [
"scalar-math",
] }
node-macro = { path = "../node-macro" }
base64 = { version = "0.13", optional = true }
base64 = { version = "0.21", optional = true }
specta.workspace = true
specta.optional = true
once_cell = { version = "1.17.0", default-features = false, optional = true }
rustybuzz = { version = "0.6.0", optional = true }
rustybuzz = { version = "0.8.0", optional = true }
num-derive = { version = "0.3.3" }
num-traits = { version = "0.2.15", default-features = false, features = [

View file

@ -8,7 +8,6 @@ use dyn_any::StaticType;
use dyn_any::StaticTypeSized;
use glam::DAffine2;
use core::any::Any;
use core::future::Future;
use core::hash::{Hash, Hasher};
use core::pin::Pin;
@ -88,6 +87,8 @@ impl<'a, Surface> Drop for SurfaceHandle<'a, Surface> {
}
}*/
pub type ResourceFuture = Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>>>>;
pub trait ApplicationIo {
type Surface;
type Executor;
@ -96,7 +97,7 @@ pub trait ApplicationIo {
fn gpu_executor(&self) -> Option<&Self::Executor> {
None
}
fn load_resource<'a>(&self, url: impl AsRef<str>) -> Result<Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>>>>, ApplicationError>;
fn load_resource(&self, url: impl AsRef<str>) -> Result<ResourceFuture, ApplicationError>;
}
impl<T: ApplicationIo> ApplicationIo for &T {
@ -115,7 +116,7 @@ impl<T: ApplicationIo> ApplicationIo for &T {
(**self).gpu_executor()
}
fn load_resource<'a>(&self, url: impl AsRef<str>) -> Result<Pin<Box<dyn Future<Output = Result<Arc<[u8]>, ApplicationError>>>>, ApplicationError> {
fn load_resource<'a>(&self, url: impl AsRef<str>) -> Result<ResourceFuture, ApplicationError> {
(**self).load_resource(url)
}
}

View file

@ -3,7 +3,6 @@ use crate::Node;
use bytemuck::{Pod, Zeroable};
use dyn_any::{DynAny, StaticType};
use num_traits::CheckedShr;
#[cfg(target_arch = "spirv")]
use spirv_std::num_traits::Float;
@ -85,9 +84,8 @@ fn quantize(value: f32, offset: u32, quantization: Quantization) -> u32 {
let rounded_value = scaled_value.clamp(0., (1 << bits) as f32 - 1.) as u32;
// Shift the quantized value to the appropriate position based on the offset
let shifted_value = rounded_value.checked_shl(32 - bits - offset).unwrap();
shifted_value as u32
rounded_value.checked_shl(32 - bits - offset).unwrap()
}
/*
#[inline(always)]
@ -113,9 +111,8 @@ fn decode(value: u32, offset: u32, quantization: Quantization) -> f32 {
let unpacked_value = shifted_value & ((1 << bits) - 1); // Mask out the unnecessary bits
let normalized_value = unpacked_value as f32 / ((1 << bits) - 1) as f32; // Normalize the value based on the quantization range
let decoded_value = normalized_value - b;
let original_value = decoded_value / a;
original_value
decoded_value / a
}
pub struct QuantizeNode<Quantization> {
@ -174,7 +171,7 @@ mod test {
let color = Color::from_rgbaf32_unchecked(0.5, 0.5, 0.5, 0.5);
let quantized = quantize_color(color, [quant; 4]);
assert_eq!(quantized.0, 0x7f7f7f7f);
let dequantized = dequantize_color(quantized, [quant; 4]);
let _dequantized = dequantize_color(quantized, [quant; 4]);
//assert_eq!(color, dequantized);
}

View file

@ -233,9 +233,9 @@ fn levels_node(color: Color, input_start: f32, input_mid: f32, input_end: f32, o
let color = color.to_gamma_srgb();
// Input Range (Range: 0-1)
let input_shadows = (input_start / 100.) as f32;
let input_midtones = (input_mid / 100.) as f32;
let input_highlights = (input_end / 100.) as f32;
let input_shadows = input_start / 100.;
let input_midtones = input_mid / 100.;
let input_highlights = input_end / 100.;
// Output Range (Range: 0-1)
let output_minimums = output_start / 100.;
@ -289,12 +289,12 @@ pub struct GrayscaleNode<Tint, Reds, Yellows, Greens, Cyans, Blues, Magentas> {
fn grayscale_color_node(color: Color, tint: Color, reds: f32, yellows: f32, greens: f32, cyans: f32, blues: f32, magentas: f32) -> Color {
let color = color.to_gamma_srgb();
let reds = reds as f32 / 100.;
let yellows = yellows as f32 / 100.;
let greens = greens as f32 / 100.;
let cyans = cyans as f32 / 100.;
let blues = blues as f32 / 100.;
let magentas = magentas as f32 / 100.;
let reds = reds / 100.;
let yellows = yellows / 100.;
let greens = greens / 100.;
let cyans = cyans / 100.;
let blues = blues / 100.;
let magentas = magentas / 100.;
let gray_base = color.r().min(color.g()).min(color.b());
@ -406,7 +406,7 @@ pub struct BlendNode<BlendMode, Opacity> {
#[node_macro::node_fn(BlendNode)]
fn blend_node(input: (Color, Color), blend_mode: BlendMode, opacity: f32) -> Color {
blend_colors(input.0, input.1, blend_mode, opacity as f32 / 100.)
blend_colors(input.0, input.1, blend_mode, opacity / 100.)
}
#[inline(always)]
@ -575,15 +575,15 @@ fn channel_mixer_node(
let (r, g, b, a) = color.components();
let color = if monochrome {
let (monochrome_r, monochrome_g, monochrome_b, monochrome_c) = (monochrome_r as f32 / 100., monochrome_g as f32 / 100., monochrome_b as f32 / 100., monochrome_c as f32 / 100.);
let (monochrome_r, monochrome_g, monochrome_b, monochrome_c) = (monochrome_r / 100., monochrome_g / 100., monochrome_b / 100., monochrome_c / 100.);
let gray = (r * monochrome_r + g * monochrome_g + b * monochrome_b + monochrome_c).clamp(0., 1.);
Color::from_rgbaf32_unchecked(gray, gray, gray, a)
} else {
let (red_r, red_g, red_b, red_c) = (red_r as f32 / 100., red_g as f32 / 100., red_b as f32 / 100., red_c as f32 / 100.);
let (green_r, green_g, green_b, green_c) = (green_r as f32 / 100., green_g as f32 / 100., green_b as f32 / 100., green_c as f32 / 100.);
let (blue_r, blue_g, blue_b, blue_c) = (blue_r as f32 / 100., blue_g as f32 / 100., blue_b as f32 / 100., blue_c as f32 / 100.);
let (red_r, red_g, red_b, red_c) = (red_r / 100., red_g / 100., red_b / 100., red_c / 100.);
let (green_r, green_g, green_b, green_c) = (green_r / 100., green_g / 100., green_b / 100., green_c / 100.);
let (blue_r, blue_g, blue_b, blue_c) = (blue_r / 100., blue_g / 100., blue_b / 100., blue_c / 100.);
let red = (r * red_r + g * red_g + b * red_b + red_c).clamp(0., 1.);
let green = (r * green_r + g * green_g + b * green_b + green_c).clamp(0., 1.);
@ -779,7 +779,7 @@ fn selective_color_node(
return acc;
}
let (c, m, y, k) = (c as f32 / 100., m as f32 / 100., y as f32 / 100., k as f32 / 100.);
let (c, m, y, k) = (c / 100., m / 100., y / 100., k / 100.);
let color_parameter_group_scale_factor = match color_parameter_group {
SelectiveColorChoice::Reds | SelectiveColorChoice::Greens | SelectiveColorChoice::Blues => color_parameter_group_scale_factor_rgb,
@ -808,7 +808,7 @@ pub struct OpacityNode<O> {
#[node_macro::node_fn(OpacityNode)]
fn image_opacity(color: Color, opacity_multiplier: f32) -> Color {
let opacity_multiplier = opacity_multiplier as f32 / 100.;
let opacity_multiplier = opacity_multiplier / 100.;
Color::from_rgbaf32_unchecked(color.r(), color.g(), color.b(), color.a() * opacity_multiplier)
}
@ -823,7 +823,7 @@ pub struct PosterizeNode<P> {
fn posterize(color: Color, posterize_value: f32) -> Color {
let color = color.to_gamma_srgb();
let posterize_value = posterize_value as f32;
let posterize_value = posterize_value;
let number_of_areas = posterize_value.recip();
let size_of_areas = (posterize_value - 1.).recip();
let channel = |channel: f32| (channel / number_of_areas).floor() * size_of_areas;
@ -844,11 +844,11 @@ pub struct ExposureNode<Exposure, Offset, GammaCorrection> {
fn exposure(color: Color, exposure: f32, offset: f32, gamma_correction: f32) -> Color {
let adjusted = color
// Exposure
.map_rgb(|c: f32| c * 2_f32.powf(exposure as f32))
.map_rgb(|c: f32| c * 2_f32.powf(exposure))
// Offset
.map_rgb(|c: f32| c + offset as f32)
.map_rgb(|c: f32| c + offset)
// Gamma correction
.gamma(gamma_correction as f32);
.gamma(gamma_correction);
adjusted.map_rgb(|c: f32| c.clamp(0., 1.))
}

View file

@ -256,15 +256,15 @@ mod tests {
assert_eq!(brightness_contrast_legacy_map(-150., 100.), [0; 256]);
assert_eq!(brightness_contrast_legacy_map(-77., 100.), {
let mut x = [0; 153].into_iter().chain([2, 20, 65, 143].into_iter()).chain([255; 99].into_iter());
let mut x = [0; 153].into_iter().chain([2, 20, 65, 143]).chain([255; 99]);
core::array::from_fn(|_| x.next().unwrap())
});
assert_eq!(brightness_contrast_legacy_map(0., 100.), {
let mut x = [0; 54].into_iter().chain([13, 107].into_iter()).chain([255; 200].into_iter());
let mut x = [0; 54].into_iter().chain([13, 107]).chain([255; 200]);
core::array::from_fn(|_| x.next().unwrap())
});
assert_eq!(brightness_contrast_legacy_map(53., 100.), {
let mut x = [0; 18].into_iter().chain([132].into_iter()).chain([255; 237].into_iter());
let mut x = [0; 18].into_iter().chain([132]).chain([255; 237]);
core::array::from_fn(|_| x.next().unwrap())
});
assert_eq!(brightness_contrast_legacy_map(150., 100.), [255; 256]);
@ -279,13 +279,13 @@ mod tests {
assert_eq!(brightness_contrast_legacy_map(0., 0.), core::array::from_fn(|i| i as u8));
assert_eq!(
brightness_contrast_legacy_map(53., 0.),
string_data("9,14,18,21,24,27,29,32,34,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,66,68,70,72,73,75,77,79,80,82,84,85,87,89,90,92,94,95,97,99,100,102,104,105,107,108,110,111,113,115,116,118,119,121,122,124,126,127,129,130,132,133,135,136,138,139,141,142,144,145,147,148,150,151,153,154,156,157,159,160,161,163,164,166,167,169,170,172,173,175,176,177,179,180,182,183,185,186,187,189,190,192,193,195,196,197,199,200,202,203,204,206,207,209,210,211,213,214,216,217,218,220,221,223,224,225,227,228,230,231,232,234,235,236,238,239,241,242,243,245,246,247,249,250,251,253,254").into_iter().chain([255; 105].into_iter()).collect::<Vec<_>>().as_slice(),
string_data("9,14,18,21,24,27,29,32,34,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,66,68,70,72,73,75,77,79,80,82,84,85,87,89,90,92,94,95,97,99,100,102,104,105,107,108,110,111,113,115,116,118,119,121,122,124,126,127,129,130,132,133,135,136,138,139,141,142,144,145,147,148,150,151,153,154,156,157,159,160,161,163,164,166,167,169,170,172,173,175,176,177,179,180,182,183,185,186,187,189,190,192,193,195,196,197,199,200,202,203,204,206,207,209,210,211,213,214,216,217,218,220,221,223,224,225,227,228,230,231,232,234,235,236,238,239,241,242,243,245,246,247,249,250,251,253,254").into_iter().chain([255; 105]).collect::<Vec<_>>().as_slice(),
);
assert_eq!(
brightness_contrast_legacy_map(150., 0.),
string_data("78,93,105,114,122,129,135,141,147,152,157,162,167,171,176,180,184,188,192,196,200,204,208,211,215,218,222,225,229,232,236,239,242,245,249,252")
.into_iter()
.chain([255; 220].into_iter())
.chain([255; 220])
.collect::<Vec<_>>()
.as_slice(),
);

View file

@ -11,6 +11,7 @@ mod base64_serde {
//! Basic wrapper for [`serde`] to perform [`base64`] encoding
use super::super::Pixel;
use base64::Engine;
use serde::{Deserialize, Deserializer, Serializer};
pub fn as_base64<S, P: Pixel>(key: &[P], serializer: S) -> Result<S::Ok, S::Error>
@ -18,7 +19,7 @@ mod base64_serde {
S: Serializer,
{
let u8_data = key.iter().flat_map(|color| color.to_bytes()).collect::<Vec<_>>();
serializer.serialize_str(&base64::encode(u8_data))
serializer.serialize_str(&base64::engine::general_purpose::STANDARD.encode(u8_data))
}
pub fn from_base64<'a, D, P: Pixel>(deserializer: D) -> Result<Vec<P>, D::Error>
@ -32,7 +33,7 @@ mod base64_serde {
let colors_from_bytes = |bytes: Vec<u8>| bytes.chunks_exact(P::byte_size()).map(color_from_chunk).collect();
String::deserialize(deserializer)
.and_then(|string| base64::decode(string).map_err(|err| Error::custom(err.to_string())))
.and_then(|string| base64::engine::general_purpose::STANDARD.decode(string).map_err(|err| Error::custom(err.to_string())))
.map(colors_from_bytes)
.map_err(serde::de::Error::custom)
}

View file

@ -97,7 +97,9 @@ impl BrushStroke {
// placing a blit point every time we travelled our spacing distance.
let spacing_dist = self.style.spacing / 100. * self.style.diameter;
let Some(first_sample) = self.trace.first() else { return Vec::new(); };
let Some(first_sample) = self.trace.first() else {
return Vec::new();
};
let mut cur_pos = first_sample.position;
let mut result = vec![cur_pos];