Vector2.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3  * Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #ifndef PLAYRHO_COMMON_VECTOR2_HPP
23 #define PLAYRHO_COMMON_VECTOR2_HPP
24 
28 
29 namespace playrho {
30 
33 template <typename T>
35 
40 
44 
48 
52 
56 
59 
62 
66 
69 {
70  return value;
71 }
72 
74 template <>
75 PLAYRHO_CONSTEXPR inline Vec2 GetInvalid() noexcept
76 {
77  return Vec2{GetInvalid<Vec2::value_type>(), GetInvalid<Vec2::value_type>()};
78 }
79 
81 template <typename TYPE>
82 PLAYRHO_CONSTEXPR inline bool IsValid(const Vector2<TYPE>& value) noexcept
83 {
84  return IsValid(get<0>(value)) && IsValid(get<1>(value));
85 }
86 
87 #ifdef USE_BOOST_UNITS
88 template <>
90 PLAYRHO_CONSTEXPR inline Length2 GetInvalid() noexcept
91 {
92  return Length2{GetInvalid<Length>(), GetInvalid<Length>()};
93 }
94 
96 template <>
98 {
99  return LinearVelocity2{GetInvalid<LinearVelocity>(), GetInvalid<LinearVelocity>()};
100 }
101 
103 template <>
104 PLAYRHO_CONSTEXPR inline Force2 GetInvalid() noexcept
105 {
106  return Force2{GetInvalid<Force>(), GetInvalid<Force>()};
107 }
108 
110 template <>
111 PLAYRHO_CONSTEXPR inline Momentum2 GetInvalid() noexcept
112 {
113  return Momentum2{GetInvalid<Momentum>(), GetInvalid<Momentum>()};
114 }
115 
116 PLAYRHO_CONSTEXPR inline Vec2 GetVec2(const Length2 value)
117 {
118  return Vec2{
119  get<0>(value) / Meter,
120  get<1>(value) / Meter
121  };
122 }
123 
124 PLAYRHO_CONSTEXPR inline Vec2 GetVec2(const LinearVelocity2 value)
125 {
126  return Vec2{
127  get<0>(value) / MeterPerSecond,
128  get<1>(value) / MeterPerSecond
129  };
130 }
131 
132 PLAYRHO_CONSTEXPR inline Vec2 GetVec2(const Momentum2 value)
133 {
134  return Vec2{
135  get<0>(value) / (Kilogram * MeterPerSecond),
136  get<1>(value) / (Kilogram * MeterPerSecond)
137  };
138 }
139 
140 PLAYRHO_CONSTEXPR inline Vec2 GetVec2(const Force2 value)
141 {
142  return Vec2{
143  get<0>(value) / Newton,
144  get<1>(value) / Newton
145  };
146 }
147 #endif
148 
149 namespace d2 {
150 
155  0_mps2, EarthlyLinearAcceleration};
156 
157 } // namespace d2
158 } // namespace playrho
159 
160 #endif // PLAYRHO_COMMON_VECTOR2_HPP