1
- use crate :: math :: angular ;
2
- use std:: ops:: { Add , Div , Index , IndexMut , Mul , Sub } ;
1
+ use super :: * ;
2
+ use std:: ops:: { Add , Div , Mul , Sub } ;
3
3
4
4
/// Generic 3D coordinate tuple, with no fixed interpretation of the elements
5
5
#[ derive( Debug , Default , PartialEq , Copy , Clone ) ]
6
6
pub struct Coor3D ( pub [ f64 ; 3 ] ) ;
7
7
8
- // ----- O P E R A T O R T R A I T S -------------------------------------------------
8
+ impl CoordinateTuple for Coor3D {
9
+ fn new ( fill : f64 ) -> Self {
10
+ Coor3D ( [ fill; 3 ] )
11
+ }
9
12
10
- impl Index < usize > for Coor3D {
11
- type Output = f64 ;
12
- fn index ( & self , i : usize ) -> & Self :: Output {
13
- & self . 0 [ i]
13
+ fn dim ( & self ) -> usize {
14
+ 3
14
15
}
15
- }
16
16
17
- impl IndexMut < usize > for Coor3D {
18
- fn index_mut ( & mut self , i : usize ) -> & mut Self :: Output {
19
- & mut self . 0 [ i]
17
+ fn nth_unchecked ( & self , n : usize ) -> f64 {
18
+ self . 0 [ n]
19
+ }
20
+
21
+ fn set_nth_unchecked ( & mut self , n : usize , value : f64 ) {
22
+ self . 0 [ n] = value;
20
23
}
21
24
}
22
25
26
+ // ----- O P E R A T O R T R A I T S -------------------------------------------------
27
+
23
28
impl Add for Coor3D {
24
29
type Output = Self ;
25
30
fn add ( self , other : Self ) -> Self {
@@ -79,13 +84,13 @@ impl Div for Coor3D {
79
84
80
85
/// Constructors
81
86
impl Coor3D {
82
- /// A `Coor3D` from latitude/longitude/height/time , with the angular input in degrees
87
+ /// A `Coor3D` from latitude/longitude/height, with the angular input in degrees
83
88
#[ must_use]
84
89
pub fn geo ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
85
90
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
86
91
}
87
92
88
- /// A `Coor3D` from longitude/latitude/height/time , with the angular input in seconds
93
+ /// A `Coor3D` from longitude/latitude/height, with the angular input in seconds
89
94
/// of arc. Mostly for handling grid shift elements.
90
95
#[ must_use]
91
96
pub fn arcsec ( longitude : f64 , latitude : f64 , height : f64 ) -> Coor3D {
@@ -96,7 +101,7 @@ impl Coor3D {
96
101
] )
97
102
}
98
103
99
- /// A `Coor3D` from longitude/latitude/height/time , with the angular input in degrees
104
+ /// A `Coor3D` from longitude/latitude/height, with the angular input in degrees
100
105
#[ must_use]
101
106
pub fn gis ( longitude : f64 , latitude : f64 , height : f64 ) -> Coor3D {
102
107
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
@@ -108,7 +113,7 @@ impl Coor3D {
108
113
Coor3D ( [ first, second, third] )
109
114
}
110
115
111
- /// A `Coor3D` from latitude/longitude/height/time ,
116
+ /// A `Coor3D` from latitude/longitude/height,
112
117
/// with the angular input in the ISO-6709 DDDMM.mmmmm format
113
118
#[ must_use]
114
119
pub fn iso_dm ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
@@ -117,7 +122,7 @@ impl Coor3D {
117
122
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
118
123
}
119
124
120
- /// A `Coor3D` from latitude/longitude/height/time , with
125
+ /// A `Coor3D` from latitude/longitude/height, with
121
126
/// the angular input in the ISO-6709 DDDMMSS.sssss format
122
127
#[ must_use]
123
128
pub fn iso_dms ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
@@ -129,7 +134,7 @@ impl Coor3D {
129
134
/// A `Coor3D` consisting of 3 `NaN`s
130
135
#[ must_use]
131
136
pub fn nan ( ) -> Coor3D {
132
- Coor3D ( [ f64:: NAN , f64:: NAN , f64:: NAN ] )
137
+ Coor3D :: new ( f64 :: NAN ) // ([f64::NAN, f64::NAN, f64::NAN])
133
138
}
134
139
135
140
/// A `Coor3D` consisting of 3 `0`s
@@ -172,7 +177,6 @@ impl Coor3D {
172
177
#[ cfg( test) ]
173
178
mod tests {
174
179
use super :: * ;
175
- use crate :: prelude:: * ;
176
180
177
181
#[ test]
178
182
fn distances ( ) {
0 commit comments