Skip to content

Commit 5e5f2ec

Browse files
authored
Add nice to have functions for coordindate types (#130)
Think I got a little over zealous with the RIIR, and removed a couple of nice to have functions. Is it acceptable to have multiple `AsRef` impls on a type? It seems like the stdlin does (e.g. `Vec` implements two different `AsRef`). Also is it preferable to not have dedicated functions and only rely on the `AsRef` impl for casting?
1 parent d2c0b1a commit 5e5f2ec

File tree

5 files changed

+254
-5
lines changed

5 files changed

+254
-5
lines changed

swiftnav/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

swiftnav/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# swiftnav
2+
3+
`swiftnav` is a library that implements GNSS utility functions to perform
4+
position estimations. The data used by `swiftnav` typically comes from GNSS
5+
receiver chips as raw observation and ephemeris data. `swiftnav` is more of
6+
a "bring your own algorithm" library, it provides a bunch of functionality that
7+
is useful when processing raw GNSS data, but it provides only limited position
8+
estimation capabilities. Each module encompasses a single set of functionality,
9+
and they are meant to be pretty self-explanatory for developers familiar with
10+
GNSS processing.
11+
12+
GNSS systems are used to estimate the location of the receiver by determining
13+
the distance between the receiver and several satellites. The satellites send
14+
out precisely timed periodic messages and the receiver measures the delay
15+
of those messages. Knowing the location of the satellites at the time of
16+
transmission and the delays of the messages the receiver is able to determine
17+
the location of itself in relation to the satellites.
18+
19+
`swiftnav` does not provide any functionality for communicating with
20+
receivers made by Swift Navigation, or any manufacturer.
21+
[libsbp](https://github.com/swift-nav/libsbp) is the library to use if you
22+
want to communicate with receivers using Swift Binary Protocol (SBP).

swiftnav/src/coords/ecef.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,30 @@ impl ECEF {
1919
Self(Vector3::new(x, y, z))
2020
}
2121

22-
/// Get a reference to the inner [`Vector3<f64>`]
22+
/// Get a reference to the inner array storing the data
2323
#[must_use]
24-
pub(crate) fn as_vector(&self) -> &Vector3<f64> {
24+
pub fn as_array(&self) -> &[f64; 3] {
25+
&self.0.data.0[0]
26+
}
27+
28+
/// Get a mutable reference to the inner array storing the data
29+
#[must_use]
30+
pub fn as_array_mut(&mut self) -> &mut [f64; 3] {
31+
&mut self.0.data.0[0]
32+
}
33+
34+
/// Get a reference to the inner [`Vector3`] storing the data
35+
#[must_use]
36+
pub fn as_vector(&self) -> &Vector3<f64> {
2537
&self.0
2638
}
2739

40+
/// Get a mutable reference to the inner [`Vector3`] storing the data
41+
#[must_use]
42+
pub fn as_vector_mut(&mut self) -> &mut Vector3<f64> {
43+
&mut self.0
44+
}
45+
2846
/// Get the X component
2947
#[must_use]
3048
pub fn x(&self) -> f64 {
@@ -215,6 +233,30 @@ impl From<LLHDegrees> for ECEF {
215233
}
216234
}
217235

236+
impl AsRef<[f64; 3]> for ECEF {
237+
fn as_ref(&self) -> &[f64; 3] {
238+
self.as_array()
239+
}
240+
}
241+
242+
impl AsRef<Vector3<f64>> for ECEF {
243+
fn as_ref(&self) -> &Vector3<f64> {
244+
self.as_vector()
245+
}
246+
}
247+
248+
impl AsMut<[f64; 3]> for ECEF {
249+
fn as_mut(&mut self) -> &mut [f64; 3] {
250+
self.as_array_mut()
251+
}
252+
}
253+
254+
impl AsMut<Vector3<f64>> for ECEF {
255+
fn as_mut(&mut self) -> &mut Vector3<f64> {
256+
self.as_vector_mut()
257+
}
258+
}
259+
218260
impl Add for ECEF {
219261
type Output = Self;
220262
fn add(self, rhs: ECEF) -> Self {

swiftnav/src/coords/llh.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ impl LLHDegrees {
1414
Self(Vector3::new(lat, lon, height))
1515
}
1616

17+
/// Get a reference to the inner array storing the data
18+
#[must_use]
19+
pub fn as_array(&self) -> &[f64; 3] {
20+
&self.0.data.0[0]
21+
}
22+
23+
/// Get a mutable reference to the inner array storing the data
24+
#[must_use]
25+
pub fn as_array_mut(&mut self) -> &mut [f64; 3] {
26+
&mut self.0.data.0[0]
27+
}
28+
29+
/// Get a reference to the inner [`Vector3`] storing the data
30+
#[must_use]
31+
pub fn as_vector(&self) -> &Vector3<f64> {
32+
&self.0
33+
}
34+
35+
/// Get a mutable reference to the inner [`Vector3`] storing the data
36+
#[must_use]
37+
pub fn as_vector_mut(&mut self) -> &mut Vector3<f64> {
38+
&mut self.0
39+
}
40+
1741
/// Get the latitude component
1842
#[must_use]
1943
pub fn latitude(&self) -> f64 {
@@ -85,6 +109,30 @@ impl From<ECEF> for LLHDegrees {
85109
}
86110
}
87111

112+
impl AsRef<[f64; 3]> for LLHDegrees {
113+
fn as_ref(&self) -> &[f64; 3] {
114+
self.as_array()
115+
}
116+
}
117+
118+
impl AsRef<Vector3<f64>> for LLHDegrees {
119+
fn as_ref(&self) -> &Vector3<f64> {
120+
self.as_vector()
121+
}
122+
}
123+
124+
impl AsMut<[f64; 3]> for LLHDegrees {
125+
fn as_mut(&mut self) -> &mut [f64; 3] {
126+
self.as_array_mut()
127+
}
128+
}
129+
130+
impl AsMut<Vector3<f64>> for LLHDegrees {
131+
fn as_mut(&mut self) -> &mut Vector3<f64> {
132+
self.as_vector_mut()
133+
}
134+
}
135+
88136
/// WGS84 geodetic coordinates (Latitude, Longitude, Height), with angles in radians.
89137
///
90138
/// Internally stored as an array of 3 [f64](std::f64) values: latitude, longitude, and height above the ellipsoid in meters
@@ -98,6 +146,30 @@ impl LLHRadians {
98146
Self(Vector3::new(lat, lon, height))
99147
}
100148

149+
/// Get a reference to the inner array storing the data
150+
#[must_use]
151+
pub fn as_array(&self) -> &[f64; 3] {
152+
&self.0.data.0[0]
153+
}
154+
155+
/// Get a mutable reference to the inner array storing the data
156+
#[must_use]
157+
pub fn as_array_mut(&mut self) -> &mut [f64; 3] {
158+
&mut self.0.data.0[0]
159+
}
160+
161+
/// Get a reference to the inner [`Vector3`] storing the data
162+
#[must_use]
163+
pub fn as_vector(&self) -> &Vector3<f64> {
164+
&self.0
165+
}
166+
167+
/// Get a mutable reference to the inner [`Vector3`] storing the data
168+
#[must_use]
169+
pub fn as_vector_mut(&mut self) -> &mut Vector3<f64> {
170+
&mut self.0
171+
}
172+
101173
/// Get the latitude component
102174
#[must_use]
103175
pub fn latitude(&self) -> f64 {
@@ -176,3 +248,27 @@ impl From<ECEF> for LLHRadians {
176248
ecef.to_llh()
177249
}
178250
}
251+
252+
impl AsRef<[f64; 3]> for LLHRadians {
253+
fn as_ref(&self) -> &[f64; 3] {
254+
self.as_array()
255+
}
256+
}
257+
258+
impl AsRef<Vector3<f64>> for LLHRadians {
259+
fn as_ref(&self) -> &Vector3<f64> {
260+
self.as_vector()
261+
}
262+
}
263+
264+
impl AsMut<[f64; 3]> for LLHRadians {
265+
fn as_mut(&mut self) -> &mut [f64; 3] {
266+
self.as_array_mut()
267+
}
268+
}
269+
270+
impl AsMut<Vector3<f64>> for LLHRadians {
271+
fn as_mut(&mut self) -> &mut Vector3<f64> {
272+
self.as_vector_mut()
273+
}
274+
}

swiftnav/src/coords/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ impl AzimuthElevation {
105105
Self(Vector2::new(az, el))
106106
}
107107

108+
/// Get a reference to the inner array storing the data
109+
#[must_use]
110+
pub fn as_array(&self) -> &[f64; 2] {
111+
&self.0.data.0[0]
112+
}
113+
114+
/// Get a mutable reference to the inner array storing the data
115+
#[must_use]
116+
pub fn as_array_mut(&mut self) -> &mut [f64; 2] {
117+
&mut self.0.data.0[0]
118+
}
119+
120+
/// Get a reference to the inner [`Vector2`] storing the data
121+
#[must_use]
122+
pub fn as_vector(&self) -> &Vector2<f64> {
123+
&self.0
124+
}
125+
126+
/// Get a mutable reference to the inner [`Vector2`] storing the data
127+
#[must_use]
128+
pub fn as_vector_mut(&mut self) -> &mut Vector2<f64> {
129+
&mut self.0
130+
}
131+
108132
/// Get the Azimuth component
109133
#[must_use]
110134
pub fn az(&self) -> f64 {
@@ -142,6 +166,30 @@ impl From<(f64, f64)> for AzimuthElevation {
142166
}
143167
}
144168

169+
impl AsRef<[f64; 2]> for AzimuthElevation {
170+
fn as_ref(&self) -> &[f64; 2] {
171+
self.as_array()
172+
}
173+
}
174+
175+
impl AsRef<Vector2<f64>> for AzimuthElevation {
176+
fn as_ref(&self) -> &Vector2<f64> {
177+
self.as_vector()
178+
}
179+
}
180+
181+
impl AsMut<[f64; 2]> for AzimuthElevation {
182+
fn as_mut(&mut self) -> &mut [f64; 2] {
183+
self.as_array_mut()
184+
}
185+
}
186+
187+
impl AsMut<Vector2<f64>> for AzimuthElevation {
188+
fn as_mut(&mut self) -> &mut Vector2<f64> {
189+
self.as_vector_mut()
190+
}
191+
}
192+
145193
/// Complete coordinate used for transforming between reference frames
146194
///
147195
/// Velocities are optional, but when present they will be transformed

swiftnav/src/coords/ned.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ impl NED {
1515
NED(Vector3::new(n, e, d))
1616
}
1717

18-
/// Get a reference to the inner [`Vector3<f64>`]
18+
/// Get a reference to the inner array storing the data
1919
#[must_use]
20-
pub(crate) fn as_vector(&self) -> &Vector3<f64> {
20+
pub fn as_array(&self) -> &[f64; 3] {
21+
&self.0.data.0[0]
22+
}
23+
24+
/// Get a mutable reference to the inner array storing the data
25+
#[must_use]
26+
pub fn as_array_mut(&mut self) -> &mut [f64; 3] {
27+
&mut self.0.data.0[0]
28+
}
29+
30+
/// Get a reference to the inner [`Vector3`] storing the data
31+
#[must_use]
32+
pub fn as_vector(&self) -> &Vector3<f64> {
2133
&self.0
2234
}
2335

36+
/// Get a mutable reference to the inner [`Vector3`] storing the data
37+
#[must_use]
38+
pub fn as_vector_mut(&mut self) -> &mut Vector3<f64> {
39+
&mut self.0
40+
}
41+
2442
/// Get the north component
2543
#[must_use]
2644
pub fn n(&self) -> f64 {
@@ -73,3 +91,27 @@ impl From<(f64, f64, f64)> for NED {
7391
Self::new(x, y, z)
7492
}
7593
}
94+
95+
impl AsRef<[f64; 3]> for NED {
96+
fn as_ref(&self) -> &[f64; 3] {
97+
self.as_array()
98+
}
99+
}
100+
101+
impl AsRef<Vector3<f64>> for NED {
102+
fn as_ref(&self) -> &Vector3<f64> {
103+
self.as_vector()
104+
}
105+
}
106+
107+
impl AsMut<[f64; 3]> for NED {
108+
fn as_mut(&mut self) -> &mut [f64; 3] {
109+
self.as_array_mut()
110+
}
111+
}
112+
113+
impl AsMut<Vector3<f64>> for NED {
114+
fn as_mut(&mut self) -> &mut Vector3<f64> {
115+
self.as_vector_mut()
116+
}
117+
}

0 commit comments

Comments
 (0)