psen_scan_internal_angle.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
17 #include <cmath>
18 
19 namespace psen_scan
20 {
26 Degree::Degree(const double& angle) : angle_(angle)
27 {
28 }
29 
35 Degree::Degree(const Degree& angle) : angle_(static_cast<double>(angle))
36 {
37 }
38 
44 Degree::Degree(const PSENscanInternalAngle& angle) : angle_(static_cast<int>(angle) / 10.)
45 {
46 }
47 
53 Degree::operator double() const noexcept
54 {
55  return angle_;
56 }
57 
64 bool Degree::operator<(const Degree& rhs) const
65 {
66  return angle_ < rhs.angle_;
67 }
68 
75 bool Degree::operator>(const Degree& rhs) const
76 {
77  return angle_ > rhs.angle_;
78 }
79 
86 bool Degree::operator==(const Degree& rhs) const
87 {
88  return angle_ == rhs.angle_;
89 }
90 
97 Degree& Degree::operator*=(const double& rhs)
98 {
99  angle_ *= rhs;
100  return *this;
101 }
102 
109 Degree Degree::operator*(const double& rhs)
110 {
111  Degree ret(*this);
112  ret *= rhs;
113  return ret;
114 }
115 
123 {
124  angle_ -= rhs.angle_;
125  return *this;
126 }
127 
135 {
136  Degree ret(*this);
137  ret -= rhs;
138  return ret;
139 }
140 
147 {
148  Degree ret(*this);
149  ret.angle_ = -ret.angle_;
150  return ret;
151 }
152 
160 std::ostream& operator<<(std::ostream& os, const Degree& deg)
161 {
162  return os << deg.angle_;
163 }
164 
171 {
172 }
173 
180 {
181 }
182 
189  : angle_(static_cast<int>(round(static_cast<double>(angle) * 10.)))
190 {
191  if ((angle_ / 10.) != round(static_cast<double>(angle) * 10.) / 10.)
192  {
193  throw std::overflow_error("Degree cannot be converted to PSENscanInternalAngle.");
194  }
195 }
196 
202 PSENscanInternalAngle::operator int() const noexcept
203 {
204  return angle_;
205 }
206 
214 {
215  return angle_ < rhs.angle_;
216 }
217 
225 {
226  return angle_ > rhs.angle_;
227 }
228 
236 {
237  return angle_ <= rhs.angle_;
238 }
239 
247 {
248  return angle_ >= rhs.angle_;
249 }
250 
258 {
259  return angle_ == rhs.angle_;
260 }
261 
269 {
270  return angle_ != rhs.angle_;
271 }
272 
280 {
281  angle_ -= rhs.angle_;
282  return *this;
283 }
284 
292 {
293  PSENscanInternalAngle ret(*this);
294  ret -= rhs;
295  return ret;
296 }
297 
304 {
305  PSENscanInternalAngle ret(*this);
306  ret.angle_ = -ret.angle_;
307  return ret;
308 }
309 
317 {
318  angle_ += rhs.angle_;
319  return *this;
320 }
321 
329 {
330  PSENscanInternalAngle ret(*this);
331  ret += rhs;
332  return ret;
333 }
334 
342 std::ostream& operator<<(std::ostream& os, const PSENscanInternalAngle& deg)
343 {
344  return os << deg.angle_;
345 }
346 } // namespace psen_scan
bool operator==(const Degree &rhs) const
Compare a Degree object with another Degree object.
Degree operator*(const double &rhs)
Multiply a Degree object by a double precision floating point number.
bool operator>(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...
Degree & operator*=(const double &rhs)
Define multiplying a Degree object by a double precision floating point number.
Class to model angles in degrees from user&#39;s perspective.
bool operator>(const Degree &rhs) const
Compare a Degree object with another Degree object.
Degree & operator-=(const Degree &rhs)
Define subtracting a Degree object by another Degree.
Degree operator-()
Unary Minus Operator switches the sign of the angle.
PSENscanInternalAngle(const PSENscanInternalAngle &angle)
Construct a new PSENscanInternalAngle::PSENscanInternalAngle object from another PSENscanInternalAngl...
PSENscanInternalAngle operator-=(const PSENscanInternalAngle &rhs)
Define subtracting a PSENscanInternalAngle object by another PSENscanInternalAngle.
bool operator!=(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...
PSENscanInternalAngle operator+(const PSENscanInternalAngle &rhs) const
Add a PSENscanInternalAngle object to another PSENscanInternalAngle.
bool operator<=(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...
friend std::ostream & operator<<(std::ostream &os, const PSENscanInternalAngle &deg)
Define how PSENscanInternalAngle should behave with stream operator.
Degree(const Degree &angle)
Construct a new Degree:: Degree object from another Degree object.
friend std::ostream & operator<<(std::ostream &os, const Degree &deg)
Define how Degree should behave with stream operator.
bool operator<(const Degree &rhs) const
Compare a Degree object with another Degree object.
PSENscanInternalAngle operator-()
Unary Minus Operator to switch the sign of the Degree.
PSENscanInternalAngle operator+=(const PSENscanInternalAngle &rhs)
Define adding a PSENscanInternalAngle object to another PSENscanInternalAngle.
bool operator<(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...
Class to model angles in PSENscan internal format (tenth of degrees)
bool operator>=(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...
bool operator==(const PSENscanInternalAngle &rhs) const
Compare a PSENscanInternalAngle object with another PSENscanInternalAngle object. ...


psen_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:16:20