Merge lp:~unity-team/nux/nux.constants-namespace into lp:nux/2.0
- nux.constants-namespace
- Merge into 2.0
Proposed by
Jay Taoko
Status: | Merged |
---|---|
Approved by: | Jay Taoko |
Approved revision: | 579 |
Merged at revision: | 578 |
Proposed branch: | lp:~unity-team/nux/nux.constants-namespace |
Merge into: | lp:nux/2.0 |
Diff against target: |
373 lines (+67/-95) 9 files modified
Nux/Coverflow.cpp (+3/-3) NuxCore/Math/Algo.cpp (+2/-2) NuxCore/Math/Constants.cpp (+22/-20) NuxCore/Math/Constants.h (+16/-46) NuxCore/Math/MathUtility.h (+4/-4) NuxCore/Math/Matrix4.h (+1/-1) NuxCore/Math/Trigonometry.cpp (+7/-7) NuxCore/Math/Tweening.cpp (+11/-11) configure.ac (+1/-1) |
To merge this branch: | bzr merge lp:~unity-team/nux/nux.constants-namespace |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jay Taoko (community) | Approve | ||
Review via email: mp+93723@code.launchpad.net |
Commit message
Description of the change
* Added namespace nux::constants for constant values such as pi.
To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/Coverflow.cpp' |
2 | --- Nux/Coverflow.cpp 2012-02-13 10:15:35 +0000 |
3 | +++ Nux/Coverflow.cpp 2012-02-19 04:29:19 +0000 |
4 | @@ -44,7 +44,7 @@ |
5 | { |
6 | float EaseSin(float x) |
7 | { |
8 | - return sin(x * nux::Const::pi / 2.0f); |
9 | + return sin(x * nux::constants::pi / 2.0f); |
10 | } |
11 | |
12 | float RoundFloor(float x) |
13 | @@ -666,13 +666,13 @@ |
14 | |
15 | if (x < flat_left) |
16 | { |
17 | - cover.position.rot = (atan((x - flat_left) * parent_->folding_rate) / (nux::Const::pi / 2)) * -parent_->folding_angle; |
18 | + cover.position.rot = (atan((x - flat_left) * parent_->folding_rate) / (nux::constants::pi / 2)) * -parent_->folding_angle; |
19 | float scale_in_factor = neg_pinch + (1.0f - (std::abs(cover.position.rot) / parent_->folding_angle)) * parent_->pinching; |
20 | cover.position.x = flat_left - ((flat_left - x) * scale_in_factor); |
21 | } |
22 | else if (x > flat_right) |
23 | { |
24 | - cover.position.rot = (atan((x - flat_right) * parent_->folding_rate) / (nux::Const::pi / 2)) * -parent_->folding_angle; |
25 | + cover.position.rot = (atan((x - flat_right) * parent_->folding_rate) / (nux::constants::pi / 2)) * -parent_->folding_angle; |
26 | float scale_in_factor = neg_pinch+ (1.0f - (std::abs(cover.position.rot) / parent_->folding_angle)) * parent_->pinching; |
27 | cover.position.x = flat_right + ((x - flat_right) * scale_in_factor); |
28 | } |
29 | |
30 | === modified file 'NuxCore/Math/Algo.cpp' |
31 | --- NuxCore/Math/Algo.cpp 2011-04-06 21:54:09 +0000 |
32 | +++ NuxCore/Math/Algo.cpp 2012-02-19 04:29:19 +0000 |
33 | @@ -1,5 +1,5 @@ |
34 | /* |
35 | - * Copyright 2010 Inalogic® Inc. |
36 | + * Copyright 2010-2012 Inalogic® Inc. |
37 | * |
38 | * This program is free software: you can redistribute it and/or modify it |
39 | * under the terms of the GNU Lesser General Public License, as |
40 | @@ -81,7 +81,7 @@ |
41 | double xinters = (pt.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x; |
42 | |
43 | //overlies on a ray |
44 | - if(fabs(pt.x - xinters) < Const::dbl_epsilon) return onedge; |
45 | + if(fabs(pt.x - xinters) < constants::dbl_epsilon) return onedge; |
46 | |
47 | //before ray |
48 | if(pt.x < xinters) ++__count; |
49 | |
50 | === modified file 'NuxCore/Math/Constants.cpp' |
51 | --- NuxCore/Math/Constants.cpp 2011-04-06 21:54:09 +0000 |
52 | +++ NuxCore/Math/Constants.cpp 2012-02-19 04:29:19 +0000 |
53 | @@ -1,5 +1,5 @@ |
54 | /* |
55 | - * Copyright 2010 Inalogic® Inc. |
56 | + * Copyright 2010-2012 Inalogic® Inc. |
57 | * |
58 | * This program is free software: you can redistribute it and/or modify it |
59 | * under the terms of the GNU Lesser General Public License, as |
60 | @@ -19,36 +19,38 @@ |
61 | * |
62 | */ |
63 | |
64 | - |
65 | #include "../NuxCore.h" |
66 | #include "Constants.h" |
67 | |
68 | +#include <limits> |
69 | namespace nux |
70 | { |
71 | - const float Const::pi = 3.1415926535f; |
72 | - const float Const::Pi = 3.1415926535f; |
73 | - const float Const::e = 2.7182817f; |
74 | - const float Const::sqrt2 = 1.414214f; |
75 | - const float Const::sqrt3 = 1.732051f; |
76 | - const float Const::golden = 1.618034f; |
77 | + namespace constants |
78 | + { |
79 | + const float pi = 3.1415926535f; |
80 | + const float e = 2.7182817f; |
81 | + const float sqrt2 = 1.414214f; |
82 | + const float sqrt3 = 1.732051f; |
83 | + const float golden = 1.618034f; |
84 | |
85 | - const double Const::EpsilonMilli = 0.001; |
86 | - const double Const::EpsilonMicro = 0.000001; |
87 | - const double Const::EpsilonNano = 0.000000001; |
88 | - const double Const::EpsilonPico = 0.000000000001; |
89 | - const double Const::EpsilonFemto = 0.000000000000001; |
90 | + const double epsilon_milli = 0.001; |
91 | + const double epsilon_micro = 0.000001; |
92 | + const double epsilon_nano = 0.000000001; |
93 | + const double epsilon_pico = 0.000000000001; |
94 | + const double epsilon_femto = 0.000000000000001; |
95 | |
96 | #if defined(NUX_OS_WINDOWS) |
97 | - const float Const::flt_epsilon = FLT_EPSILON; |
98 | - const float Const::dbl_epsilon = DBL_EPSILON; |
99 | + const float flt_epsilon = FLT_EPSILON; |
100 | + const double dbl_epsilon = DBL_EPSILON; |
101 | #elif defined(NUX_OS_LINUX) |
102 | - const float Const::flt_epsilon = __FLT_EPSILON__; |
103 | - const float Const::dbl_epsilon = __DBL_EPSILON__; |
104 | + const float flt_epsilon = __FLT_EPSILON__; |
105 | + const double dbl_epsilon = __DBL_EPSILON__; |
106 | #elif defined(NUX_OS_MACOSX) |
107 | - const float Const::dbl_epsilon = _FLT_EPSILON_; |
108 | - const float Const::dbl_epsilon = _DBL_EPSILON_; |
109 | + const float dbl_epsilon = _FLT_EPSILON_; |
110 | + const double dbl_epsilon = _DBL_EPSILON_; |
111 | #else |
112 | - #error Undefined OS. |
113 | +#error Undefined OS. |
114 | #endif |
115 | |
116 | + } // namespace constants |
117 | } |
118 | |
119 | === modified file 'NuxCore/Math/Constants.h' |
120 | --- NuxCore/Math/Constants.h 2011-04-06 21:54:09 +0000 |
121 | +++ NuxCore/Math/Constants.h 2012-02-19 04:29:19 +0000 |
122 | @@ -1,5 +1,5 @@ |
123 | /* |
124 | - * Copyright 2010 Inalogic® Inc. |
125 | + * Copyright 2010-2012 Inalogic® Inc. |
126 | * |
127 | * This program is free software: you can redistribute it and/or modify it |
128 | * under the terms of the GNU Lesser General Public License, as |
129 | @@ -19,57 +19,27 @@ |
130 | * |
131 | */ |
132 | |
133 | - |
134 | #ifndef CONSTANTS_H |
135 | #define CONSTANTS_H |
136 | |
137 | -#include <limits> |
138 | - |
139 | -/* |
140 | -PI with 500 decimals (from http://www.ex.ac.uk/cimt/general/pi10000.htm) |
141 | - |
142 | - 3.1415926535 8979323846 2643383279 5028841971 6939937510 |
143 | - 5820974944 5923078164 0628620899 8628034825 3421170679 |
144 | - 8214808651 3282306647 0938446095 5058223172 5359408128 |
145 | - 4811174502 8410270193 8521105559 6446229489 5493038196 |
146 | - 4428810975 6659334461 2847564823 3786783165 2712019091 |
147 | - 4564856692 3460348610 4543266482 1339360726 0249141273 |
148 | - 7245870066 0631558817 4881520920 9628292540 9171536436 |
149 | - 7892590360 0113305305 4882046652 1384146951 9415116094 |
150 | - 3305727036 5759591953 0921861173 8193261179 3105118548 |
151 | - 0744623799 6274956735 1885752724 8912279381 8301194912 |
152 | -*/ |
153 | -// 2.7182818284590452353602874713526624977572470936999595749669676277 |
154 | - |
155 | - |
156 | - |
157 | namespace nux |
158 | { |
159 | - |
160 | - class Const |
161 | + namespace constants |
162 | { |
163 | - public: |
164 | - static const float pi; |
165 | - static const float Pi; |
166 | - static const float e; |
167 | - static const float sqrt2; |
168 | - static const float sqrt3; |
169 | - static const float golden; |
170 | - |
171 | - static const double EpsilonMilli; |
172 | - static const double EpsilonMicro; |
173 | - static const double EpsilonNano; |
174 | - static const double EpsilonPico; |
175 | - static const double EpsilonFemto; |
176 | - |
177 | - static const float flt_epsilon; |
178 | - static const float dbl_epsilon; |
179 | - |
180 | - private: |
181 | - Const(); |
182 | - ~Const(); |
183 | - Const (const Const &); |
184 | - Const &operator = (const Const &); |
185 | + extern const float pi; |
186 | + extern const float e; |
187 | + extern const float sqrt2; |
188 | + extern const float sqrt3; |
189 | + extern const float golden; |
190 | + |
191 | + extern const double epsilon_milli; |
192 | + extern const double epsilon_micro; |
193 | + extern const double epsilon_nano; |
194 | + extern const double epsilon_pico; |
195 | + extern const double epsilon_femto; |
196 | + |
197 | + extern const float flt_epsilon; |
198 | + extern const double dbl_epsilon; |
199 | }; |
200 | |
201 | } |
202 | |
203 | === modified file 'NuxCore/Math/MathUtility.h' |
204 | --- NuxCore/Math/MathUtility.h 2012-02-19 00:02:14 +0000 |
205 | +++ NuxCore/Math/MathUtility.h 2012-02-19 04:29:19 +0000 |
206 | @@ -1,5 +1,5 @@ |
207 | /* |
208 | - * Copyright 2010 Inalogic® Inc. |
209 | + * Copyright 2010-2012 Inalogic® Inc. |
210 | * |
211 | * This program is free software: you can redistribute it and/or modify it |
212 | * under the terms of the GNU Lesser General Public License, as |
213 | @@ -32,8 +32,8 @@ |
214 | |
215 | #include "Constants.h" |
216 | |
217 | -#define DEGTORAD(d) (d) * nux::Const::pi / 180.0f |
218 | -#define RADTODEG(d) (d) * 180.0f / nux::Const::pi |
219 | +#define DEGTORAD(d) (d) * nux::constants::pi / 180.0f |
220 | +#define RADTODEG(d) (d) * 180.0f / nux::constants::pi |
221 | |
222 | namespace nux |
223 | { |
224 | @@ -164,7 +164,7 @@ |
225 | */ |
226 | inline double RandomGaussian() |
227 | { |
228 | - return std::sqrt (-2 * std::log ((double) (1e-10 + (1 - 2e-10) * std::rand()))) * std::cos ((double) (2 * 3.14f/*Const::pi*/*std::rand())); |
229 | + return std::sqrt (-2 * std::log ((double) (1e-10 + (1 - 2e-10) * std::rand()))) * std::cos ((double) (2 * constants::pi * std::rand())); |
230 | } |
231 | |
232 | inline unsigned int RandomUInt() |
233 | |
234 | === modified file 'NuxCore/Math/Matrix4.h' |
235 | --- NuxCore/Math/Matrix4.h 2012-01-17 04:34:19 +0000 |
236 | +++ NuxCore/Math/Matrix4.h 2012-02-19 04:29:19 +0000 |
237 | @@ -1230,7 +1230,7 @@ |
238 | // note: adapted from david eberly's code without permission |
239 | //TODO: make sure it is correct |
240 | |
241 | - if (axis.LengthSquared() < Const::EpsilonMicro) |
242 | + if (axis.LengthSquared() < constants::epsilon_micro) |
243 | { |
244 | Identity(); |
245 | } |
246 | |
247 | === modified file 'NuxCore/Math/Trigonometry.cpp' |
248 | --- NuxCore/Math/Trigonometry.cpp 2011-04-06 21:54:09 +0000 |
249 | +++ NuxCore/Math/Trigonometry.cpp 2012-02-19 04:29:19 +0000 |
250 | @@ -1,5 +1,5 @@ |
251 | /* |
252 | - * Copyright 2010 Inalogic® Inc. |
253 | + * Copyright 2010-2012 Inalogic® Inc. |
254 | * |
255 | * This program is free software: you can redistribute it and/or modify it |
256 | * under the terms of the GNU Lesser General Public License, as |
257 | @@ -34,9 +34,9 @@ |
258 | Vector3 SphericalToCartesianXBaseDeg (float r, float theta, float phi) |
259 | { |
260 | Vector3 v; |
261 | - v.x = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); |
262 | - v.y = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); |
263 | - v.z = r * std::cos (phi * Const::pi / 180.0f); |
264 | + v.x = r * std::cos (theta * constants::pi / 180.0f) * std::sin (phi * constants::pi / 180.0f); |
265 | + v.y = r * std::sin (theta * constants::pi / 180.0f) * std::sin (phi * constants::pi / 180.0f); |
266 | + v.z = r * std::cos (phi * constants::pi / 180.0f); |
267 | return v; |
268 | } |
269 | |
270 | @@ -56,9 +56,9 @@ |
271 | Vector3 SphericalToCartesianZBaseDeg (float r, float theta, float phi) |
272 | { |
273 | Vector3 v; |
274 | - v.z = r * std::cos (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); |
275 | - v.x = r * std::sin (theta * Const::pi / 180.0f) * std::sin (phi * Const::pi / 180.0f); |
276 | - v.y = r * std::cos (phi * Const::pi / 180.0f); |
277 | + v.z = r * std::cos (theta * constants::pi / 180.0f) * std::sin (phi * constants::pi / 180.0f); |
278 | + v.x = r * std::sin (theta * constants::pi / 180.0f) * std::sin (phi * constants::pi / 180.0f); |
279 | + v.y = r * std::cos (phi * constants::pi / 180.0f); |
280 | return v; |
281 | } |
282 | |
283 | |
284 | === modified file 'NuxCore/Math/Tweening.cpp' |
285 | --- NuxCore/Math/Tweening.cpp 2011-04-06 21:54:09 +0000 |
286 | +++ NuxCore/Math/Tweening.cpp 2012-02-19 04:29:19 +0000 |
287 | @@ -1,5 +1,5 @@ |
288 | /* |
289 | - * Copyright 2010 Inalogic® Inc. |
290 | + * Copyright 2010-2012 Inalogic® Inc. |
291 | * |
292 | * This program is free software: you can redistribute it and/or modify it |
293 | * under the terms of the GNU Lesser General Public License, as |
294 | @@ -166,10 +166,10 @@ |
295 | s = p / 4; |
296 | } |
297 | else |
298 | - s = p / (2 * nux::Const::pi) * std::asin (c / a); |
299 | + s = p / (2 * constants::pi) * std::asin (c / a); |
300 | |
301 | t -= 1.0; |
302 | - return - (a * std::pow (2, 10 * t) * std::sin ( (t * d - s) * (2 * nux::Const::pi) / p ) ) + b; |
303 | + return - (a * std::pow (2, 10 * t) * std::sin ( (t * d - s) * (2 * constants::pi) / p ) ) + b; |
304 | } |
305 | |
306 | double ElasticEaseOut (double t, double b, double c, double d, double a, double p) |
307 | @@ -191,9 +191,9 @@ |
308 | s = p / 4; |
309 | } |
310 | else |
311 | - s = p / (2 * nux::Const::pi) * std::asin (c / a); |
312 | + s = p / (2 * constants::pi) * std::asin (c / a); |
313 | |
314 | - return (a * std::pow (2, -10 * t) * std::sin ( (t * d - s) * (2 * nux::Const::pi) / p ) + c + b); |
315 | + return (a * std::pow (2, -10 * t) * std::sin ( (t * d - s) * (2 * constants::pi) / p ) + c + b); |
316 | } |
317 | |
318 | double ElasticEaseInOut (double t, double b, double c, double d, double a, double p) |
319 | @@ -216,17 +216,17 @@ |
320 | } |
321 | else |
322 | { |
323 | - s = p / (2 * nux::Const::pi) * std::asin (c / a); |
324 | + s = p / (2 * constants::pi) * std::asin (c / a); |
325 | } |
326 | |
327 | if (t < 1.0) |
328 | { |
329 | t -= 1; |
330 | - return -0.5 * (a * std::pow (2, 10.0 * t) * std::sin ( (t * d - s) * (2 * nux::Const::pi) / p ) ) + b; |
331 | + return -0.5 * (a * std::pow (2, 10.0 * t) * std::sin ( (t * d - s) * (2 * constants::pi) / p ) ) + b; |
332 | } |
333 | |
334 | t -= 1; |
335 | - return a * std::pow (2, -10 * t) * std::sin ( (t * d - s) * (2 * nux::Const::pi) / p ) * .5 + c + b; |
336 | + return a * std::pow (2, -10 * t) * std::sin ( (t * d - s) * (2 * constants::pi) / p ) * .5 + c + b; |
337 | } |
338 | |
339 | // Expo |
340 | @@ -350,17 +350,17 @@ |
341 | // Sine |
342 | double SineEaseIn (double t, double b, double c, double d) |
343 | { |
344 | - return -c * std::cos (t / d * (nux::Const::pi / 2) ) + c + b; |
345 | + return -c * std::cos (t / d * (constants::pi / 2) ) + c + b; |
346 | } |
347 | |
348 | double SineEaseOut (double t, double b, double c, double d) |
349 | { |
350 | - return c * std::sin (t / d * (nux::Const::pi / 2) ) + b; |
351 | + return c * std::sin (t / d * (constants::pi / 2) ) + b; |
352 | } |
353 | |
354 | double SineEaseInOut (double t, double b, double c, double d) |
355 | { |
356 | - return -c / 2 * (std::cos (nux::Const::pi * t / d) - 1) + b; |
357 | + return -c / 2 * (std::cos (constants::pi * t / d) - 1) + b; |
358 | } |
359 | |
360 | } |
361 | |
362 | === modified file 'configure.ac' |
363 | --- configure.ac 2012-02-19 00:02:14 +0000 |
364 | +++ configure.ac 2012-02-19 04:29:19 +0000 |
365 | @@ -22,7 +22,7 @@ |
366 | # The number format is : year/month/day |
367 | # e.g.: december 5th, 2011 is: 20111205 |
368 | # To make more than one API change in a day, add a number to the date. Like 20111205.xx |
369 | -m4_define([nux_abi_version], [20120218.01]) |
370 | +m4_define([nux_abi_version], [20120218.02]) |
371 | |
372 | m4_define([nux_version], |
373 | [nux_major_version.nux_minor_version.nux_micro_version]) |