Skip to content

Commit 0d949c7

Browse files
heussyophilli
authored andcommitted
style: cleanup clippy lints
Problem: My editor complains. Solution: Manually fix clippy warnings. Testing: `cargo run` Issue: #3
1 parent b6d5edc commit 0d949c7

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

src/main.rs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{f64::consts::PI, io::stdout};
1919

2020
/// Based on https://github.com/colej4/satapp/blob/main/src-tauri/src/tracking.rs#L419-L423
2121
struct SphericalPoint {
22+
#[allow(dead_code)]
2223
rho: f64,
2324
theta: f64,
2425
phi: f64,
@@ -43,17 +44,13 @@ fn rect_to_spherical(r: &RectangularPoint) -> SphericalPoint {
4344
let rho = f64::sqrt(r.x.powi(2) + r.y.powi(2) + r.z.powi(2));
4445
let theta = f64::atan2(r.y, r.x);
4546
let phi = f64::atan2(f64::sqrt(r.x.powf(2.0) + r.y.powf(2.0)), r.z);
46-
return SphericalPoint {
47-
rho: rho,
48-
theta: theta,
49-
phi: phi,
50-
};
47+
SphericalPoint { rho, theta, phi }
5148
}
5249

5350
/// Based on https://github.com/colej4/satapp/blob/be4a3831134475396bab3639b8add1b337e5b93c/src-tauri/src/tracking.rs#L30-L42
5451
fn spherical_to_lat_lon(s: &SphericalPoint, time: Epoch) -> GroundPos {
5552
let lat = ((s.phi * 180.0 / PI) - 90.0) * -1.0;
56-
let sidereal_time = calc_gmst(time) as f64 / 86400.0 * 360.0;
53+
let sidereal_time = calc_gmst(time) / 86400.0 * 360.0;
5754
let mut lon = ((s.theta * 180.0 / PI) - sidereal_time) % 360.0;
5855
if lon < -180.0 {
5956
lon += 360.0;
@@ -62,7 +59,7 @@ fn spherical_to_lat_lon(s: &SphericalPoint, time: Epoch) -> GroundPos {
6259
lon -= 360.0;
6360
}
6461

65-
return GroundPos { lat: lat, lon: lon };
62+
GroundPos { lat, lon }
6663
}
6764

6865
/// returns current gmst in seconds
@@ -73,29 +70,16 @@ pub fn calc_gmst(time: Epoch) -> f64 {
7370
let t = (now.to_jde_et_days() - s / 86400.0 - 2451545.0) / 36525.0; //days since january 1, 4713 BC noon
7471
let h0 = 24110.54841 + 8640184.812866 * t + 0.093104 * t.powi(2); //the sidereal time at midnight this morning
7572
let h1 = 1.00273790935 + 5.9 * 10.0f64.powf(-11.0) * t;
76-
let rot = (h0 + h1 * s) % 86400.0;
77-
return rot;
73+
(h0 + h1 * s) % 86400.0
7874
}
7975

8076
/// Based on https://github.com/colej4/satapp/blob/be4a3831134475396bab3639b8add1b337e5b93c/src-tauri/src/tracking.rs#L60-L77
8177
fn get_prediction(time: Epoch, elements: &Elements) -> Option<Prediction> {
8278
let epoch = Epoch::from_str(format!("{} UTC", elements.datetime).as_str()).unwrap();
8379
let duration = time - epoch;
84-
let constants = sgp4::Constants::from_elements(&elements).unwrap();
85-
//println!("last epoch was at {}", epoch);
86-
//println!("last epoch was {} ago", duration);
87-
let prediction =
88-
constants.propagate(sgp4::MinutesSinceEpoch(duration.to_seconds() / 60 as f64));
89-
match prediction {
90-
Ok(pred) => return Some(pred),
91-
Err(_) => {
92-
//println!("{:?} at sat {}", e, elements.norad_id);
93-
return None;
94-
}
95-
}
96-
97-
//println!(" r = {:?} km", prediction.position);
98-
//println!(" ṙ = {:?} km.s⁻¹", prediction.velocity);
80+
let constants = sgp4::Constants::from_elements(elements).unwrap();
81+
let prediction = constants.propagate(sgp4::MinutesSinceEpoch(duration.to_seconds() / 60_f64));
82+
prediction.ok()
9983
}
10084

10185
/// Based on https://github.com/colej4/satapp/blob/be4a3831134475396bab3639b8add1b337e5b93c/src-tauri/src/tracking.rs#L79-L94
@@ -105,13 +89,12 @@ pub fn get_sat_lat_lon(time: Epoch, elements: &Elements) -> Option<GroundPos> {
10589
let x = prediction.position[0];
10690
let y = prediction.position[1];
10791
let z = prediction.position[2];
108-
let rect = RectangularPoint { x: x, y: y, z: z };
92+
let rect = RectangularPoint { x, y, z };
10993
let spher = rect_to_spherical(&rect);
11094
let g = spherical_to_lat_lon(&spher, time);
111-
//println!("sat is at ({}, {}) at {:?}", g.lat, g.lon, time);
112-
return Some(g);
95+
Some(g)
11396
} else {
114-
return None;
97+
None
11598
}
11699
}
117100

0 commit comments

Comments
 (0)