putz u in dhe washing machin and spins ur bsky pofile pictuer !!! :D
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

simplify previous angle comparison logic & f32 -> i32

did:plc:73gqgbnvpx5syidcponjri… b1f46ef1 7c322073

verified
+12 -11
+12 -11
src/main.rs
··· 20 20 type AgentType = 21 21 Agent<CredentialSession<MemorySessionStore<SessionKey, AtpSession>, JacquardResolver>>; 22 22 23 - fn write_state(angle: f32) { 23 + fn write_state(angle: i32) { 24 24 const STATE_FILE: &str = ".statefile"; 25 25 26 26 std::fs::write(STATE_FILE, angle.to_string()).unwrap_or_else(|e| { ··· 29 29 }); 30 30 } 31 31 32 - fn read_state() -> Option<f32> { 32 + fn read_state() -> Option<i32> { 33 33 const STATE_FILE: &str = ".statefile"; 34 34 let contents = std::fs::read_to_string(STATE_FILE).ok()?; 35 - let angle: f32 = contents.trim().parse().ok()?; 35 + let angle: i32 = contents.trim().parse().ok()?; 36 36 Some(angle) 37 37 } 38 38 ··· 44 44 process::exit(1); 45 45 } 46 46 47 - fn compute_angle() -> f32 { 47 + fn compute_angle() -> i32 { 48 48 const MS_PER_DAY: i128 = 86_400_000; 49 49 let now_ms = match SystemTime::now().duration_since(UNIX_EPOCH) { 50 50 Ok(dur) => dur.as_secs() as i128 * 1000 + dur.subsec_millis() as i128, ··· 71 71 let fraction_of_day = (ms_today as f64) / (MS_PER_DAY as f64); 72 72 let angle = (fraction_of_day * 360.0).floor() as i32; 73 73 74 - (((angle % 360) + 360) % 360) as f32 74 + ((angle % 360) + 360) % 360 75 75 } 76 76 77 - fn rotate_image(image: DynamicImage, radians: f32) -> image::RgbaImage { 77 + fn rotate_image(image: DynamicImage, degrees: i32) -> image::RgbaImage { 78 78 let width = image.width(); 79 79 let height = image.height(); 80 + 81 + let radians = (degrees as f32).to_radians(); 80 82 81 83 let rotated = rotate( 82 84 &image.to_rgba8(), ··· 184 186 process::exit(1); 185 187 }); 186 188 187 - let previous_angle = read_state(); 188 - if let Some(prev) = previous_angle { 189 - let current_angle = compute_angle(); 190 - if (prev - current_angle).abs() < f32::EPSILON { 191 - println!("profile picture is already at {} degrees", current_angle); 189 + let angle = compute_angle(); 190 + if let Some(prev) = read_state() { 191 + if prev == angle { 192 + println!("profile picture is already at {} degrees", angle); 192 193 return; 193 194 } 194 195 }