Skip to content

Commit 4c6afbb

Browse files
committed
Restore llmath improvements from archived develop branch:
* Make eligible functions constexpr * Use constants for vector indices where applicable * Reformat to match actual coding conventions
1 parent 441c844 commit 4c6afbb

28 files changed

+1879
-2111
lines changed

indra/llcommon/indra_constants.h

Lines changed: 204 additions & 204 deletions
Large diffs are not rendered by default.

indra/llcommon/lldefs.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,34 @@ constexpr U32 MAXADDRSTR = 17; // 123.567.901.345 = 15 chars + \0 +
171171

172172
// recursion tail
173173
template <typename T>
174-
inline auto llmax(T data)
174+
constexpr auto llmax(T data)
175175
{
176176
return data;
177177
}
178178

179179
template <typename T0, typename T1, typename... Ts>
180-
inline auto llmax(T0 d0, T1 d1, Ts... rest)
180+
constexpr auto llmax(T0 d0, T1 d1, Ts... rest)
181181
{
182182
auto maxrest = llmax(d1, rest...);
183183
return (d0 > maxrest)? d0 : maxrest;
184184
}
185185

186186
// recursion tail
187187
template <typename T>
188-
inline auto llmin(T data)
188+
constexpr auto llmin(T data)
189189
{
190190
return data;
191191
}
192192

193193
template <typename T0, typename T1, typename... Ts>
194-
inline auto llmin(T0 d0, T1 d1, Ts... rest)
194+
constexpr auto llmin(T0 d0, T1 d1, Ts... rest)
195195
{
196196
auto minrest = llmin(d1, rest...);
197197
return (d0 < minrest) ? d0 : minrest;
198198
}
199199

200200
template <typename A, typename MIN, typename MAX>
201-
inline A llclamp(A a, MIN minval, MAX maxval)
201+
constexpr A llclamp(A a, MIN minval, MAX maxval)
202202
{
203203
A aminval{ static_cast<A>(minval) }, amaxval{ static_cast<A>(maxval) };
204204
if ( a < aminval )
@@ -213,13 +213,13 @@ inline A llclamp(A a, MIN minval, MAX maxval)
213213
}
214214

215215
template <class LLDATATYPE>
216-
inline LLDATATYPE llclampf(LLDATATYPE a)
216+
constexpr LLDATATYPE llclampf(LLDATATYPE a)
217217
{
218218
return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(1));
219219
}
220220

221221
template <class LLDATATYPE>
222-
inline LLDATATYPE llclampb(LLDATATYPE a)
222+
constexpr LLDATATYPE llclampb(LLDATATYPE a)
223223
{
224224
return llmin(llmax(a, LLDATATYPE(0)), LLDATATYPE(255));
225225
}

indra/llcommon/stdtypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ class narrow
164164
FROM mValue;
165165

166166
public:
167-
narrow(FROM value): mValue(value) {}
167+
constexpr narrow(FROM value): mValue(value) {}
168168

169169
/*---------------------- Narrowing unsigned to signed ----------------------*/
170170
template <typename TO,
171171
typename std::enable_if<std::is_unsigned<FROM>::value &&
172172
std::is_signed<TO>::value,
173173
bool>::type = true>
174-
inline
174+
constexpr
175175
operator TO() const
176176
{
177177
// The reason we skip the
@@ -189,7 +189,7 @@ class narrow
189189
typename std::enable_if<! (std::is_unsigned<FROM>::value &&
190190
std::is_signed<TO>::value),
191191
bool>::type = true>
192-
inline
192+
constexpr
193193
operator TO() const
194194
{
195195
// two different assert()s so we can tell which condition failed

indra/llmath/llcamera.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@
3333
#include "llplane.h"
3434
#include "llvector4a.h"
3535

36-
const F32 DEFAULT_FIELD_OF_VIEW = 60.f * DEG_TO_RAD;
37-
const F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f;
38-
const F32 DEFAULT_NEAR_PLANE = 0.25f;
39-
const F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions
36+
constexpr F32 DEFAULT_FIELD_OF_VIEW = 60.f * DEG_TO_RAD;
37+
constexpr F32 DEFAULT_ASPECT_RATIO = 640.f / 480.f;
38+
constexpr F32 DEFAULT_NEAR_PLANE = 0.25f;
39+
constexpr F32 DEFAULT_FAR_PLANE = 64.f; // far reaches across two horizontal, not diagonal, regions
4040

41-
const F32 MAX_ASPECT_RATIO = 50.0f;
42-
const F32 MAX_NEAR_PLANE = 1023.9f; // Clamp the near plane just before the skybox ends
43-
const F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though.
44-
const F32 MAX_FAR_CLIP = 512.0f;
41+
constexpr F32 MAX_ASPECT_RATIO = 50.0f;
42+
constexpr F32 MAX_NEAR_PLANE = 1023.9f; // Clamp the near plane just before the skybox ends
43+
constexpr F32 MAX_FAR_PLANE = 100000.0f; //1000000.0f; // Max allowed. Not good Z precision though.
44+
constexpr F32 MAX_FAR_CLIP = 512.0f;
4545

46-
const F32 MIN_ASPECT_RATIO = 0.02f;
47-
const F32 MIN_NEAR_PLANE = 0.1f;
48-
const F32 MIN_FAR_PLANE = 0.2f;
46+
constexpr F32 MIN_ASPECT_RATIO = 0.02f;
47+
constexpr F32 MIN_NEAR_PLANE = 0.1f;
48+
constexpr F32 MIN_FAR_PLANE = 0.2f;
4949

5050
// Min/Max FOV values for square views. Call getMin/MaxView to get extremes based on current aspect ratio.
51-
static const F32 MIN_FIELD_OF_VIEW = 5.0f * DEG_TO_RAD;
52-
static const F32 MAX_FIELD_OF_VIEW = 175.f * DEG_TO_RAD;
51+
constexpr F32 MIN_FIELD_OF_VIEW = 5.0f * DEG_TO_RAD;
52+
constexpr F32 MAX_FIELD_OF_VIEW = 175.f * DEG_TO_RAD;
5353

5454
// An LLCamera is an LLCoorFrame with a view frustum.
5555
// This means that it has several methods for moving it around

indra/llmath/llcoordframe.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
#include "linden_common.h"
2828

29-
//#include "vmath.h"
3029
#include "v3math.h"
3130
#include "m3math.h"
3231
#include "v4math.h"

indra/llmath/llcoordframe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LLCoordFrame
6161
//LLCoordFrame(const F32 *origin, const F32 *rotation); // Assumes "origin" is 1x3 and "rotation" is 1x9 array
6262
//LLCoordFrame(const F32 *origin_and_rotation); // Assumes "origin_and_rotation" is 1x12 array
6363

64-
bool isFinite() { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); }
64+
bool isFinite() const { return mOrigin.isFinite() && mXAxis.isFinite() && mYAxis.isFinite() && mZAxis.isFinite(); }
6565

6666
void reset();
6767
void resetAxes();

indra/llmath/llline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "stdtypes.h"
3434
#include "v3math.h"
3535

36-
const F32 DEFAULT_INTERSECTION_ERROR = 0.000001f;
36+
constexpr F32 DEFAULT_INTERSECTION_ERROR = 0.000001f;
3737

3838
class LLLine
3939
{

indra/llmath/llmath.h

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ constexpr F32 GIMBAL_THRESHOLD = 0.000436f; // sets the gimballock threshold 0
7979
constexpr F32 FP_MAG_THRESHOLD = 0.0000001f;
8080

8181
// TODO: Replace with logic like is_approx_equal
82-
inline bool is_approx_zero( F32 f ) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
82+
constexpr bool is_approx_zero(F32 f) { return (-F_APPROXIMATELY_ZERO < f) && (f < F_APPROXIMATELY_ZERO); }
8383

8484
// These functions work by interpreting sign+exp+mantissa as an unsigned
8585
// integer.
@@ -138,33 +138,17 @@ inline F64 llabs(const F64 a)
138138
return F64(std::fabs(a));
139139
}
140140

141-
inline S32 lltrunc( F32 f )
141+
constexpr S32 lltrunc(F32 f)
142142
{
143-
#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32)
144-
// Avoids changing the floating point control word.
145-
// Add or subtract 0.5 - epsilon and then round
146-
const static U32 zpfp[] = { 0xBEFFFFFF, 0x3EFFFFFF };
147-
S32 result;
148-
__asm {
149-
fld f
150-
mov eax, f
151-
shr eax, 29
152-
and eax, 4
153-
fadd dword ptr [zpfp + eax]
154-
fistp result
155-
}
156-
return result;
157-
#else
158-
return (S32)f;
159-
#endif
143+
return narrow(f);
160144
}
161145

162-
inline S32 lltrunc( F64 f )
146+
constexpr S32 lltrunc(F64 f)
163147
{
164-
return (S32)f;
148+
return narrow(f);
165149
}
166150

167-
inline S32 llfloor( F32 f )
151+
inline S32 llfloor(F32 f)
168152
{
169153
#if LL_WINDOWS && !defined( __INTEL_COMPILER ) && (ADDRESS_SIZE == 32)
170154
// Avoids changing the floating point control word.
@@ -274,7 +258,7 @@ constexpr F32 FAST_MAG_BETA = 0.397824734759f;
274258
//constexpr F32 FAST_MAG_ALPHA = 0.948059448969f;
275259
//constexpr F32 FAST_MAG_BETA = 0.392699081699f;
276260

277-
inline F32 fastMagnitude(F32 a, F32 b)
261+
constexpr F32 fastMagnitude(F32 a, F32 b)
278262
{
279263
a = (a > 0) ? a : -a;
280264
b = (b > 0) ? b : -b;
@@ -332,7 +316,7 @@ inline F32 llfastpow(const F32 x, const F32 y)
332316
}
333317

334318

335-
inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
319+
constexpr F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
336320
{
337321
// compute the power of ten
338322
F32 bar = 1.f;
@@ -350,25 +334,25 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs)
350334

351335
using std::lerp;
352336

353-
inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
337+
constexpr F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v)
354338
{
355339
F32 a = x00 + (x01-x00)*u;
356340
F32 b = x10 + (x11-x10)*u;
357341
F32 r = a + (b-a)*v;
358342
return r;
359343
}
360344

361-
inline F32 ramp(F32 x, F32 a, F32 b)
345+
constexpr F32 ramp(F32 x, F32 a, F32 b)
362346
{
363347
return (a == b) ? 0.0f : ((a - x) / (a - b));
364348
}
365349

366-
inline F32 rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
350+
constexpr F32 rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
367351
{
368352
return lerp(y1, y2, ramp(x, x1, x2));
369353
}
370354

371-
inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
355+
constexpr F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
372356
{
373357
if (y1 < y2)
374358
{
@@ -381,7 +365,7 @@ inline F32 clamp_rescale(F32 x, F32 x1, F32 x2, F32 y1, F32 y2)
381365
}
382366

383367

384-
inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
368+
constexpr F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
385369
{
386370
if (x <= x0)
387371
return s0;
@@ -394,14 +378,14 @@ inline F32 cubic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
394378
return s0 + (s1 - s0) * (f * f) * (3.0f - 2.0f * f);
395379
}
396380

397-
inline F32 cubic_step( F32 x )
381+
constexpr F32 cubic_step( F32 x )
398382
{
399383
x = llclampf(x);
400384

401385
return (x * x) * (3.0f - 2.0f * x);
402386
}
403387

404-
inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
388+
constexpr F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
405389
{
406390
if (x <= x0)
407391
return s0;
@@ -415,7 +399,7 @@ inline F32 quadratic_step( F32 x, F32 x0, F32 x1, F32 s0, F32 s1 )
415399
return (s0 * (1.f - f_squared)) + ((s1 - s0) * f_squared);
416400
}
417401

418-
inline F32 llsimple_angle(F32 angle)
402+
constexpr F32 llsimple_angle(F32 angle)
419403
{
420404
while(angle <= -F_PI)
421405
angle += F_TWO_PI;
@@ -425,7 +409,7 @@ inline F32 llsimple_angle(F32 angle)
425409
}
426410

427411
//SDK - Renamed this to get_lower_power_two, since this is what this actually does.
428-
inline U32 get_lower_power_two(U32 val, U32 max_power_two)
412+
constexpr U32 get_lower_power_two(U32 val, U32 max_power_two)
429413
{
430414
if(!max_power_two)
431415
{
@@ -447,7 +431,7 @@ inline U32 get_lower_power_two(U32 val, U32 max_power_two)
447431
// number of digits, then add one. We subtract 1 initially to handle
448432
// the case where the number passed in is actually a power of two.
449433
// WARNING: this only works with 32 bit ints.
450-
inline U32 get_next_power_two(U32 val, U32 max_power_two)
434+
constexpr U32 get_next_power_two(U32 val, U32 max_power_two)
451435
{
452436
if(!max_power_two)
453437
{
@@ -473,7 +457,7 @@ inline U32 get_next_power_two(U32 val, U32 max_power_two)
473457
//get the gaussian value given the linear distance from axis x and guassian value o
474458
inline F32 llgaussian(F32 x, F32 o)
475459
{
476-
return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2*o*o));
460+
return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2.f*o*o));
477461
}
478462

479463
//helper function for removing outliers
@@ -526,7 +510,8 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
526510
// Note: in our code, values labeled as sRGB are ALWAYS gamma corrected linear values, NOT linear values with monitor gamma applied
527511
// Note: stored color values should always be gamma corrected linear (i.e. the values returned from an on-screen color swatch)
528512
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses
529-
inline float linearTosRGB(const float val) {
513+
inline float linearTosRGB(const float val)
514+
{
530515
if (val < 0.0031308f) {
531516
return val * 12.92f;
532517
}
@@ -541,7 +526,8 @@ inline float linearTosRGB(const float val) {
541526
// Note: Stored color values should generally be gamma corrected sRGB.
542527
// If you're serializing the return value of this function, you're probably doing it wrong.
543528
// Note: DO NOT cache the conversion. This leads to error prone synchronization and is actually slower in the typical case due to cache misses.
544-
inline float sRGBtoLinear(const float val) {
529+
inline float sRGBtoLinear(const float val)
530+
{
545531
if (val < 0.04045f) {
546532
return val / 12.92f;
547533
}

indra/llmath/llquaternion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include "llquaternion.h"
3232

33-
//#include "vmath.h"
3433
#include "v3math.h"
3534
#include "v3dmath.h"
3635
#include "v4math.h"

indra/llmath/llvolume.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class LLVolumeOctree;
4545

4646
#include "lluuid.h"
4747
#include "v4color.h"
48-
//#include "vmath.h"
4948
#include "v2math.h"
5049
#include "v3math.h"
5150
#include "v3dmath.h"

0 commit comments

Comments
 (0)