dioxus_leaflet/types/
latlng.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Serialize, Deserialize)]
4pub struct LatLng {
5 pub lat: f64,
6 pub lng: f64,
7 pub alt: Option<f64>,
8}
9
10impl LatLng {
11 pub const fn new(lat: f64, lng: f64) -> Self {
12 Self { lat, lng, alt: None }
13 }
14}
15
16impl std::ops::Add for LatLng {
17 type Output = LatLng;
18 fn add(self, rhs: Self) -> Self::Output {
19 Self {
20 lat: self.lat + rhs.lat,
21 lng: self.lng + rhs.lng,
22 alt: match (self.alt, rhs.alt) {
23 (Some(a), Some(b)) => Some(a + b),
24 (Some(a), None) => Some(a),
25 (None, Some(b)) => Some(b),
26 (None, None) => None,
27 },
28 }
29 }
30}
31
32impl std::ops::AddAssign for LatLng {
33 fn add_assign(&mut self, rhs: Self) {
34 self.lat += rhs.lat;
35 self.lng += rhs.lng;
36 self.alt = match (self.alt, rhs.alt) {
37 (Some(a), Some(b)) => Some(a + b),
38 (Some(a), None) => Some(a),
39 (None, Some(b)) => Some(b),
40 (None, None) => None,
41 };
42 }
43}