Skip to content

Commit 204de50

Browse files
authored
rustfmt (#138)
1 parent d68e21b commit 204de50

File tree

16 files changed

+106
-78
lines changed

16 files changed

+106
-78
lines changed

rustfmt.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
max_width = 100
2+
wrap_comments = true
3+
comment_width = 100
4+
format_strings = true
5+
edition = "2024"
6+
imports_granularity = "Crate"
7+
group_imports = "StdExternalCrate"
8+
style_edition = "2024"

swiftnav/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ rust-version = "1.85.0"
1212
[dependencies]
1313
bon = "3.8.1"
1414
rustversion = "1.0.22"
15-
chrono = { version = "0.4.42", optional = true }
15+
chrono = { version = "0.4.42" }
1616
strum = { version = "0.27.2", features = ["derive"] }
1717
nalgebra = "0.34.1"
1818
thiserror = "2.0.17"
1919

2020
[dev-dependencies]
2121
float_eq = "1.0.1"
22-
proptest = "1.8.0"
22+
proptest = "1.9.0"
2323

2424
# This tells docs.rs to include the katex header for math formatting
2525
# To do this locally

swiftnav/src/coords/ecef.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use nalgebra::Vector3;
21
use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
32

3+
use nalgebra::Vector3;
4+
45
use crate::{
56
coords::{AzimuthElevation, Ellipsoid, LLHDegrees, LLHRadians, NED, WGS84},
67
math,

swiftnav/src/coords/llh.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::coords::{LatitudinalHemisphere, LongitudinalHemisphere};
2-
3-
use super::{Ellipsoid, ECEF, WGS84};
41
use nalgebra::Vector3;
52

3+
use super::{ECEF, Ellipsoid, WGS84};
4+
use crate::coords::{LatitudinalHemisphere, LongitudinalHemisphere};
5+
66
/// WGS84 geodetic coordinates (Latitude, Longitude, Height), with angles in degrees.
77
///
8-
/// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude, and height above the ellipsoid in meters
8+
/// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude, and height above
9+
/// the ellipsoid in meters
910
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Default)]
1011
pub struct LLHDegrees(Vector3<f64>);
1112

@@ -157,7 +158,8 @@ impl AsMut<Vector3<f64>> for LLHDegrees {
157158

158159
/// WGS84 geodetic coordinates (Latitude, Longitude, Height), with angles in radians.
159160
///
160-
/// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude, and height above the ellipsoid in meters
161+
/// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude, and height above
162+
/// the ellipsoid in meters
161163
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Default)]
162164
pub struct LLHRadians(Vector3<f64>);
163165

swiftnav/src/coords/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
//! the more common algortihms based on the Newton-Raphson method.
4545
//!
4646
//! ## References
47-
//! * "A comparison of methods used in rectangular to Geodetic Coordinates
48-
//! Transformations", Burtch R. R. (2006), American Congress for Surveying
49-
//! and Mapping Annual Conference. Orlando, Florida.
50-
//! * "Transformation from Cartesian to Geodetic Coordinates Accelerated by
51-
//! Halley’s Method", T. Fukushima (2006), Journal of Geodesy.
47+
//! * "A comparison of methods used in rectangular to Geodetic Coordinates Transformations", Burtch
48+
//! R. R. (2006), American Congress for Surveying and Mapping Annual Conference. Orlando, Florida.
49+
//! * "Transformation from Cartesian to Geodetic Coordinates Accelerated by Halley’s Method", T.
50+
//! Fukushima (2006), Journal of Geodesy.
5251
//!
5352
//! # Examples
5453
//!
@@ -84,16 +83,19 @@ pub use ecef::*;
8483
pub use ellipsoid::*;
8584
pub use hemisphere::*;
8685
pub use llh::*;
86+
use nalgebra::Vector2;
8787
pub use ned::*;
8888

8989
use crate::{reference_frame::ReferenceFrame, time::GpsTime};
90-
use nalgebra::Vector2;
9190

92-
/// WGS84 local horizontal coordinates consisting of an Azimuth and Elevation, with angles stored as radians
91+
/// WGS84 local horizontal coordinates consisting of an Azimuth and Elevation, with angles stored as
92+
/// radians
9393
///
94-
/// Azimuth can range from $0$ to $2\pi$. North has an azimuth of $0$, east has an azimuth of $\frac{\pi}{2}$
94+
/// Azimuth can range from $0$ to $2\pi$. North has an azimuth of $0$, east has an azimuth of
95+
/// $\frac{\pi}{2}$
9596
///
96-
/// Elevation can range from $-\frac{\pi}{2}$ to $\frac{\pi}{2}$. Up has an elevation of $\frac{\pi}{2}$, down an elevation of $-\frac{\pi}{2}$
97+
/// Elevation can range from $-\frac{\pi}{2}$ to $\frac{\pi}{2}$. Up has an elevation of
98+
/// $\frac{\pi}{2}$, down an elevation of $-\frac{\pi}{2}$
9799
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Default)]
98100
pub struct AzimuthElevation(Vector2<f64>);
99101

@@ -292,11 +294,10 @@ impl Coordinate {
292294
#[cfg(test)]
293295
mod tests {
294296
use float_eq::assert_float_eq;
295-
296-
use crate::time::UtcTime;
297+
use proptest::prelude::*;
297298

298299
use super::*;
299-
use proptest::prelude::*;
300+
use crate::time::UtcTime;
300301

301302
/* Maximum allowable error in quantities with units of length (in meters). */
302303
const MAX_DIST_ERROR_M: f64 = 1e-6;

swiftnav/src/edc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,10 @@ pub fn compute_crc24q(buf: &[u8], initial_value: u32) -> u32 {
326326

327327
#[cfg(test)]
328328
mod tests {
329-
use super::*;
330329
use proptest::prelude::*;
331330

331+
use super::*;
332+
332333
const TEST_DATA: &[u8] = "123456789".as_bytes();
333334

334335
/// Helper function to append a CRC-24Q value as 3 bytes (big-endian) to a buffer

swiftnav/src/math.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
/// We define a `const` max function since [`std::cmp::max`] isn't `const`
1212
pub(crate) const fn compile_time_max_u16(a: u16, b: u16) -> u16 {
13-
if b < a {
14-
a
15-
} else {
16-
b
17-
}
13+
if b < a { a } else { b }
1814
}
1915

2016
/// Computes the square root of a given number at compile time using the Newton-Raphson method.
@@ -35,7 +31,8 @@ pub(crate) const fn compile_time_max_u16(a: u16, b: u16) -> u16 {
3531
/// # Notes
3632
///
3733
/// - This function is marked as `const`, allowing it to be evaluated at compile time.
38-
/// - The algorithm iteratively refines the approximation of the square root until the result stabilizes.
34+
/// - The algorithm iteratively refines the approximation of the square root until the result
35+
/// stabilizes.
3936
#[expect(clippy::many_single_char_names, reason = "It's math, whatyagonnado?")]
4037
pub(crate) const fn compile_time_sqrt(s: f64) -> f64 {
4138
assert!(
@@ -57,7 +54,8 @@ pub(crate) const fn compile_time_sqrt(s: f64) -> f64 {
5754
x
5855
}
5956

60-
/// Calculate the rotation matrix for rotating between an [`crate::coords::ECEF`] and [`crate::coords::NED`] frames
57+
/// Calculate the rotation matrix for rotating between an [`crate::coords::ECEF`] and
58+
/// [`crate::coords::NED`] frames
6159
#[must_use]
6260
pub(crate) fn ecef2ned_matrix(llh: crate::coords::LLHRadians) -> nalgebra::Matrix3<f64> {
6361
let sin_lat = llh.latitude().sin();
@@ -80,10 +78,11 @@ pub(crate) fn ecef2ned_matrix(llh: crate::coords::LLHRadians) -> nalgebra::Matri
8078

8179
#[cfg(test)]
8280
mod tests {
83-
use super::*;
8481
use float_eq::assert_float_eq;
8582
use proptest::prelude::*;
8683

84+
use super::*;
85+
8786
proptest! {
8887
#![proptest_config(ProptestConfig::with_cases(1000))]
8988

swiftnav/src/nmea/checksum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn u8_to_ascii_char(nibble: u8) -> char {
2525
pub fn calculate_checksum(sentence: &str) -> String {
2626
let mut checksum = 0;
2727

28-
// this flag indicates if we have reached the '*' character or anything beyond that such as the actual checksum value or the end sequence (<CR><LF>)
28+
// this flag indicates if we have reached the '*' character or anything beyond that such as the
29+
// actual checksum value or the end sequence (<CR><LF>)
2930
let mut at_or_past_checksum_field = false;
3031

3132
for (i, byte) in sentence.bytes().enumerate() {

swiftnav/src/nmea/gga.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ impl GGA {
9999

100100
let hdop = self.hdop.map_or(String::new(), |hdop| format!("{hdop:.1}"));
101101

102-
// NOTE(ted): This is actually not the right value to use, however, we don't really use height for finding information like nearest station so it's ok to use for now
102+
// NOTE(ted): This is actually not the right value to use, however, we don't really use
103+
// height for finding information like nearest station so it's ok to use for now
103104
let height = "0.0";
104105

105-
let age_dgps = self.age_dgps.map_or(0.0, |age| age.as_secs_f64());
106+
let age_dgps = self
107+
.age_dgps
108+
.map_or(String::new(), |age| format!("{:.1}", age.as_secs_f64()));
106109

107110
let geoidal_separation = self
108111
.geoidal_separation
@@ -113,7 +116,9 @@ impl GGA {
113116
.map_or(String::new(), |id| id.to_string());
114117

115118
let sentence = format!(
116-
"GPGGA,{timestamp},{latitude:.6},{latitudinal_hemisphere},{longitude:.6},{longitudinal_hemisphere},{gps_quality},{sat_in_use},{hdop},{height:.6},M,{geoidal_separation},{age_dgps:.1},{reference_station_id}",
119+
"GPGGA,{timestamp},{latitude:.6},{latitudinal_hemisphere},{longitude:.6},\
120+
{longitudinal_hemisphere},{gps_quality},{sat_in_use},{hdop},{height:.6},M,\
121+
{geoidal_separation},{age_dgps:.1},{reference_station_id}",
117122
);
118123

119124
let checksum = nmea::calculate_checksum(&sentence);
@@ -133,6 +138,7 @@ mod test {
133138
let gga = GGA::builder()
134139
.sat_in_use(12)
135140
.time(DateTime::from_timestamp(1_761_351_489, 0).unwrap())
141+
.gps_quality(GPSQuality::GPS)
136142
.hdop(0.9)
137143
.llh(super::LLHDegrees::new(37.7749, -122.4194, 10.0))
138144
.build();
@@ -166,30 +172,10 @@ mod test {
166172
);
167173
}
168174

169-
#[test]
170-
fn gga_with_dgps_fields_that_is_not_dgps_is_ignored() {
171-
let gga = GGA::builder()
172-
.sat_in_use(8)
173-
.time(DateTime::from_timestamp(1_761_351_489, 0).unwrap())
174-
.hdop(1.2)
175-
.llh(super::LLHDegrees::new(34.0522, -118.2437, 15.0))
176-
.gps_quality(GPSQuality::GPS)
177-
.age_dgps(Duration::from_secs_f64(2.5))
178-
.geoidal_separation(1.0)
179-
.reference_station_id(42)
180-
.build();
181-
182-
let sentence = gga.to_sentence();
183-
184-
assert_eq!(
185-
sentence,
186-
"$GPGGA,0189.00,34.052200,N,-118.243700,W,1,8,1.2,0.0,M,1.00,,*00\r\n"
187-
);
188-
}
189-
190175
#[test]
191176
fn gga_sentence_is_always_less_than_82_characters() {
192-
// we are going to set some very large decimal places and the highest possible values in terms of character count to ensure our sentence is always below 82 characters
177+
// we are going to set some very large decimal places and the highest possible values in
178+
// terms of character count to ensure our sentence is always below 82 characters
193179
let gga = GGA::builder()
194180
.sat_in_use(12)
195181
.time(DateTime::from_timestamp(1_761_351_489, 0).unwrap())

swiftnav/src/nmea/source.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ pub enum Source {
99
Gallileo = 0b100,
1010
/// China's Beidou
1111
Beidou = 0b1000,
12-
/// Global Navigation Sattelite System. Some combination of other systems. Depends on receiver model, receiver settings, etc..
12+
/// Global Navigation Sattelite System. Some combination of other systems. Depends on receiver
13+
/// model, receiver settings, etc..
1314
GNSS = 0b10000,
1415
/// `MediaTek` NMEA packet protocol
1516
MTK = 0b10_0000,

0 commit comments

Comments
 (0)