1
1
use super :: * ;
2
2
use crate :: math:: angular;
3
- use std:: ops:: { Index , IndexMut } ;
4
3
5
4
/// Generic 2D Coordinate tuple, with no fixed interpretation of the elements
6
5
#[ derive( Debug , Default , PartialEq , Copy , Clone ) ]
7
6
pub struct Coor2D ( pub [ f64 ; 2 ] ) ;
8
7
9
- // ----- O P E R A T O R T R A I T S -------------------------------------------------
8
+ use std :: ops :: { Index , IndexMut } ;
10
9
11
10
impl Index < usize > for Coor2D {
12
11
type Output = f64 ;
@@ -21,34 +20,6 @@ impl IndexMut<usize> for Coor2D {
21
20
}
22
21
}
23
22
24
- // ----- A N G U L A R U N I T S -------------------------------------------
25
-
26
- impl AngularUnits for Coor2D {
27
- /// Transform the elements of a `Coor2D` from degrees to radians
28
- #[ must_use]
29
- fn to_radians ( self ) -> Self {
30
- Coor2D ( [ self [ 0 ] . to_radians ( ) , self [ 1 ] . to_radians ( ) ] )
31
- }
32
-
33
- /// Transform the elements of a `Coor2D` from radians to degrees
34
- #[ must_use]
35
- fn to_degrees ( self ) -> Self {
36
- Coor2D ( [ self [ 0 ] . to_degrees ( ) , self [ 1 ] . to_degrees ( ) ] )
37
- }
38
-
39
- /// Transform the elements of a `Coor2D` from radians to seconds of arc.
40
- #[ must_use]
41
- fn to_arcsec ( self ) -> Self {
42
- Coor2D ( [ self [ 0 ] . to_degrees ( ) * 3600. , self [ 1 ] . to_degrees ( ) * 3600. ] )
43
- }
44
-
45
- /// Transform the internal lon/lat-in-radians to lat/lon-in-degrees
46
- #[ must_use]
47
- fn to_geo ( self ) -> Self {
48
- Coor2D ( [ self [ 1 ] . to_degrees ( ) , self [ 0 ] . to_degrees ( ) ] )
49
- }
50
- }
51
-
52
23
// ----- C O N S T R U C T O R S ---------------------------------------------
53
24
54
25
/// Constructors
@@ -127,53 +98,13 @@ impl Coor2D {
127
98
/// Multiply by a scalar
128
99
#[ must_use]
129
100
pub fn scale ( & self , factor : f64 ) -> Coor2D {
130
- Coor2D ( [ self [ 0 ] * factor, self [ 1 ] * factor] )
101
+ Coor2D ( [ self . x ( ) * factor, self . y ( ) * factor] )
131
102
}
132
103
133
104
/// Scalar product
134
105
#[ must_use]
135
106
pub fn dot ( & self , other : Coor2D ) -> f64 {
136
- self [ 0 ] * other[ 0 ] + self [ 1 ] * other[ 1 ]
137
- }
138
- }
139
-
140
- // ----- D I S T A N C E S ---------------------------------------------------
141
-
142
- impl Coor2D {
143
- /// Euclidean distance between two points in the 2D plane.
144
- ///
145
- /// Primarily used to compute the distance between two projected points
146
- /// in their projected plane. Typically, this distance will differ from
147
- /// the actual distance in the real world.
148
- ///
149
- /// # See also:
150
- ///
151
- /// [`distance`](crate::ellipsoid::Ellipsoid::distance)
152
- ///
153
- /// # Examples
154
- ///
155
- /// ```
156
- /// use geodesy::prelude::*;
157
- /// let t = 1000 as f64;
158
- /// let p0 = Coor2D::origin();
159
- /// let p1 = Coor2D::raw(t, t);
160
- /// assert_eq!(p0.hypot2(&p1), t.hypot(t));
161
- /// ```
162
- #[ must_use]
163
- pub fn hypot2 ( & self , other : & Self ) -> f64 {
164
- ( self [ 0 ] - other[ 0 ] ) . hypot ( self [ 1 ] - other[ 1 ] )
165
- }
166
- }
167
-
168
- impl From < Coor2D > for Coor4D {
169
- fn from ( c : Coor2D ) -> Self {
170
- Coor4D ( [ c[ 0 ] , c[ 1 ] , 0.0 , 0.0 ] )
171
- }
172
- }
173
-
174
- impl From < Coor4D > for Coor2D {
175
- fn from ( xyzt : Coor4D ) -> Self {
176
- Coor2D ( [ xyzt[ 0 ] , xyzt[ 1 ] ] )
107
+ self . x ( ) * other. x ( ) + self . y ( ) * other. y ( )
177
108
}
178
109
}
179
110
@@ -197,16 +128,15 @@ mod tests {
197
128
let c = Coor2D :: raw ( 12. , 55. ) . to_radians ( ) ;
198
129
let d = Coor2D :: gis ( 12. , 55. ) ;
199
130
assert_eq ! ( c, d) ;
200
- assert_eq ! ( d[ 0 ] , 12f64 . to_radians( ) ) ;
201
- let e = d. to_degrees ( ) ;
202
- assert_eq ! ( e[ 0 ] , c. to_degrees( ) [ 0 ] ) ;
131
+ assert_eq ! ( d. x( ) , 12f64 . to_radians( ) ) ;
132
+ assert_eq ! ( d. x( ) . to_degrees( ) , c. x( ) . to_degrees( ) ) ;
203
133
}
204
134
205
135
#[ test]
206
136
fn array ( ) {
207
137
let b = Coor2D :: raw ( 7. , 8. ) ;
208
- let c = [ b[ 0 ] , b[ 1 ] , f64:: NAN , f64:: NAN ] ;
209
- assert_eq ! ( b[ 0 ] , c[ 0 ] ) ;
138
+ let c = [ b. x ( ) , b. y ( ) , f64:: NAN , f64:: NAN ] ;
139
+ assert_eq ! ( b. x ( ) , c[ 0 ] ) ;
210
140
}
211
141
212
142
#[ test]
0 commit comments