Skip to content

Commit 58d621c

Browse files
committed
Removed use of Vec3 in favor of specific coordinate types
1 parent 0d591be commit 58d621c

File tree

3 files changed

+25
-67
lines changed

3 files changed

+25
-67
lines changed

src/coords.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ impl<T: Angle> LLH<T> {
7373
&mut self.0
7474
}
7575

76+
pub fn as_array_ref(&self) -> &[f64; 3] {
77+
&self.0
78+
}
79+
80+
pub fn as_mut_array_ref(&mut self) -> &mut [f64; 3] {
81+
&mut self.0
82+
}
83+
7684
pub fn latitude(&self) -> f64 {
7785
self.0[0]
7886
}
@@ -163,6 +171,14 @@ impl ECEF {
163171
&mut self.0
164172
}
165173

174+
pub fn as_array_ref(&self) -> &[f64; 3] {
175+
&self.0
176+
}
177+
178+
pub fn as_mut_array_ref(&mut self) -> &mut [f64; 3] {
179+
&mut self.0
180+
}
181+
166182
pub fn x(&self) -> f64 {
167183
self.0[0]
168184
}

src/ephemeris.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
1111
use crate::{
1212
c_bindings,
13-
coords::AzimuthElevation,
13+
coords::{AzimuthElevation, ECEF},
1414
signal::{Code, Constellation, GnssSignal},
1515
time::GpsTime,
16-
Vec3,
1716
};
1817
use std::fmt::{Display, Formatter};
1918

@@ -268,9 +267,9 @@ impl Ephemeris {
268267
/// Calculate satellite position, velocity and clock offset from ephemeris.
269268
pub fn calc_satellite_state(&self, t: &GpsTime) -> Result<SatelliteState> {
270269
let mut sat = SatelliteState {
271-
pos: Vec3::default(),
272-
vel: Vec3::default(),
273-
acc: Vec3::default(),
270+
pos: ECEF::default(),
271+
vel: ECEF::default(),
272+
acc: ECEF::default(),
274273
clock_err: 0.0,
275274
clock_rate_err: 0.0,
276275
iodc: 0,
@@ -298,7 +297,7 @@ impl Ephemeris {
298297

299298
/// Calculate the azimuth and elevation of a satellite from a reference
300299
/// position given the satellite ephemeris.
301-
pub fn calc_satellite_az_el(&self, t: &GpsTime, pos: &Vec3) -> Result<AzimuthElevation> {
300+
pub fn calc_satellite_az_el(&self, t: &GpsTime, pos: &ECEF) -> Result<AzimuthElevation> {
302301
let mut sat = AzimuthElevation::default();
303302

304303
let result = unsafe {
@@ -322,7 +321,7 @@ impl Ephemeris {
322321

323322
/// Calculate the Doppler shift of a satellite as observed at a reference
324323
/// position given the satellite ephemeris.
325-
pub fn calc_satellite_doppler(&self, t: &GpsTime, pos: &Vec3, vel: &Vec3) -> Result<f64> {
324+
pub fn calc_satellite_doppler(&self, t: &GpsTime, pos: &ECEF, vel: &ECEF) -> Result<f64> {
326325
let mut doppler = 0.0;
327326

328327
let result = unsafe {
@@ -379,11 +378,11 @@ impl Default for Ephemeris {
379378
/// certain time.
380379
pub struct SatelliteState {
381380
/// Calculated satellite position, in meters
382-
pub pos: Vec3,
381+
pub pos: ECEF,
383382
/// Calculated satellite velocity, in meters/second
384-
pub vel: Vec3,
383+
pub vel: ECEF,
385384
/// Calculated satellite acceleration, meters/second/second
386-
pub acc: Vec3,
385+
pub acc: ECEF,
387386
/// Calculated satellite clock error, in seconds
388387
pub clock_err: f64,
389388
/// Calculated satellite clock error rate, in seconds/second

src/lib.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,3 @@ pub mod ionosphere;
2222
pub mod signal;
2323
pub mod time;
2424
pub mod troposphere;
25-
26-
#[derive(Copy, Clone, Debug, Default)]
27-
pub struct Vec3([f64; 3]);
28-
29-
impl Vec3 {
30-
pub fn new(x: f64, y: f64, z: f64) -> Vec3 {
31-
Vec3([x, y, z])
32-
}
33-
34-
pub fn from_array(a: &[f64; 3]) -> Vec3 {
35-
Vec3(*a)
36-
}
37-
38-
pub fn get_x(&self) -> f64 {
39-
self.0[0]
40-
}
41-
42-
pub fn get_y(&self) -> f64 {
43-
self.0[1]
44-
}
45-
46-
pub fn get_z(&self) -> f64 {
47-
self.0[2]
48-
}
49-
50-
pub fn set_x(&mut self, new_x: f64) {
51-
self.0[0] = new_x;
52-
}
53-
54-
pub fn set_y(&mut self, new_y: f64) {
55-
self.0[1] = new_y;
56-
}
57-
58-
pub fn set_z(&mut self, new_z: f64) {
59-
self.0[2] = new_z;
60-
}
61-
62-
pub fn as_array_ref(&self) -> &[f64; 3] {
63-
&self.0
64-
}
65-
66-
pub fn as_mut_array_ref(&mut self) -> &mut [f64; 3] {
67-
&mut self.0
68-
}
69-
}
70-
71-
impl AsRef<[f64; 3]> for Vec3 {
72-
fn as_ref(&self) -> &[f64; 3] {
73-
&self.0
74-
}
75-
}
76-
77-
impl AsMut<[f64; 3]> for Vec3 {
78-
fn as_mut(&mut self) -> &mut [f64; 3] {
79-
&mut self.0
80-
}
81-
}

0 commit comments

Comments
 (0)