2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "utils/Archive.h"
12 #include "utils/StringUtils.h"
22 CSpeed::CSpeed(const CSpeed
& speed
)
24 m_value
= speed
.m_value
;
25 m_valid
= speed
.m_valid
;
28 CSpeed::CSpeed(double value
)
34 bool CSpeed::operator >(const CSpeed
& right
) const
37 assert(right
.IsValid());
39 if (!IsValid() || !right
.IsValid())
45 return (m_value
> right
.m_value
);
48 bool CSpeed::operator >=(const CSpeed
& right
) const
50 return operator >(right
) || operator ==(right
);
53 bool CSpeed::operator <(const CSpeed
& right
) const
56 assert(right
.IsValid());
58 if (!IsValid() || !right
.IsValid())
64 return (m_value
< right
.m_value
);
67 bool CSpeed::operator <=(const CSpeed
& right
) const
69 return operator <(right
) || operator ==(right
);
72 bool CSpeed::operator ==(const CSpeed
& right
) const
75 assert(right
.IsValid());
77 if (!IsValid() || !right
.IsValid())
83 return (m_value
== right
.m_value
);
86 bool CSpeed::operator !=(const CSpeed
& right
) const
88 return !operator ==(right
.m_value
);
91 CSpeed
& CSpeed::operator =(const CSpeed
& right
)
93 m_valid
= right
.m_valid
;
94 m_value
= right
.m_value
;
98 const CSpeed
& CSpeed::operator +=(const CSpeed
& right
)
101 assert(right
.IsValid());
103 m_value
+= right
.m_value
;
107 const CSpeed
& CSpeed::operator -=(const CSpeed
& right
)
110 assert(right
.IsValid());
112 m_value
-= right
.m_value
;
116 const CSpeed
& CSpeed::operator *=(const CSpeed
& right
)
119 assert(right
.IsValid());
121 m_value
*= right
.m_value
;
125 const CSpeed
& CSpeed::operator /=(const CSpeed
& right
)
128 assert(right
.IsValid());
130 m_value
/= right
.m_value
;
134 CSpeed
CSpeed::operator +(const CSpeed
& right
) const
137 assert(right
.IsValid());
141 if (!IsValid() || !right
.IsValid())
142 temp
.SetValid(false);
144 temp
.m_value
+= right
.m_value
;
149 CSpeed
CSpeed::operator -(const CSpeed
& right
) const
152 assert(right
.IsValid());
155 if (!IsValid() || !right
.IsValid())
156 temp
.SetValid(false);
158 temp
.m_value
-= right
.m_value
;
163 CSpeed
CSpeed::operator *(const CSpeed
& right
) const
166 assert(right
.IsValid());
169 if (!IsValid() || !right
.IsValid())
170 temp
.SetValid(false);
172 temp
.m_value
*= right
.m_value
;
176 CSpeed
CSpeed::operator /(const CSpeed
& right
) const
179 assert(right
.IsValid());
182 if (!IsValid() || !right
.IsValid())
183 temp
.SetValid(false);
185 temp
.m_value
/= right
.m_value
;
189 CSpeed
& CSpeed::operator ++()
197 CSpeed
& CSpeed::operator --()
205 CSpeed
CSpeed::operator ++(int)
214 CSpeed
CSpeed::operator --(int)
223 bool CSpeed::operator >(double right
) const
230 return (m_value
> right
);
233 bool CSpeed::operator >=(double right
) const
235 return operator >(right
) || operator ==(right
);
238 bool CSpeed::operator <(double right
) const
245 return (m_value
< right
);
248 bool CSpeed::operator <=(double right
) const
250 return operator <(right
) || operator ==(right
);
253 bool CSpeed::operator ==(double right
) const
258 return (m_value
== right
);
261 bool CSpeed::operator !=(double right
) const
263 return !operator ==(right
);
266 const CSpeed
& CSpeed::operator +=(double right
)
274 const CSpeed
& CSpeed::operator -=(double right
)
282 const CSpeed
& CSpeed::operator *=(double right
)
290 const CSpeed
& CSpeed::operator /=(double right
)
298 CSpeed
CSpeed::operator +(double right
) const
303 temp
.m_value
+= right
;
307 CSpeed
CSpeed::operator -(double right
) const
312 temp
.m_value
-= right
;
316 CSpeed
CSpeed::operator *(double right
) const
321 temp
.m_value
*= right
;
325 CSpeed
CSpeed::operator /(double right
) const
330 temp
.m_value
/= right
;
334 CSpeed
CSpeed::CreateFromKilometresPerHour(double value
)
336 return CSpeed(value
/ 3.6);
339 CSpeed
CSpeed::CreateFromMetresPerMinute(double value
)
341 return CSpeed(value
/ 60.0);
344 CSpeed
CSpeed::CreateFromMetresPerSecond(double value
)
346 return CSpeed(value
);
349 CSpeed
CSpeed::CreateFromFeetPerHour(double value
)
351 return CreateFromFeetPerMinute(value
/ 60.0);
354 CSpeed
CSpeed::CreateFromFeetPerMinute(double value
)
356 return CreateFromFeetPerSecond(value
/ 60.0);
359 CSpeed
CSpeed::CreateFromFeetPerSecond(double value
)
361 return CSpeed(value
/ 3.280839895);
364 CSpeed
CSpeed::CreateFromMilesPerHour(double value
)
366 return CSpeed(value
/ 2.236936292);
369 CSpeed
CSpeed::CreateFromKnots(double value
)
371 return CSpeed(value
/ 1.943846172);
374 CSpeed
CSpeed::CreateFromBeaufort(unsigned int value
)
389 return CSpeed(12.35);
391 return CSpeed(15.55);
393 return CSpeed(18.95);
397 return CSpeed(26.45);
404 CSpeed
CSpeed::CreateFromInchPerSecond(double value
)
406 return CSpeed(value
/ 39.37007874);
409 CSpeed
CSpeed::CreateFromYardPerSecond(double value
)
411 return CSpeed(value
/ 1.093613298);
414 CSpeed
CSpeed::CreateFromFurlongPerFortnight(double value
)
416 return CSpeed(value
/ 6012.885613871);
419 void CSpeed::Archive(CArchive
& ar
)
433 bool CSpeed::IsValid() const
438 double CSpeed::ToKilometresPerHour() const
440 return m_value
* 3.6;
443 double CSpeed::ToMetresPerMinute() const
445 return m_value
* 60.0;
448 double CSpeed::ToMetresPerSecond() const
453 double CSpeed::ToFeetPerHour() const
455 return ToFeetPerMinute() * 60.0;
458 double CSpeed::ToFeetPerMinute() const
460 return ToFeetPerSecond() * 60.0;
463 double CSpeed::ToFeetPerSecond() const
465 return m_value
* 3.280839895;
468 double CSpeed::ToMilesPerHour() const
470 return m_value
* 2.236936292;
473 double CSpeed::ToKnots() const
475 return m_value
* 1.943846172;
478 double CSpeed::ToBeaufort() const
482 if (m_value
>= 0.3 && m_value
< 1.5)
484 if (m_value
>= 1.5 && m_value
< 3.3)
486 if (m_value
>= 3.3 && m_value
< 5.5)
488 if (m_value
>= 5.5 && m_value
< 8.0)
490 if (m_value
>= 8.0 && m_value
< 10.8)
492 if (m_value
>= 10.8 && m_value
< 13.9)
494 if (m_value
>= 13.9 && m_value
< 17.2)
496 if (m_value
>= 17.2 && m_value
< 20.7)
498 if (m_value
>= 20.7 && m_value
< 24.5)
500 if (m_value
>= 24.5 && m_value
< 28.4)
502 if (m_value
>= 28.4 && m_value
< 32.6)
508 double CSpeed::ToInchPerSecond() const
510 return m_value
* 39.37007874;
513 double CSpeed::ToYardPerSecond() const
515 return m_value
* 1.093613298;
518 double CSpeed::ToFurlongPerFortnight() const
520 return m_value
* 6012.885613871;
523 double CSpeed::To(Unit speedUnit
) const
532 case UnitKilometresPerHour
:
533 value
= ToKilometresPerHour();
535 case UnitMetresPerMinute
:
536 value
= ToMetresPerMinute();
538 case UnitMetresPerSecond
:
539 value
= ToMetresPerSecond();
541 case UnitFeetPerHour
:
542 value
= ToFeetPerHour();
544 case UnitFeetPerMinute
:
545 value
= ToFeetPerMinute();
547 case UnitFeetPerSecond
:
548 value
= ToFeetPerSecond();
550 case UnitMilesPerHour
:
551 value
= ToMilesPerHour();
557 value
= ToBeaufort();
559 case UnitInchPerSecond
:
560 value
= ToInchPerSecond();
562 case UnitYardPerSecond
:
563 value
= ToYardPerSecond();
565 case UnitFurlongPerFortnight
:
566 value
= ToFurlongPerFortnight();
575 // Returns temperature as localized string
576 std::string
CSpeed::ToString(Unit speedUnit
) const
581 return StringUtils::Format("{:2.0f}", To(speedUnit
));