|
|
@@ -8,14 +8,14 @@ use cgmath::{Point3};
|
|
8
|
8
|
/// latitude: [-90.0, 90.0]
|
|
9
|
9
|
/// longitude: [-180, 180.0]
|
|
10
|
10
|
#[derive(Copy, Debug, PartialEq, Clone)]
|
|
11
|
|
-pub struct LatLon {
|
|
|
11
|
+pub struct LatLonDeg {
|
|
12
|
12
|
pub lat: f64,
|
|
13
|
13
|
pub lon: f64,
|
|
14
|
14
|
}
|
|
15
|
15
|
|
|
16
|
|
-impl LatLon {
|
|
|
16
|
+impl LatLonDeg {
|
|
17
|
17
|
pub fn new(lat: f64, lon: f64) -> Self {
|
|
18
|
|
- LatLon { lat, lon }
|
|
|
18
|
+ LatLonDeg { lat, lon }
|
|
19
|
19
|
}
|
|
20
|
20
|
|
|
21
|
21
|
pub fn to_radians(&self) -> LatLonRad {
|
|
|
@@ -42,9 +42,9 @@ impl LatLonRad {
|
|
42
|
42
|
LatLonRad { lat, lon }
|
|
43
|
43
|
}
|
|
44
|
44
|
|
|
45
|
|
- pub fn to_degrees(&self) -> LatLon {
|
|
|
45
|
+ pub fn to_degrees(&self) -> LatLonDeg {
|
|
46
|
46
|
let f = 180.0 * FRAC_1_PI;
|
|
47
|
|
- LatLon {
|
|
|
47
|
+ LatLonDeg {
|
|
48
|
48
|
lat: self.lat * f,
|
|
49
|
49
|
lon: self.lon * f,
|
|
50
|
50
|
}
|
|
|
@@ -89,9 +89,9 @@ pub struct MapCoord {
|
|
89
|
89
|
pub y: f64,
|
|
90
|
90
|
}
|
|
91
|
91
|
|
|
92
|
|
-impl From<LatLon> for MapCoord
|
|
|
92
|
+impl From<LatLonDeg> for MapCoord
|
|
93
|
93
|
{
|
|
94
|
|
- fn from(pos: LatLon) -> MapCoord {
|
|
|
94
|
+ fn from(pos: LatLonDeg) -> MapCoord {
|
|
95
|
95
|
let x = pos.lon * (1.0 / 360.0) + 0.5;
|
|
96
|
96
|
let pi_lat = pos.lat * (PI / 180.0);
|
|
97
|
97
|
let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 * FRAC_1_PI) + 0.5;
|
|
|
@@ -146,8 +146,8 @@ impl MapCoord {
|
|
146
|
146
|
}
|
|
147
|
147
|
}
|
|
148
|
148
|
|
|
149
|
|
- pub fn to_latlon_deg(&self) -> LatLon {
|
|
150
|
|
- LatLon {
|
|
|
149
|
+ pub fn to_latlon_deg(&self) -> LatLonDeg {
|
|
|
150
|
+ LatLonDeg {
|
|
151
|
151
|
lat: (PI - self.y * (2.0 * PI)).sinh().atan() * (180.0 * FRAC_1_PI),
|
|
152
|
152
|
lon: self.x * 360.0 - 180.0,
|
|
153
|
153
|
}
|
|
|
@@ -476,7 +476,7 @@ mod tests {
|
|
476
|
476
|
#[test]
|
|
477
|
477
|
fn degree_radians() {
|
|
478
|
478
|
{
|
|
479
|
|
- let rad = LatLon::new(0.0, 0.0).to_radians();
|
|
|
479
|
+ let rad = LatLonDeg::new(0.0, 0.0).to_radians();
|
|
480
|
480
|
assert!(approx_eq(rad.lat, 0.0));
|
|
481
|
481
|
assert!(approx_eq(rad.lon, 0.0));
|
|
482
|
482
|
let deg = rad.to_degrees();
|
|
|
@@ -484,7 +484,7 @@ mod tests {
|
|
484
|
484
|
assert!(approx_eq(deg.lon, 0.0));
|
|
485
|
485
|
}
|
|
486
|
486
|
{
|
|
487
|
|
- let rad = LatLon::new(-45.0, 180.0).to_radians();
|
|
|
487
|
+ let rad = LatLonDeg::new(-45.0, 180.0).to_radians();
|
|
488
|
488
|
assert!(approx_eq(rad.lat, -PI / 4.0));
|
|
489
|
489
|
assert!(approx_eq(rad.lon, PI));
|
|
490
|
490
|
let deg = rad.to_degrees();
|
|
|
@@ -493,7 +493,7 @@ mod tests {
|
|
493
|
493
|
}
|
|
494
|
494
|
|
|
495
|
495
|
{
|
|
496
|
|
- let mc = MapCoord::from(LatLon::new(23.45, 123.45));
|
|
|
496
|
+ let mc = MapCoord::from(LatLonDeg::new(23.45, 123.45));
|
|
497
|
497
|
let deg = mc.to_latlon_rad().to_degrees();
|
|
498
|
498
|
assert!(approx_eq(deg.lat, 23.45));
|
|
499
|
499
|
assert!(approx_eq(deg.lon, 123.45));
|