From 015ff3d6083a6ea6f7d9e30b22cfe080c81c04a5 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 26 Sep 2024 09:22:09 -0400 Subject: #include rather than "math.h" to avoid lerp() conflict. GCC on Linux complains that "math.h", which hoists all the standard library math functions into the global namespace for classic C compatibility, creates a conflict between `std::lerp()` and the `lerp()` function in llmath.h. (Perhaps we should just replace our `lerp()` definition with `using std::lerp;`) Anyway, bringing in rather than "math.h" leaves standard library math functions in the `std` namespace, avoiding the conflict. --- indra/llmath/raytrace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llmath') diff --git a/indra/llmath/raytrace.cpp b/indra/llmath/raytrace.cpp index 893bf1fc70..1251ab9f8d 100644 --- a/indra/llmath/raytrace.cpp +++ b/indra/llmath/raytrace.cpp @@ -26,7 +26,7 @@ #include "linden_common.h" -#include "math.h" +#include //#include "vmath.h" #include "v3math.h" #include "llquaternion.h" -- cgit v1.2.3 From 6400284278071b774d2837d62142a15b94120198 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 26 Sep 2024 09:42:14 -0400 Subject: Ditch our own (conflicting) definition of the lerp() function. Hoist `std::lerp()` into the global namespace instead. --- indra/llmath/llmath.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index fa315291a3..09b685a68b 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -358,10 +358,9 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs) return new_foo; } -inline F32 lerp(F32 a, F32 b, F32 u) -{ - return a + ((b - a) * u); -} +// We used to define a simple lerp(F32, F32, F32) that probably predated +// std::lerp(). By now, do we need our own definition any longer? +using std::lerp; inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v) { -- cgit v1.2.3 From d7f6b96e36c3cadb7a2731c6417709ee9668f2d7 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 26 Sep 2024 12:35:27 -0400 Subject: Reinstate our lerp() function, avoid "math.h" header. For reasons that remain unclear, MSVC likes our lerp() function better than its own std::lerp() function: publishing the latter into the global namespace, instead of defining our own, produces fatal argument conversion warnings. "math.h" publishes all of into the global namespace, which causes a GCC conflict between std::lerp() and our lerp() function. Including instead leaves std::lerp() in the std namespace, eliminating the conflict. --- indra/llmath/llinterp.h | 4 ++-- indra/llmath/llmath.h | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llinterp.h b/indra/llmath/llinterp.h index f4faa82a82..386679ffe9 100644 --- a/indra/llmath/llinterp.h +++ b/indra/llmath/llinterp.h @@ -29,11 +29,11 @@ #if defined(LL_WINDOWS) // macro definitions for common math constants (e.g. M_PI) are declared under the _USE_MATH_DEFINES // on Windows system. -// So, let's define _USE_MATH_DEFINES before including math.h +// So, let's define _USE_MATH_DEFINES before including cmath #define _USE_MATH_DEFINES #endif -#include "math.h" +#include // Class from which different types of interpolators can be derived diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index 09b685a68b..75284ef57e 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -358,9 +358,14 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs) return new_foo; } -// We used to define a simple lerp(F32, F32, F32) that probably predated -// std::lerp(). By now, do we need our own definition any longer? -using std::lerp; +// Even though there's now a std::lerp() function that appears to do the same +// as this function, for some reason MSVC likes this one better. Publishing +// std::lerp() into the global namespace instead of defining this function +// results in fatal argument conversion warnings. +inline F32 lerp(F32 a, F32 b, F32 u) +{ + return a + ((b - a) * u); +} inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v) { -- cgit v1.2.3 From 8a6da4d6210192ada4a26ddd397c00d78b08dfcc Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 26 Sep 2024 13:48:58 -0400 Subject: Rename our lerp() to flerp(); call where MSVC balks at std::lerp(). Now the lerp() in global namespace is std::lerp(), but it remains true that for some calls to std::lerp(), MSVC issues fatal argument conversion warnings. In those places, call flerp() (our historic lerp()) instead. --- indra/llmath/llmath.h | 8 ++++---- indra/llmath/llvolume.cpp | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index 75284ef57e..1d6d986207 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -358,11 +358,11 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs) return new_foo; } +using std::lerp; // Even though there's now a std::lerp() function that appears to do the same -// as this function, for some reason MSVC likes this one better. Publishing -// std::lerp() into the global namespace instead of defining this function -// results in fatal argument conversion warnings. -inline F32 lerp(F32 a, F32 b, F32 u) +// as this function, in some cases MSVC likes this one better: some calls to +// std::lerp() produce fatal argument conversion warnings. +inline F32 flerp(F32 a, F32 b, F32 u) { return a + ((b - a) * u); } diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 700e61467b..275e5bcb43 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -1294,9 +1294,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + lerp(0,params.getShear().mV[0],s) - + lerp(-skew ,skew, t) * 0.5f, - c + lerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) + + flerp(-skew ,skew, t) * 0.5f, + c + flerp(0,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), hole_y * lerp(taper_y_begin, taper_y_end, t), @@ -1327,9 +1327,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); s = sin(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + lerp(0,params.getShear().mV[0],s) - + lerp(-skew ,skew, t) * 0.5f, - c + lerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) + + flerp(-skew ,skew, t) * 0.5f, + c + flerp(0,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), @@ -1354,9 +1354,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); s = sin(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + lerp(0,params.getShear().mV[0],s) - + lerp(-skew ,skew, t) * 0.5f, - c + lerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) + + flerp(-skew ,skew, t) * 0.5f, + c + flerp(0,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), hole_y * lerp(taper_y_begin, taper_y_end, t), @@ -1494,8 +1494,8 @@ bool LLPath::generate(const LLPathParams& params, F32 detail, S32 split, for (S32 i=0;i Date: Fri, 27 Sep 2024 03:35:42 +0200 Subject: Fix lerp issues and eliminate flerp in favor of std::lerp (#2712) --- indra/llmath/llmath.h | 9 +-------- indra/llmath/llvolume.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 22 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index 1d6d986207..0348dad8fe 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -359,13 +359,6 @@ inline F32 snap_to_sig_figs(F32 foo, S32 sig_figs) } using std::lerp; -// Even though there's now a std::lerp() function that appears to do the same -// as this function, in some cases MSVC likes this one better: some calls to -// std::lerp() produce fatal argument conversion warnings. -inline F32 flerp(F32 a, F32 b, F32 u) -{ - return a + ((b - a) * u); -} inline F32 lerp2d(F32 x00, F32 x01, F32 x10, F32 x11, F32 u, F32 v) { @@ -490,7 +483,7 @@ inline U32 get_next_power_two(U32 val, U32 max_power_two) //get the gaussian value given the linear distance from axis x and guassian value o inline F32 llgaussian(F32 x, F32 o) { - return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2*o*o)); + return 1.f/(F_SQRT_TWO_PI*o)*powf(F_E, -(x*x)/(2.f*o*o)); } //helper function for removing outliers diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 275e5bcb43..00a56edf68 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -1294,9 +1294,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) - + flerp(-skew ,skew, t) * 0.5f, - c + flerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + lerp(0.f,params.getShear().mV[0],s) + + lerp(-skew ,skew, t) * 0.5f, + c + lerp(0.f,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), hole_y * lerp(taper_y_begin, taper_y_end, t), @@ -1327,9 +1327,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); s = sin(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) - + flerp(-skew ,skew, t) * 0.5f, - c + flerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + lerp(0.f,params.getShear().mV[0],s) + + lerp(-skew ,skew, t) * 0.5f, + c + lerp(0.f,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), @@ -1354,9 +1354,9 @@ void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 en c = cos(ang)*lerp(radius_start, radius_end, t); s = sin(ang)*lerp(radius_start, radius_end, t); - pt->mPos.set(0 + flerp(0,params.getShear().mV[0],s) - + flerp(-skew ,skew, t) * 0.5f, - c + flerp(0,params.getShear().mV[1],s), + pt->mPos.set(0 + lerp(0.f,params.getShear().mV[0],s) + + lerp(-skew ,skew, t) * 0.5f, + c + lerp(0.f,params.getShear().mV[1],s), s); pt->mScale.set(hole_x * lerp(taper_x_begin, taper_x_end, t), hole_y * lerp(taper_y_begin, taper_y_end, t), @@ -1494,8 +1494,8 @@ bool LLPath::generate(const LLPathParams& params, F32 detail, S32 split, for (S32 i=0;i Date: Fri, 27 Sep 2024 05:38:39 -0400 Subject: Migrate ~LLPointer()'s peculiar warning case to llpointer.cpp. This allows removing #include "llerror.h" from llpointer.h. Also remove #include "llmutex.h" as a heavy way to get . That requires adding #include "llmutex.h" to llimage.h, llnotifications.h, llwatchdog.cpp and llvolumemgr.cpp, which were inheriting it from llpointer.h. --- indra/llmath/llvolumemgr.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llmath') diff --git a/indra/llmath/llvolumemgr.cpp b/indra/llmath/llvolumemgr.cpp index bb0c94d513..d8f649140f 100644 --- a/indra/llmath/llvolumemgr.cpp +++ b/indra/llmath/llvolumemgr.cpp @@ -25,6 +25,7 @@ #include "linden_common.h" +#include "llmutex.h" #include "llvolumemgr.h" #include "llvolume.h" -- cgit v1.2.3 From d904d54b8fe9957cd7754eff59978ede6e8111c2 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 4 Oct 2024 12:53:38 -0400 Subject: Use approximate equality for failing v3dmath test. Modernize lltut.h. Allow both F32 and F64 for ensure_approximately_equals() etc. Use std::string_view instead of const char* for message string to allow passing std::string as well. Use stringize() instead of explicit std::stringstream idiom. --- indra/llmath/tests/v3dmath_test.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'indra/llmath') diff --git a/indra/llmath/tests/v3dmath_test.cpp b/indra/llmath/tests/v3dmath_test.cpp index db08419012..36ad1067a2 100644 --- a/indra/llmath/tests/v3dmath_test.cpp +++ b/indra/llmath/tests/v3dmath_test.cpp @@ -504,14 +504,11 @@ namespace tut template<> template<> void v3dmath_object::test<24>() { -#if LL_WINDOWS && _MSC_VER < 1400 - skip("This fails on VS2003!"); -#else F64 x = 10., y = 20., z = -15.; F64 angle1, angle2; LLVector3d vec3Da(x,y,z), vec3Db(x,y,z); angle1 = angle_between(vec3Da, vec3Db); - ensure("1:angle_between: Fail ", (0 == angle1)); + ensure_approximately_equals_range("1:angle_between: Fail ", angle1, 0., 1.5e-8); F64 x1 = -1., y1 = -20., z1 = -1.; vec3Da.clearVec(); vec3Da.setVec(x1,y1,z1); @@ -520,12 +517,6 @@ namespace tut vec3Da.normVec(); F64 angle = vec3Db*vec3Da; angle = acos(angle); -#if LL_WINDOWS && _MSC_VER > 1900 - skip("This fails on VS2017!"); -#else - ensure("2:angle_between: Fail ", (angle == angle2)); -#endif - -#endif + ensure_equals("2:angle_between: Fail ", angle, angle2); } } -- cgit v1.2.3