distance.h Source File

CPP API: distance.h Source File
distance.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Kilian Volmer, Rene Schmiedling
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_GEOGRAPHY_DISTANCE_H
21 #define MIO_GEOGRAPHY_DISTANCE_H
22 
23 #include "memilio/config.h"
25 
26 namespace mio
27 {
28 
29 namespace geo
30 {
31 
36 class Distance
37 {
38 public:
42  Distance() = default;
47  explicit constexpr Distance(ScalarType meters)
48  : m_meters(meters)
49  {
50  }
51 
56  {
57  return ScalarType(m_meters) / 1000;
58  }
59 
64  {
65  return m_meters;
66  }
67 
72  bool operator==(const Distance& other) const
73  {
74  return m_meters == other.m_meters;
75  }
76  bool operator!=(const Distance& other) const
77  {
78  return !(*this == other);
79  }
80  bool operator<(const Distance& other) const
81  {
82  return m_meters < other.m_meters;
83  }
84  bool operator<=(const Distance& other) const
85  {
86  return m_meters <= other.m_meters;
87  }
88  bool operator>(const Distance& other) const
89  {
90  return m_meters > other.m_meters;
91  }
92  bool operator>=(const Distance& other) const
93  {
94  return m_meters >= other.m_meters;
95  }
102  Distance operator+(const Distance& m) const
103  {
104  return Distance{m_meters + m.meters()};
105  }
107  {
108  m_meters += m.meters();
109  return *this;
110  }
111  Distance operator-(const Distance& m) const
112  {
113  return Distance{m_meters - m.meters()};
114  }
116  {
117  m_meters -= m.meters();
118  return *this;
119  }
124  {
125  return Members("Distance").add("meters", m_meters);
126  }
127 
128 private:
130 };
131 
136 constexpr inline Distance meters(ScalarType meters)
137 {
138  return Distance(meters);
139 }
140 
146 {
147  return Distance(kilometers * 1000);
148 }
149 
150 } // namespace geo
151 } // namespace mio
152 
153 #endif // MIO_GEOGRAPHY_DISTANCE_H
Represents a distance.
Definition: distance.h:37
bool operator==(const Distance &other) const
Definition: distance.h:72
bool operator>(const Distance &other) const
Definition: distance.h:88
Distance operator-(const Distance &m) const
Add or subtract a Distance.
Definition: distance.h:111
Distance operator+(const Distance &m) const
Add or subtract a Distance.
Definition: distance.h:102
bool operator>=(const Distance &other) const
Definition: distance.h:92
Distance & operator-=(const Distance &m)
Add or subtract a Distance.
Definition: distance.h:115
auto default_serialize()
This method is used by the default serialization feature.
Definition: distance.h:123
ScalarType meters() const
return distance in meters.
Definition: distance.h:63
ScalarType kilometers() const
return distance in kilometers.
Definition: distance.h:55
constexpr Distance(ScalarType meters)
Creates a Distance from a specified distance in meters.
Definition: distance.h:47
bool operator<(const Distance &other) const
Definition: distance.h:80
bool operator!=(const Distance &other) const
Definition: distance.h:76
Distance()=default
Default ctor, unitinialized.
ScalarType m_meters
The distance in meters.
Definition: distance.h:129
bool operator<=(const Distance &other) const
Definition: distance.h:84
Distance & operator+=(const Distance &m)
Add or subtract a Distance.
Definition: distance.h:106
double ScalarType
Configuration of memilio library.
Definition: memilio/config.h:30
constexpr Distance kilometers(ScalarType kilometers)
Create a Distance of a specified number of kilometers.
Definition: distance.h:145
constexpr Distance meters(ScalarType meters)
Create a Distance of a specified number of meters.
Definition: distance.h:136
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
List of a class's members.
Definition: default_serialize.h:113
Members< ValueTypes..., T > add(const char *member_name, T &member)
Add a class member.
Definition: default_serialize.h:139