diff options
Diffstat (limited to 'src/gpx.rs')
-rw-r--r-- | src/gpx.rs | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -22,7 +22,8 @@ impl Coordinates { let lambda = self.longitude.to_radians(); let phi = self.latitude.to_radians(); let x = 2u64.pow(zoom) as f64 / (2.0 * PI) * 256.0 * (lambda + PI); - let y = 2u64.pow(zoom) as f64 / (2.0 * PI) * 256.0 * (PI - (PI / 4.0 + phi / 2.0).tan().ln()); + let y = + 2u64.pow(zoom) as f64 / (2.0 * PI) * 256.0 * (PI - (PI / 4.0 + phi / 2.0).tan().ln()); (x.floor() as u64, y.floor() as u64) } } @@ -45,13 +46,18 @@ pub fn extract_from_str(input: &str) -> Result<Vec<Coordinates>> { for node in document.root_element().children().filter(is_track_node) { for segment in node.children().filter(is_track_segment) { for point in segment.children().filter(is_track_point) { - let latitude = point.attribute("lat") + let latitude = point + .attribute("lat") .and_then(|l| l.parse::<f64>().ok()) .ok_or_else(|| eyre!("Invalid latitude"))?; - let longitude = point.attribute("lon") + let longitude = point + .attribute("lon") .and_then(|l| l.parse::<f64>().ok()) .ok_or_else(|| eyre!("Invalid longitude"))?; - result.push(Coordinates { latitude, longitude }); + result.push(Coordinates { + latitude, + longitude, + }); } } } @@ -63,7 +69,10 @@ pub enum Compression { None, } -pub fn extract_from_file<P: AsRef<Path>>(path: P, _compression: Compression) -> Result<Vec<Coordinates>> { +pub fn extract_from_file<P: AsRef<Path>>( + path: P, + _compression: Compression, +) -> Result<Vec<Coordinates>> { let content = fs::read_to_string(path)?; extract_from_str(&content) } |