clippy
This commit is contained in:
parent
6591de7dec
commit
b5bc14faa3
84
src/blur.rs
84
src/blur.rs
@ -8,9 +8,9 @@ pub struct Blur {
|
||||
|
||||
impl Clone for Blur {
|
||||
fn clone(&self) -> Blur {
|
||||
return Blur {
|
||||
Blur {
|
||||
row_buffer: self.row_buffer.clone(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,16 +148,16 @@ mod tests {
|
||||
// ndimage.uniform_filter(a, size=3, mode='wrap') # 2D blur
|
||||
|
||||
let mut src: Vec<f32> = vec![
|
||||
0.32352856, 0.06571674, 0.01939427, 0.06352045, 0.70852702, 0.61722172, 0.16638431,
|
||||
0.62840077, 0.55489392, 0.24007676, 0.32500995, 0.08515139, 0.67984092, 0.6975669,
|
||||
0.73623422, 0.55053085, 0.69222768, 0.22727048, 0.13594262, 0.10002105, 0.16099514,
|
||||
0.07719103, 0.23984282, 0.9083058, 0.64222744, 0.96893419, 0.74662715, 0.71562013,
|
||||
0.73654653, 0.70610344, 0.22101117, 0.75572186, 0.69195882, 0.83741404, 0.27583158,
|
||||
0.57257051, 0.68160597, 0.39237339, 0.33524343, 0.89396836, 0.60296932, 0.17130112,
|
||||
0.1733834, 0.77127819, 0.99537134, 0.91504964, 0.49312109, 0.43035202, 0.70297265,
|
||||
0.36734178, 0.4551964, 0.47104315, 0.60374777, 0.73872683, 0.5630592, 0.97440224,
|
||||
0.63368284, 0.84109297, 0.24447136, 0.750384, 0.16893725, 0.54225663, 0.43560783,
|
||||
0.41497124,
|
||||
0.32352856, 0.06571674, 0.01939427, 0.06352045, 0.708_527, 0.617_221_7, 0.16638431,
|
||||
0.628_400_74, 0.554_893_9, 0.240_076_77, 0.325_009_94, 0.08515139, 0.679_840_9, 0.6975669,
|
||||
0.736_234_25, 0.55053085, 0.692_227_66, 0.22727048, 0.13594262, 0.10002105, 0.16099514,
|
||||
0.07719103, 0.23984282, 0.9083058, 0.642_227_4, 0.968_934_2, 0.74662715, 0.715_620_1,
|
||||
0.736_546_5, 0.70610344, 0.221_011_18, 0.755_721_87, 0.691_958_84, 0.837_414, 0.27583158,
|
||||
0.572_570_5, 0.681_606, 0.392_373_38, 0.33524343, 0.893_968_34, 0.602_969_35, 0.171_301_13,
|
||||
0.1733834, 0.771_278_2, 0.99537134, 0.915_049_6, 0.493_121_1, 0.430_352_03, 0.70297265,
|
||||
0.367_341_8, 0.4551964, 0.471_043_14, 0.603_747_8, 0.738_726_85, 0.5630592, 0.974_402_25,
|
||||
0.633_682_85, 0.841_092_94, 0.24447136, 0.750384, 0.16893725, 0.542_256_65, 0.435_607_82,
|
||||
0.414_971_23,
|
||||
];
|
||||
let (width, height) = (8, 8);
|
||||
let mut dst = vec![0.0; width * height];
|
||||
@ -165,16 +165,16 @@ mod tests {
|
||||
|
||||
blur.box_blur_h(&src, &mut dst, width, 1);
|
||||
let mut sol: Vec<f32> = vec![
|
||||
0.33921536, 0.13621319, 0.04954382, 0.26381392, 0.46308973, 0.49737768, 0.47066893,
|
||||
0.37277121, 0.44850051, 0.37332688, 0.21674603, 0.36333409, 0.48751974, 0.70454735,
|
||||
0.66144399, 0.61388633, 0.60926799, 0.35181359, 0.15441138, 0.1323196, 0.11273574,
|
||||
0.159343, 0.40844655, 0.61345877, 0.78896116, 0.78592959, 0.81039382, 0.73293127,
|
||||
0.71942337, 0.55455371, 0.56094549, 0.53965349, 0.80778041, 0.60173482, 0.56193871,
|
||||
0.51000269, 0.54884996, 0.46974093, 0.54052839, 0.64039021, 0.40154082, 0.31588461,
|
||||
0.37198757, 0.64667764, 0.89389972, 0.80118069, 0.61284092, 0.50881414, 0.68157222,
|
||||
0.50850361, 0.43119378, 0.50999577, 0.60450592, 0.63517794, 0.75872942, 0.74681136,
|
||||
0.62991568, 0.57308239, 0.61198277, 0.38793087, 0.48719263, 0.38226724, 0.46427857,
|
||||
0.49475397,
|
||||
0.339_215_37, 0.136_213_18, 0.04954382, 0.263_813_9, 0.46308973, 0.497_377_7, 0.470_668_94,
|
||||
0.372_771_2, 0.448_500_5, 0.373_326_87, 0.21674603, 0.363_334_1, 0.48751974, 0.70454735,
|
||||
0.661_444, 0.613_886_36, 0.609_268, 0.351_813_58, 0.15441138, 0.1323196, 0.11273574,
|
||||
0.159343, 0.40844655, 0.613_458_75, 0.788_961_2, 0.785_929_56, 0.810_393_8, 0.732_931_26,
|
||||
0.719_423_35, 0.554_553_7, 0.560_945_5, 0.539_653_5, 0.807_780_4, 0.601_734_8, 0.561_938_7,
|
||||
0.510_002_7, 0.548_849_94, 0.46974093, 0.540_528_4, 0.640_390_2, 0.40154082, 0.315_884_62,
|
||||
0.371_987_58, 0.646_677_6, 0.893_899_74, 0.801_180_66, 0.612_840_9, 0.508_814_16, 0.681_572_2,
|
||||
0.508_503_6, 0.431_193_77, 0.509_995_76, 0.604_505_9, 0.635_177_9, 0.758_729_4, 0.746_811_33,
|
||||
0.629_915_65, 0.573_082_4, 0.611_982_76, 0.38793087, 0.48719263, 0.38226724, 0.464_278_58,
|
||||
0.494_753_96,
|
||||
];
|
||||
for (v1, v2) in dst.iter().zip(sol) {
|
||||
assert!((v1 - v2).abs() < 1e-6);
|
||||
@ -182,16 +182,16 @@ mod tests {
|
||||
|
||||
blur.box_blur_v(&src, &mut dst, width, height, 1, 1.0);
|
||||
sol = vec![
|
||||
0.50403511, 0.38229549, 0.19629186, 0.29968528, 0.51910173, 0.61901508, 0.44607546,
|
||||
0.53130095, 0.52355005, 0.177688, 0.16011561, 0.08289763, 0.51645436, 0.46399322,
|
||||
0.38082045, 0.69574581, 0.62978301, 0.47876048, 0.40252657, 0.30026419, 0.5257942,
|
||||
0.49362046, 0.3990294, 0.73818617, 0.67547131, 0.67787291, 0.38613379, 0.46273723,
|
||||
0.52638255, 0.39188929, 0.26536581, 0.85266534, 0.64571853, 0.65921645, 0.39861405,
|
||||
0.68648961, 0.80450795, 0.67117549, 0.34979189, 0.69334741, 0.66596693, 0.45868565,
|
||||
0.30147046, 0.60496395, 0.76024169, 0.68204996, 0.46380791, 0.76624087, 0.6465416,
|
||||
0.45991196, 0.29101705, 0.66423511, 0.58935212, 0.73201103, 0.49726271, 0.60657516,
|
||||
0.55339468, 0.42471716, 0.23968734, 0.42831587, 0.49373735, 0.63273506, 0.38835045,
|
||||
0.67259142,
|
||||
0.504_035_1, 0.382_295_5, 0.19629186, 0.299_685_27, 0.519_101_74, 0.619_015_1, 0.446_075_47,
|
||||
0.531_300_96, 0.523_550_03, 0.177688, 0.16011561, 0.08289763, 0.516_454_34, 0.46399322,
|
||||
0.38082045, 0.695_745_8, 0.629_783_03, 0.47876048, 0.402_526_56, 0.300_264_18, 0.5257942,
|
||||
0.49362046, 0.3990294, 0.738_186_2, 0.675_471_3, 0.677_872_9, 0.386_133_8, 0.46273723,
|
||||
0.526_382_57, 0.391_889_3, 0.265_365_8, 0.852_665_36, 0.645_718_5, 0.659_216_46, 0.39861405,
|
||||
0.686_489_6, 0.804_508, 0.671_175_5, 0.349_791_88, 0.693_347_4, 0.665_966_9, 0.458_685_64,
|
||||
0.30147046, 0.604_963_96, 0.760_241_7, 0.682_05, 0.463_807_9, 0.766_240_9, 0.6465416,
|
||||
0.459_911_97, 0.291_017_06, 0.664_235_1, 0.589_352_13, 0.732_011, 0.497_262_72, 0.606_575_13,
|
||||
0.553_394_7, 0.42471716, 0.23968734, 0.428_315_88, 0.493_737_34, 0.632_735_1, 0.388_350_46,
|
||||
0.672_591_45,
|
||||
];
|
||||
for (v1, v2) in dst.iter().zip(sol) {
|
||||
assert!((v1 - v2).abs() < 1e-6);
|
||||
@ -199,16 +199,16 @@ mod tests {
|
||||
|
||||
blur.box_blur(&mut src, &mut dst, width, height, 1, 1.0);
|
||||
sol = vec![
|
||||
0.47254385, 0.36087415, 0.29275754, 0.33835963, 0.47926736, 0.52806409, 0.5321305,
|
||||
0.49380384, 0.46566129, 0.28711789, 0.14023375, 0.25315587, 0.3544484, 0.45375601,
|
||||
0.51351983, 0.5333721, 0.61557655, 0.50369002, 0.39385041, 0.40952832, 0.43989295,
|
||||
0.47281469, 0.54361201, 0.58899953, 0.73533652, 0.579826, 0.50891464, 0.45841785,
|
||||
0.46033635, 0.39454588, 0.50330681, 0.59783415, 0.66609413, 0.56784968, 0.58144004,
|
||||
0.62987053, 0.72072435, 0.60849178, 0.57143827, 0.56295261, 0.63029782, 0.47537435,
|
||||
0.45504002, 0.5555587, 0.68241853, 0.63536652, 0.63736624, 0.63200524, 0.57100958,
|
||||
0.46582354, 0.47172137, 0.5148681, 0.66186609, 0.60620862, 0.61194964, 0.58345982,
|
||||
0.55023442, 0.40593306, 0.36424013, 0.38724685, 0.51826276, 0.50494095, 0.56455897,
|
||||
0.53811218,
|
||||
0.472_543_84, 0.36087415, 0.29275754, 0.338_359_62, 0.47926736, 0.528_064_1, 0.5321305,
|
||||
0.493_803_83, 0.465_661_3, 0.287_117_9, 0.140_233_76, 0.253_155_86, 0.3544484, 0.453_756,
|
||||
0.513_519_8, 0.5333721, 0.615_576_57, 0.503_69, 0.393_850_42, 0.40952832, 0.43989295,
|
||||
0.472_814_68, 0.543_612, 0.588_999_5, 0.735_336_54, 0.579826, 0.508_914_65, 0.458_417_86,
|
||||
0.460_336_36, 0.39454588, 0.503_306_8, 0.597_834_17, 0.666_094_1, 0.567_849_7, 0.581_440_03,
|
||||
0.62987053, 0.720_724_34, 0.608_491_8, 0.571_438_25, 0.562_952_64, 0.630_297_84, 0.475_374_34,
|
||||
0.455_04, 0.5555587, 0.682_418_5, 0.635_366_5, 0.63736624, 0.632_005_2, 0.571_009_6,
|
||||
0.465_823_53, 0.471_721_38, 0.5148681, 0.661_866_07, 0.606_208_6, 0.611_949_6, 0.583_459_8,
|
||||
0.550_234_44, 0.405_933_05, 0.364_240_14, 0.38724685, 0.518_262_74, 0.504_940_9, 0.564_559,
|
||||
0.538_112_16,
|
||||
];
|
||||
for (v1, v2) in src.iter().zip(sol) {
|
||||
assert!((v1 - v2).abs() < 1e-6);
|
||||
|
||||
12
src/grid.rs
12
src/grid.rs
@ -18,14 +18,14 @@ pub struct PopulationConfig {
|
||||
|
||||
impl Clone for PopulationConfig {
|
||||
fn clone(&self) -> PopulationConfig {
|
||||
return PopulationConfig {
|
||||
PopulationConfig {
|
||||
sensor_distance: self.sensor_distance,
|
||||
step_distance: self.step_distance,
|
||||
sensor_angle: self.sensor_angle,
|
||||
rotation_angle: self.rotation_angle,
|
||||
decay_factor: self.decay_factor,
|
||||
deposition_amount: self.deposition_amount,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,14 +92,14 @@ pub struct Grid {
|
||||
|
||||
impl Clone for Grid {
|
||||
fn clone(&self) -> Grid {
|
||||
return Grid {
|
||||
Grid {
|
||||
config: self.config.clone(),
|
||||
width: self.width.clone(),
|
||||
height: self.height.clone(),
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
data: self.data.clone(),
|
||||
buf: self.buf.clone(),
|
||||
blur: self.blur.clone(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,11 +9,11 @@ pub struct ImgData {
|
||||
|
||||
impl Clone for ImgData {
|
||||
fn clone(&self) -> ImgData {
|
||||
return ImgData {
|
||||
ImgData {
|
||||
grids: self.grids.clone(),
|
||||
palette: self.palette.clone(),
|
||||
iteration: self.iteration.clone(),
|
||||
};
|
||||
palette: self.palette,
|
||||
iteration: self.iteration,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
fn abs(x: f32) -> f32 {
|
||||
return f32::from_bits(x.to_bits() & 0x7FFF_FFFF);
|
||||
f32::from_bits(x.to_bits() & 0x7FFF_FFFF)
|
||||
}
|
||||
|
||||
// Previously from trig.rs
|
||||
@ -13,7 +13,7 @@ fn abs(x: f32) -> f32 {
|
||||
fn floor(x: f32) -> f32 {
|
||||
let mut x_trunc = (x as i32) as f32;
|
||||
x_trunc -= (x < x_trunc) as i32 as f32;
|
||||
return x_trunc;
|
||||
x_trunc
|
||||
}
|
||||
|
||||
// Previously from trig.rs
|
||||
@ -27,7 +27,7 @@ pub fn cos(mut x: f32) -> f32 {
|
||||
x -= 0.25_f32 + floor(x + 0.25_f32);
|
||||
x *= 16.0_f32 * (abs(x) - 0.5_f32);
|
||||
x += 0.225_f32 * x * (abs(x) - 1.0_f32);
|
||||
return x;
|
||||
x
|
||||
}
|
||||
|
||||
// Previously from trig.rs
|
||||
@ -35,6 +35,6 @@ pub fn cos(mut x: f32) -> f32 {
|
||||
#[allow(dead_code)]
|
||||
#[inline]
|
||||
pub fn sin(x: f32) -> f32 {
|
||||
return cos(x - std::f32::consts::FRAC_PI_2);
|
||||
cos(x - std::f32::consts::FRAC_PI_2)
|
||||
}
|
||||
|
||||
|
||||
20
src/model.rs
20
src/model.rs
@ -31,30 +31,30 @@ impl Agent {
|
||||
y: y * height as f32,
|
||||
angle: angle * TAU,
|
||||
population_id: id,
|
||||
i: i,
|
||||
i,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Agent {
|
||||
fn clone(&self) -> Agent {
|
||||
return Agent {
|
||||
Agent {
|
||||
x: self.x,
|
||||
y: self.y,
|
||||
angle: self.angle,
|
||||
population_id: self.population_id,
|
||||
i: self.i,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Agent {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
return self.x == other.x
|
||||
self.x == other.x
|
||||
&& self.y == other.y
|
||||
&& self.angle == other.angle
|
||||
&& self.population_id == other.population_id
|
||||
&& self.i == other.i;
|
||||
&& self.i == other.i
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,12 +266,10 @@ impl Model {
|
||||
let grids = self.grids.clone();
|
||||
let img_data = ImgData::new(grids, self.palette, self.iteration);
|
||||
self.img_data_vec.push(img_data);
|
||||
if self.grids[0].width > 1024 && self.grids[0].height > 1024 {
|
||||
if self.img_data_vec.len() > 100 {
|
||||
self.render_all_imgdata();
|
||||
self.flush_image_data();
|
||||
return;
|
||||
}
|
||||
if self.grids[0].width > 1024 && self.grids[0].height > 1024 && self.img_data_vec.len() > 100 {
|
||||
self.render_all_imgdata();
|
||||
self.flush_image_data();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,14 +9,14 @@ pub fn random_palette() -> Palette {
|
||||
let mut rng = thread_rng();
|
||||
let mut palette = PALETTES[rng.gen_range(0..PALETTES.len())];
|
||||
palette.colors.shuffle(&mut rng);
|
||||
return palette;
|
||||
palette
|
||||
}
|
||||
|
||||
const fn hex_to_color(c: usize) -> image::Rgb<u8> {
|
||||
let r = (c >> 16) & 0xff;
|
||||
let g = (c >> 8) & 0xff;
|
||||
let b = (c >> 0) & 0xff;
|
||||
return image::Rgb::<u8>([r as u8, g as u8, b as u8]);
|
||||
image::Rgb::<u8>([r as u8, g as u8, b as u8])
|
||||
}
|
||||
|
||||
const PALETTES: [Palette; 8] = [
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#[inline(always)]
|
||||
pub fn wrap(x: f32, max: f32) -> f32 {
|
||||
return x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32);
|
||||
x - max * ((x > max) as i32 as f32 - (x < 0.0_f32) as i32 as f32)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user