libosmscout  1.1.1
Bearing.h
Go to the documentation of this file.
1 #ifndef LIBOSMSCOUT_BEARING_H
2 #define LIBOSMSCOUT_BEARING_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2019 Lukáš Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
25 #include <osmscout/system/Math.h>
26 
27 #include <string>
28 #include <ostream>
29 
30 namespace osmscout {
31 
32  class OSMSCOUT_API Bearing CLASS_FINAL
33  {
34  private:
35  double radians=0.0;
36 
37  private:
38  explicit Bearing(double radians):
39  radians(Normalise(radians))
40  { }
41 
42  public:
43  Bearing() = default;
44  ~Bearing() = default;
45 
46  Bearing(const Bearing &d) = default;
47 
48  Bearing& operator=(const Bearing &d) = default;
49 
50  Bearing(Bearing &&d) noexcept
51  {
52  std::swap(radians, d.radians);
53  }
54 
55  Bearing &operator=(Bearing &&d) noexcept
56  {
57  std::swap(radians, d.radians);
58  return *this;
59  }
60 
64  double AsRadians() const
65  {
66  return radians;
67  }
68 
72  double AsDegrees() const
73  {
74  return radians*180.0/M_PI;
75  }
76 
77  Bearing operator-(const Bearing &d) const
78  {
79  return Bearing(radians-d.radians);
80  }
81 
82  Bearing operator+(const Bearing &d) const
83  {
84  return Bearing(radians+d.radians);
85  }
86 
87  Bearing operator*(const double &d) const
88  {
89  return Bearing(radians * d);
90  }
91 
92  Bearing operator/(const double &d) const
93  {
94  return Bearing(radians / d);
95  }
96 
101  std::string DisplayString() const;
102 
107  std::string LongDisplayString() const;
108 
109  bool operator==(const Bearing& o) const
110  {
111  return radians == o.radians;
112  }
113 
114  bool operator!=(const Bearing& o) const
115  {
116  return radians != o.radians;
117  }
118 
119  inline static Bearing Radians(double radians)
120  {
121  return Bearing(radians);
122  }
123 
124  inline static Bearing Degrees(double degrees)
125  {
126  return Bearing(degrees*M_PI/180.0);
127  }
128 
129  private:
130  static double Normalise(double radians);
131  };
132 
133 }
134 
135 #endif //LIBOSMSCOUT_BEARING_H
Bearing(Bearing &&d) noexcept
Definition: Bearing.h:50
Bearing operator*(const double &d) const
Definition: Bearing.h:87
static Bearing Degrees(double degrees)
Definition: Bearing.h:124
Bearing operator/(const double &d) const
Definition: Bearing.h:92
Definition: Area.h:38
double AsDegrees() const
Definition: Bearing.h:72
Bearing operator-(const Bearing &d) const
Definition: Bearing.h:77
bool operator!=(const Bearing &o) const
Definition: Bearing.h:114
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
static Bearing Radians(double radians)
Definition: Bearing.h:119
Bearing operator+(const Bearing &d) const
Definition: Bearing.h:82
double AsRadians() const
Definition: Bearing.h:64
bool operator==(const Bearing &o) const
Definition: Bearing.h:109
Bearing & operator=(Bearing &&d) noexcept
Definition: Bearing.h:55