1
- use crate :: math:: angular;
2
- use std:: ops:: { Add , Div , Index , IndexMut , Mul , Sub } ;
1
+ use super :: * ;
3
2
4
3
/// Generic 3D coordinate tuple, with no fixed interpretation of the elements
5
4
#[ derive( Debug , Default , PartialEq , Copy , Clone ) ]
6
5
pub struct Coor3D ( pub [ f64 ; 3 ] ) ;
7
6
8
- // ----- O P E R A T O R T R A I T S -------------------------------------------------
9
-
10
- impl Index < usize > for Coor3D {
11
- type Output = f64 ;
12
- fn index ( & self , i : usize ) -> & Self :: Output {
13
- & self . 0 [ i]
14
- }
15
- }
16
-
17
- impl IndexMut < usize > for Coor3D {
18
- fn index_mut ( & mut self , i : usize ) -> & mut Self :: Output {
19
- & mut self . 0 [ i]
7
+ impl CoordinateTuple for Coor3D {
8
+ fn new ( fill : f64 ) -> Self {
9
+ Coor3D ( [ fill; 3 ] )
20
10
}
21
- }
22
11
23
- impl Add for Coor3D {
24
- type Output = Self ;
25
- fn add ( self , other : Self ) -> Self {
26
- Coor3D ( [
27
- self . 0 [ 0 ] + other. 0 [ 0 ] ,
28
- self . 0 [ 1 ] + other. 0 [ 1 ] ,
29
- self . 0 [ 2 ] + other. 0 [ 2 ] ,
30
- ] )
12
+ fn dim ( & self ) -> usize {
13
+ 3
31
14
}
32
- }
33
15
34
- impl Add < & Coor3D > for Coor3D {
35
- type Output = Self ;
36
- fn add ( self , other : & Self ) -> Self {
37
- Coor3D ( [
38
- self . 0 [ 0 ] + other. 0 [ 0 ] ,
39
- self . 0 [ 1 ] + other. 0 [ 1 ] ,
40
- self . 0 [ 2 ] + other. 0 [ 2 ] ,
41
- ] )
16
+ fn nth_unchecked ( & self , n : usize ) -> f64 {
17
+ self . 0 [ n]
42
18
}
43
- }
44
19
45
- impl Sub for Coor3D {
46
- type Output = Self ;
47
- fn sub ( self , other : Self ) -> Self {
48
- Coor3D ( [
49
- self . 0 [ 0 ] - other. 0 [ 0 ] ,
50
- self . 0 [ 1 ] - other. 0 [ 1 ] ,
51
- self . 0 [ 2 ] - other. 0 [ 2 ] ,
52
- ] )
53
- }
54
- }
55
-
56
- impl Mul for Coor3D {
57
- type Output = Self ;
58
- fn mul ( self , other : Self ) -> Self {
59
- Coor3D ( [
60
- self . 0 [ 0 ] * other. 0 [ 0 ] ,
61
- self . 0 [ 1 ] * other. 0 [ 1 ] ,
62
- self . 0 [ 2 ] * other. 0 [ 2 ] ,
63
- ] )
64
- }
65
- }
66
-
67
- impl Div for Coor3D {
68
- type Output = Self ;
69
- fn div ( self , other : Self ) -> Self {
70
- Coor3D ( [
71
- self . 0 [ 0 ] / other. 0 [ 0 ] ,
72
- self . 0 [ 1 ] / other. 0 [ 1 ] ,
73
- self . 0 [ 2 ] / other. 0 [ 2 ] ,
74
- ] )
20
+ fn set_nth_unchecked ( & mut self , n : usize , value : f64 ) {
21
+ self . 0 [ n] = value;
75
22
}
76
23
}
77
24
78
25
// ----- C O N S T R U C T O R S ---------------------------------------------
79
26
80
27
/// Constructors
81
28
impl Coor3D {
82
- /// A `Coor3D` from latitude/longitude/height/time , with the angular input in degrees
29
+ /// A `Coor3D` from latitude/longitude/height, with the angular input in degrees
83
30
#[ must_use]
84
31
pub fn geo ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
85
32
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
86
33
}
87
34
88
- /// A `Coor3D` from longitude/latitude/height/time , with the angular input in seconds
35
+ /// A `Coor3D` from longitude/latitude/height, with the angular input in seconds
89
36
/// of arc. Mostly for handling grid shift elements.
90
37
#[ must_use]
91
38
pub fn arcsec ( longitude : f64 , latitude : f64 , height : f64 ) -> Coor3D {
@@ -96,7 +43,7 @@ impl Coor3D {
96
43
] )
97
44
}
98
45
99
- /// A `Coor3D` from longitude/latitude/height/time , with the angular input in degrees
46
+ /// A `Coor3D` from longitude/latitude/height, with the angular input in degrees
100
47
#[ must_use]
101
48
pub fn gis ( longitude : f64 , latitude : f64 , height : f64 ) -> Coor3D {
102
49
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
@@ -108,7 +55,7 @@ impl Coor3D {
108
55
Coor3D ( [ first, second, third] )
109
56
}
110
57
111
- /// A `Coor3D` from latitude/longitude/height/time ,
58
+ /// A `Coor3D` from latitude/longitude/height,
112
59
/// with the angular input in the ISO-6709 DDDMM.mmmmm format
113
60
#[ must_use]
114
61
pub fn iso_dm ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
@@ -117,7 +64,7 @@ impl Coor3D {
117
64
Coor3D ( [ longitude. to_radians ( ) , latitude. to_radians ( ) , height] )
118
65
}
119
66
120
- /// A `Coor3D` from latitude/longitude/height/time , with
67
+ /// A `Coor3D` from latitude/longitude/height, with
121
68
/// the angular input in the ISO-6709 DDDMMSS.sssss format
122
69
#[ must_use]
123
70
pub fn iso_dms ( latitude : f64 , longitude : f64 , height : f64 ) -> Coor3D {
@@ -129,7 +76,7 @@ impl Coor3D {
129
76
/// A `Coor3D` consisting of 3 `NaN`s
130
77
#[ must_use]
131
78
pub fn nan ( ) -> Coor3D {
132
- Coor3D ( [ f64:: NAN , f64:: NAN , f64:: NAN ] )
79
+ Coor3D :: new ( f64 :: NAN ) // ([f64::NAN, f64::NAN, f64::NAN])
133
80
}
134
81
135
82
/// A `Coor3D` consisting of 3 `0`s
@@ -172,7 +119,7 @@ impl Coor3D {
172
119
#[ cfg( test) ]
173
120
mod tests {
174
121
use super :: * ;
175
- use crate :: prelude :: * ;
122
+ use std :: ops :: { Add , Div , Mul } ;
176
123
177
124
#[ test]
178
125
fn distances ( ) {
0 commit comments