From 0e40e413d46ac2344d7f6577613512e9f4963a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:53:17 -0300 Subject: [PATCH 01/22] Added arc method --- Runtime/mathx.common.float.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 3908f73..0b54f20 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -1,4 +1,4 @@ -#region Header +#region Header // ** Copyright (C) 2023 Nicolas Reinhard, @LTMX. All rights reserved. // ** Github Profile: https://github.com/LTMX @@ -235,7 +235,19 @@ public static partial class mathx [MethodImpl(IL)] public static float pow5(this float f) => f.sq().sq() * f; #endregion - + + #region arc + /// Returns the absolute version of sin(x) + [MethodImpl(IL)] public static float4 arc(this float4 x) => abs(sine(x)); + /// + [MethodImpl(IL)] public static float3 arc(this float3 x) => abs(sine(x)); + /// + [MethodImpl(IL)] public static float2 arc(this float2 x) => abs(sine(x)); + /// + [MethodImpl(IL)] public static float arc(this float x) => abs(sine(x)); + #endregion + #endregion + #endregion #region Component-wise Math From c3337423328119357d9bbf7d53b14fa2c9a41363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:53:37 -0300 Subject: [PATCH 02/22] Added arch2 method --- Runtime/mathx.common.float.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 0b54f20..031ebf7 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -246,6 +246,17 @@ public static partial class mathx /// [MethodImpl(IL)] public static float arc(this float x) => abs(sine(x)); #endregion + + #region arch2 + /// Returns x multiplied by inv(x) + [MethodImpl(IL)] public static float4 arch2(float4 x) => x * inv(x); + /// + [MethodImpl(IL)] public static float3 arch2(float3 x) => x * inv(x); + /// + [MethodImpl(IL)] public static float2 arch2(float2 x) => x * inv(x); + /// + [MethodImpl(IL)] public static float arch2(float x) => x * inv(x); + #endregion #endregion #endregion From 0852b4c9c72d65e1482c4ca636cb8a58bb6c4831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:54:14 -0300 Subject: [PATCH 03/22] Added clamp01 method --- Runtime/mathx.common.float.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 031ebf7..751ab67 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -257,6 +257,17 @@ public static partial class mathx /// [MethodImpl(IL)] public static float arch2(float x) => x * inv(x); #endregion + + #region clamp01 + /// Clamps a value between zero and one. + [MethodImpl(IL)] public static float4 clamp01(float4 value) => clamp(value,0,1); + /// + [MethodImpl(IL)] public static float3 clamp01(float3 value) => clamp(value,0,1); + /// + [MethodImpl(IL)] public static float2 clamp01(float2 value) => clamp(value,0,1); + /// + [MethodImpl(IL)] public static float clamp01(float value) => clamp(value,0,1); + #endregion #endregion #endregion From 4a72ab0e60b5823093bc7759f467f2f80f4df905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:54:49 -0300 Subject: [PATCH 04/22] Added normalization function --- Runtime/mathx.common.float.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 751ab67..fd03b0a 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -268,6 +268,35 @@ public static partial class mathx /// [MethodImpl(IL)] public static float clamp01(float value) => clamp(value,0,1); #endregion + + #region normal + /// Remaps and clamps a value between zero and one. + [MethodImpl(IL)] public static float4 normal(float4 value, float4 zero, float4 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float4 normal(float4 value, float4 zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float4 normal(float4 value, float zero, float4 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float4 normal(float4 value, float zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float3 normal(float3 value, float3 zero, float3 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float3 normal(float3 value, float3 zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float3 normal(float3 value, float zero, float3 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float3 normal(float3 value, float zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float2 normal(float2 value, float2 zero, float2 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float2 normal(float2 value, float2 zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float2 normal(float2 value, float zero, float2 one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float2 normal(float2 value, float zero, float one) => clamp01(math.unlerp(zero, one, value)); + /// + [MethodImpl(IL)] public static float normal(float value, float zero, float one) => clamp01(math.unlerp(zero, one, value)); + #endregion #endregion #endregion From 1890df4003cffd74dd40200b38e303c508199edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:57:27 -0300 Subject: [PATCH 05/22] Added sine function --- Runtime/mathx.common.float.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index fd03b0a..55e39ac 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -297,6 +297,17 @@ public static partial class mathx /// [MethodImpl(IL)] public static float normal(float value, float zero, float one) => clamp01(math.unlerp(zero, one, value)); #endregion + + #region sine + /// Returns the sin of x multiplied by PI. + [MethodImpl(IL)] public static float4 sine(float4 x) => sin(x*PI); + /// + [MethodImpl(IL)] public static float3 sine(float3 x) => sin(x*PI); + /// + [MethodImpl(IL)] public static float2 sine(float2 x) => sin(x*PI); + /// + [MethodImpl(IL)] public static float sine(float x) => sin(x*PI); + #endregion #endregion #endregion From 5b15634bfab35aaf1c29a49ffdd4b20258addbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:58:16 -0300 Subject: [PATCH 06/22] Added snap function --- Runtime/mathx.common.float.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 55e39ac..515be8c 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -308,6 +308,22 @@ public static partial class mathx /// [MethodImpl(IL)] public static float sine(float x) => sin(x*PI); #endregion + + #region snap + /// Rounds a value to the closest multiplier of snap. + [MethodImpl(IL)] public static float4 snap(float4 x, float4 snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float4 snap(float4 x, float snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float3 snap(float3 x, float3 snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float3 snap(float3 x, float snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float2 snap(float2 x, float2 snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float2 snap(float2 x, float snap) => round(x / snap) * snap; + /// + [MethodImpl(IL)] public static float snap(float x, float snap) => round(x / snap) * snap; #endregion #endregion From fe1d8be0a9219aba62e96e671bfd12c9c21ec369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 18:59:17 -0300 Subject: [PATCH 07/22] Added bitwave function --- Runtime/mathx.common.float.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 515be8c..c80b7b8 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -325,6 +325,17 @@ public static partial class mathx /// [MethodImpl(IL)] public static float snap(float x, float snap) => round(x / snap) * snap; #endregion + + #region bitwave + /// Samples a square wave that goes between 0 and 1. + [MethodImpl(IL)] public static float4 bitwave(float4 t) => floor(math.fmod(t, 2)); + /// + [MethodImpl(IL)] public static float3 bitwave(float3 t) => floor(math.fmod(t, 2)); + /// + [MethodImpl(IL)] public static float2 bitwave(float2 t) => floor(math.fmod(t, 2)); + /// + [MethodImpl(IL)] public static float bitwave(float t) => floor(math.fmod(t, 2)); + #endregion #endregion #region Component-wise Math From 88e39ec1f65ecbfdcf44a617205c212d0faeec15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sat, 22 Apr 2023 19:01:07 -0300 Subject: [PATCH 08/22] Added triwave function --- Runtime/mathx.common.float.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index c80b7b8..0ee873b 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -336,6 +336,16 @@ public static partial class mathx /// [MethodImpl(IL)] public static float bitwave(float t) => floor(math.fmod(t, 2)); #endregion + + #region triwave + /// Samples a triangle wave between +0.5f and -0.5f. + [MethodImpl(IL)] public static float4 triwave(float4 x) => abs(frac(x) - 0.5f); + /// + [MethodImpl(IL)] public static float3 triwave(float3 x) => abs(frac(x) - 0.5f); + /// + [MethodImpl(IL)] public static float2 triwave(float2 x) => abs(frac(x) - 0.5f); + /// + [MethodImpl(IL)] public static float triwave(float x) => abs(frac(x) - 0.5f); #endregion #region Component-wise Math From 8b2a36e083e6904d2ef067d3600e24c3da1a6c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:21:31 -0300 Subject: [PATCH 09/22] Added approx which tolerance factor --- Runtime/mathx.logic.bool.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Runtime/mathx.logic.bool.cs b/Runtime/mathx.logic.bool.cs index 58f3f42..06b5591 100644 --- a/Runtime/mathx.logic.bool.cs +++ b/Runtime/mathx.logic.bool.cs @@ -87,10 +87,12 @@ public static partial class mathx [MethodImpl(INLINE)] public static bool approx(this float a, float b) => (b - a).abs() < (1E-06f * a.abs().max(b.abs())).max(EPSILON * 8); /// Compares two floating point values and returns true if they are similar. [MethodImpl(INLINE)] public static bool approx(this double a, double b) => (b - a).abs() < (1E-06f * a.abs().max(b.abs())).max(EPSILON_DBL * 8); + /// Compares two floating point values and returns true if they are within a certain distance of each other (tolerance) + [MethodImpl(INLINE)] public static bool approx(this float a, float b, float tolerance) => abs(a - b) <= abs(tolerance); + /// Compares two floating point values and returns true if they are within a certain distance of each other (tolerance) + [MethodImpl(INLINE)] public static bool approx(this double a, double b, double tolerance) => abs(a - b) <= abs(tolerance); // Odd & Even ---------------------------------------------- - - } } From 20051cafd07efc143691b3c1507b0830192a4e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:26:33 -0300 Subject: [PATCH 10/22] Simplified formula for movetowards --- .../mathx.Mathf.translations.movetowards.cs | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/Runtime/mathx.Mathf.translations.movetowards.cs b/Runtime/mathx.Mathf.translations.movetowards.cs index b62b5e2..3e4968e 100644 --- a/Runtime/mathx.Mathf.translations.movetowards.cs +++ b/Runtime/mathx.Mathf.translations.movetowards.cs @@ -11,69 +11,64 @@ namespace Unity.Mathematics public partial class mathx { /// Calculate a position between the points specified by current and target, moving no farther than the distance specified by maxDistanceDelta + public static float4 movetowards(this float4 current, float4 target, float4 maxDistanceDelta) + { + var delta = target - current; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); + } + /// public static float4 movetowards(this float4 current, float4 target, float maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float3 movetowards(this float3 current, float3 target, float maxDistanceDelta) + public static float4 movetowards(this Vector4 current, float4 target, float maxDistanceDelta) + { + return movetowards(current.asfloat(),target,maxDistanceDelta); + } + /// + public static float3 movetowards(this float3 current, float3 target, float3 maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } /// - public static float2 movetowards(this float2 current, float2 target, float maxDistanceDelta) + public static float3 movetowards(this float3 current, float3 target, float maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float movetowards(this float current, float target, float maxDistanceDelta) + public static float3 movetowards(this Vector3 current, float3 target, float maxDistanceDelta) + { + return movetowards(current.asfloat(), target, maxDistanceDelta); + } + /// + public static float2 movetowards(this float2 current, float2 target, float2 maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.sq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } - - /// - public static float4 movetowards(this Vector4 current, float4 target, float maxDistanceDelta) + public static float2 movetowards(this float2 current, float2 target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + var delta = target - current; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float3 movetowards(this Vector3 current, float3 target, float maxDistanceDelta) + public static float movetowards(this float current, float target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + var delta = target - current; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } /// public static float2 movetowards(this Vector2 current, float2 target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + return movetowards(current.asfloat(), target, maxDistanceDelta); } } } \ No newline at end of file From 426c2f939a40acb6c65cb5f58cf09c5c33165afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:28:34 -0300 Subject: [PATCH 11/22] New mix method --- Runtime/mathx.interpolation.common.cs | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index 474db33..3039b3c 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -1,4 +1,4 @@ -#region Header +#region Header // ** Copyright (C) 2023 Nicolas Reinhard, @LTMX. All rights reserved. // ** Github Profile: https://github.com/LTMX @@ -382,5 +382,34 @@ public static partial class mathx public static float3 smin_N_factor(this float3 t, float3 a, float3 b, float3 n, out float3 factor) => f3(t.x.smin_N_factor(a.x, b.x, n.x, out factor.x), t.y.smin_N_factor(a.y, b.y, n.y, out factor.y), t.z.smin_N_factor(a.z, b.z, n.z, out factor.z)); public static float4 smin_N_factor(this float4 t, float4 a, float4 b, float4 n, out float4 factor) => f4(t.x.smin_N_factor(a.x, b.x, n.x, out factor.x), t.y.smin_N_factor(a.y, b.y, n.y, out factor.y), t.z.smin_N_factor(a.z, b.z, n.z, out factor.z), t.w.smin_N_factor(a.w, b.w, n.w, out factor.w)); + #region mix + // Returns (1-weightB)*a + weightB*b. + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float4 weightB, float4 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float4 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float weightB, float4 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float3 weightB, float3 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float3 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float weightB, float3 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float2 weightB, float2 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float2 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float weightB, float2 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float mix(float a, float b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + #endregion + } } \ No newline at end of file From cdb9099586a93236f26eaf9b353e5df2ef4a35a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:30:52 -0300 Subject: [PATCH 12/22] Added smoothstart and smoothstop methods --- Runtime/mathx.interpolation.common.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index 3039b3c..ae0803b 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -411,5 +411,26 @@ public static partial class mathx [MethodImpl(IL)] public static float mix(float a, float b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); #endregion + #region smoothstart + // Returns a smoother version of the value at the start. + [MethodImpl(IL)] public static float4 smoothstart(float4 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float3 smoothstart(float3 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float2 smoothstart(float2 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float smoothstart(float t, int n) => pow(t,n); + #endregion + + #region smoothstop + // Returns a smoother version of the value at the end. + [MethodImpl(IL)] public static float4 smoothstop(float4 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float3 smoothstop(float3 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float2 smoothstop(float2 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float smoothstop(float t, int n) => inv(pow(inv(t), n)); + #endregion } } \ No newline at end of file From d2da70733fada54855824f771dd1a9834f847c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:31:26 -0300 Subject: [PATCH 13/22] Added crossfade method --- Runtime/mathx.interpolation.common.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index ae0803b..5333fdf 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -432,5 +432,22 @@ public static partial class mathx /// [MethodImpl(IL)] public static float smoothstop(float t, int n) => inv(pow(inv(t), n)); #endregion + + #region xfade (crossfade) + // Fades between values a and b. + [MethodImpl(IL)] public static float4 xfade(float4 a, float4 b, float4 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float4 xfade(float4 a, float4 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float3 xfade(float3 a, float3 b, float3 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float3 xfade(float3 a, float3 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float2 xfade(float2 a, float2 b, float2 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float2 xfade(float2 a, float2 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float xfade(float a, float b, float t) => math.mad(b-a,t,a); + #endregion } } \ No newline at end of file From e281477a2b8e1d3f812f9527d38752b6ae75199e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:31:54 -0300 Subject: [PATCH 14/22] Extended overloads for pingpong method --- Runtime/mathx.Mathf.translations.cs | 37 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Runtime/mathx.Mathf.translations.cs b/Runtime/mathx.Mathf.translations.cs index e1a2281..86e5e07 100644 --- a/Runtime/mathx.Mathf.translations.cs +++ b/Runtime/mathx.Mathf.translations.cs @@ -11,16 +11,39 @@ namespace Unity.Mathematics public static partial class mathx { + #region pingpong /// PingPongs the value t, so that it is never larger than length and never smaller than 0. - public static float pingpong(float x, float length) => length - math.abs(x.repeat(length * 2) - length); - public static float2 pingpong(float2 x, float length) => length - math.abs(x.repeat(length * 2) - length); - public static float3 pingpong(float3 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float4 pingpong(float4 x, float4 length) => length - math.abs(x.repeat(length * 2) - length); public static float4 pingpong(float4 x, float length) => length - math.abs(x.repeat(length * 2) - length); - - public static double pingpong(double x, double length) => length - math.abs(x.repeat(length * 2) - length); - public static double2 pingpong(double2 x, double length) => length - math.abs(x.repeat(length * 2) - length); - public static double3 pingpong(double3 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static float3 pingpong(float3 x, float3 length) => length - math.abs(x.repeat(length * 2) - length); + public static float3 pingpong(float3 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float2 pingpong(float2 x, float2 length) => length - math.abs(x.repeat(length * 2) - length); + public static float2 pingpong(float2 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float pingpong(float x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static double4 pingpong(double4 x, double4 length) => length - math.abs(x.repeat(length * 2) - length); public static double4 pingpong(double4 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double3 pingpong(double3 x, double3 length) => length - math.abs(x.repeat(length * 2) - length); + public static double3 pingpong(double3 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double2 pingpong(double2 x, double2 length) => length - math.abs(x.repeat(length * 2) - length); + public static double2 pingpong(double2 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double pingpong(double x, double length) => length - math.abs(x.repeat(length * 2) - length); + + // Pingpongs the value t between a and b + public static float4 pingpong(float4 a, float4 b, float4 t) => a+pingpong(t,b-a); + public static float4 pingpong(float4 a, float4 b, float t) => a+pingpong(t,b-a); + public static float3 pingpong(float3 a, float3 b, float3 t) => a+pingpong(t,b-a); + public static float3 pingpong(float3 a, float3 b, float t) => a+pingpong(t,b-a); + public static float2 pingpong(float2 a, float2 b, float2 t) => a+pingpong(t,b-a); + public static float2 pingpong(float2 a, float2 b, float t) => a+pingpong(t,b-a); + public static float pingpong(float a, float b, float t) => a+pingpong(t,b-a); + public static double4 pingpong(double4 a, double4 b, double4 t) => a+pingpong(t,b-a); + public static double4 pingpong(double4 a, double4 b, double t) => a+pingpong(t,b-a); + public static double3 pingpong(double3 a, double3 b, double3 t) => a+pingpong(t,b-a); + public static double3 pingpong(double3 a, double3 b, double t) => a+pingpong(t,b-a); + public static double2 pingpong(double2 a, double2 b, double2 t) => a+pingpong(t,b-a); + public static double2 pingpong(double2 a, double2 b, double t) => a+pingpong(t,b-a); + public static double pingpong(double a, double b, double t) => a+pingpong(t,b-a); + #endregion /// Sample a parabola trajectory From cdf3ade256917cb1c1265b5f0288eeda47d54e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:21:31 -0300 Subject: [PATCH 15/22] Added approx with tolerance factor --- Runtime/mathx.logic.bool.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Runtime/mathx.logic.bool.cs b/Runtime/mathx.logic.bool.cs index 58f3f42..06b5591 100644 --- a/Runtime/mathx.logic.bool.cs +++ b/Runtime/mathx.logic.bool.cs @@ -87,10 +87,12 @@ public static partial class mathx [MethodImpl(INLINE)] public static bool approx(this float a, float b) => (b - a).abs() < (1E-06f * a.abs().max(b.abs())).max(EPSILON * 8); /// Compares two floating point values and returns true if they are similar. [MethodImpl(INLINE)] public static bool approx(this double a, double b) => (b - a).abs() < (1E-06f * a.abs().max(b.abs())).max(EPSILON_DBL * 8); + /// Compares two floating point values and returns true if they are within a certain distance of each other (tolerance) + [MethodImpl(INLINE)] public static bool approx(this float a, float b, float tolerance) => abs(a - b) <= abs(tolerance); + /// Compares two floating point values and returns true if they are within a certain distance of each other (tolerance) + [MethodImpl(INLINE)] public static bool approx(this double a, double b, double tolerance) => abs(a - b) <= abs(tolerance); // Odd & Even ---------------------------------------------- - - } } From e06f26a3596c524abe7d0deb7a1e2647cd054612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:26:33 -0300 Subject: [PATCH 16/22] Simplified formula for movetowards --- .../mathx.Mathf.translations.movetowards.cs | 71 +++++++++---------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/Runtime/mathx.Mathf.translations.movetowards.cs b/Runtime/mathx.Mathf.translations.movetowards.cs index b62b5e2..3e4968e 100644 --- a/Runtime/mathx.Mathf.translations.movetowards.cs +++ b/Runtime/mathx.Mathf.translations.movetowards.cs @@ -11,69 +11,64 @@ namespace Unity.Mathematics public partial class mathx { /// Calculate a position between the points specified by current and target, moving no farther than the distance specified by maxDistanceDelta + public static float4 movetowards(this float4 current, float4 target, float4 maxDistanceDelta) + { + var delta = target - current; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); + } + /// public static float4 movetowards(this float4 current, float4 target, float maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float3 movetowards(this float3 current, float3 target, float maxDistanceDelta) + public static float4 movetowards(this Vector4 current, float4 target, float maxDistanceDelta) + { + return movetowards(current.asfloat(),target,maxDistanceDelta); + } + /// + public static float3 movetowards(this float3 current, float3 target, float3 maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } /// - public static float2 movetowards(this float2 current, float2 target, float maxDistanceDelta) + public static float3 movetowards(this float3 current, float3 target, float maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float movetowards(this float current, float target, float maxDistanceDelta) + public static float3 movetowards(this Vector3 current, float3 target, float maxDistanceDelta) + { + return movetowards(current.asfloat(), target, maxDistanceDelta); + } + /// + public static float2 movetowards(this float2 current, float2 target, float2 maxDistanceDelta) { var delta = target - current; - var deltaLength = delta.sq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current + delta) / deltaLength.sqrt() * maxDistanceDelta; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } - - /// - public static float4 movetowards(this Vector4 current, float4 target, float maxDistanceDelta) + public static float2 movetowards(this float2 current, float2 target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + var delta = target - current; + var deltaLength = delta.length(); + return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float3 movetowards(this Vector3 current, float3 target, float maxDistanceDelta) + public static float movetowards(this float current, float target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + var delta = target - current; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } /// public static float2 movetowards(this Vector2 current, float2 target, float maxDistanceDelta) { - var delta = target - current.asfloat(); - var deltaLength = delta.lengthsq(); - if (deltaLength == 0 || maxDistanceDelta >= 0 && deltaLength <= maxDistanceDelta.sq()) - return target; - return (current.asfloat() + delta) / deltaLength.sqrt() * maxDistanceDelta; + return movetowards(current.asfloat(), target, maxDistanceDelta); } } } \ No newline at end of file From 4abca04a7dbf5d4303fdd197f8819c82df8c2a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:28:34 -0300 Subject: [PATCH 17/22] New mix method --- Runtime/mathx.interpolation.common.cs | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index 474db33..3039b3c 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -1,4 +1,4 @@ -#region Header +#region Header // ** Copyright (C) 2023 Nicolas Reinhard, @LTMX. All rights reserved. // ** Github Profile: https://github.com/LTMX @@ -382,5 +382,34 @@ public static partial class mathx public static float3 smin_N_factor(this float3 t, float3 a, float3 b, float3 n, out float3 factor) => f3(t.x.smin_N_factor(a.x, b.x, n.x, out factor.x), t.y.smin_N_factor(a.y, b.y, n.y, out factor.y), t.z.smin_N_factor(a.z, b.z, n.z, out factor.z)); public static float4 smin_N_factor(this float4 t, float4 a, float4 b, float4 n, out float4 factor) => f4(t.x.smin_N_factor(a.x, b.x, n.x, out factor.x), t.y.smin_N_factor(a.y, b.y, n.y, out factor.y), t.z.smin_N_factor(a.z, b.z, n.z, out factor.z), t.w.smin_N_factor(a.w, b.w, n.w, out factor.w)); + #region mix + // Returns (1-weightB)*a + weightB*b. + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float4 weightB, float4 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float4 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float weightB, float4 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float4 mix(float4 a, float4 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float3 weightB, float3 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float3 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float weightB, float3 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float3 mix(float3 a, float3 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float2 weightB, float2 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float2 weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float weightB, float2 t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float2 mix(float2 a, float2 b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + /// + [MethodImpl(IL)] public static float mix(float a, float b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); + #endregion + } } \ No newline at end of file From 8c7cff4b1d90a65ebc603afef16b598b0e6ca81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:30:52 -0300 Subject: [PATCH 18/22] Added smoothstart and smoothstop methods --- Runtime/mathx.interpolation.common.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index 3039b3c..ae0803b 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -411,5 +411,26 @@ public static partial class mathx [MethodImpl(IL)] public static float mix(float a, float b, float weightB, float t) => math.mad(weightB,b,math.mad(-weightB,a,a)); #endregion + #region smoothstart + // Returns a smoother version of the value at the start. + [MethodImpl(IL)] public static float4 smoothstart(float4 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float3 smoothstart(float3 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float2 smoothstart(float2 t, int n) => pow(t,n); + /// + [MethodImpl(IL)] public static float smoothstart(float t, int n) => pow(t,n); + #endregion + + #region smoothstop + // Returns a smoother version of the value at the end. + [MethodImpl(IL)] public static float4 smoothstop(float4 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float3 smoothstop(float3 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float2 smoothstop(float2 t, int n) => inv(pow(inv(t), n)); + /// + [MethodImpl(IL)] public static float smoothstop(float t, int n) => inv(pow(inv(t), n)); + #endregion } } \ No newline at end of file From 54c1c56a031de802379e7c9cd59a34a727f475f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:31:26 -0300 Subject: [PATCH 19/22] Added crossfade method --- Runtime/mathx.interpolation.common.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Runtime/mathx.interpolation.common.cs b/Runtime/mathx.interpolation.common.cs index ae0803b..5333fdf 100644 --- a/Runtime/mathx.interpolation.common.cs +++ b/Runtime/mathx.interpolation.common.cs @@ -432,5 +432,22 @@ public static partial class mathx /// [MethodImpl(IL)] public static float smoothstop(float t, int n) => inv(pow(inv(t), n)); #endregion + + #region xfade (crossfade) + // Fades between values a and b. + [MethodImpl(IL)] public static float4 xfade(float4 a, float4 b, float4 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float4 xfade(float4 a, float4 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float3 xfade(float3 a, float3 b, float3 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float3 xfade(float3 a, float3 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float2 xfade(float2 a, float2 b, float2 t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float2 xfade(float2 a, float2 b, float t) => math.mad(b-a,t,a); + /// + [MethodImpl(IL)] public static float xfade(float a, float b, float t) => math.mad(b-a,t,a); + #endregion } } \ No newline at end of file From bbb2ba83beff33fd7d326fb34d71090918ca02e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Sun, 23 Apr 2023 16:31:54 -0300 Subject: [PATCH 20/22] Extended overloads for pingpong method --- Runtime/mathx.Mathf.translations.cs | 37 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Runtime/mathx.Mathf.translations.cs b/Runtime/mathx.Mathf.translations.cs index e1a2281..86e5e07 100644 --- a/Runtime/mathx.Mathf.translations.cs +++ b/Runtime/mathx.Mathf.translations.cs @@ -11,16 +11,39 @@ namespace Unity.Mathematics public static partial class mathx { + #region pingpong /// PingPongs the value t, so that it is never larger than length and never smaller than 0. - public static float pingpong(float x, float length) => length - math.abs(x.repeat(length * 2) - length); - public static float2 pingpong(float2 x, float length) => length - math.abs(x.repeat(length * 2) - length); - public static float3 pingpong(float3 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float4 pingpong(float4 x, float4 length) => length - math.abs(x.repeat(length * 2) - length); public static float4 pingpong(float4 x, float length) => length - math.abs(x.repeat(length * 2) - length); - - public static double pingpong(double x, double length) => length - math.abs(x.repeat(length * 2) - length); - public static double2 pingpong(double2 x, double length) => length - math.abs(x.repeat(length * 2) - length); - public static double3 pingpong(double3 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static float3 pingpong(float3 x, float3 length) => length - math.abs(x.repeat(length * 2) - length); + public static float3 pingpong(float3 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float2 pingpong(float2 x, float2 length) => length - math.abs(x.repeat(length * 2) - length); + public static float2 pingpong(float2 x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static float pingpong(float x, float length) => length - math.abs(x.repeat(length * 2) - length); + public static double4 pingpong(double4 x, double4 length) => length - math.abs(x.repeat(length * 2) - length); public static double4 pingpong(double4 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double3 pingpong(double3 x, double3 length) => length - math.abs(x.repeat(length * 2) - length); + public static double3 pingpong(double3 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double2 pingpong(double2 x, double2 length) => length - math.abs(x.repeat(length * 2) - length); + public static double2 pingpong(double2 x, double length) => length - math.abs(x.repeat(length * 2) - length); + public static double pingpong(double x, double length) => length - math.abs(x.repeat(length * 2) - length); + + // Pingpongs the value t between a and b + public static float4 pingpong(float4 a, float4 b, float4 t) => a+pingpong(t,b-a); + public static float4 pingpong(float4 a, float4 b, float t) => a+pingpong(t,b-a); + public static float3 pingpong(float3 a, float3 b, float3 t) => a+pingpong(t,b-a); + public static float3 pingpong(float3 a, float3 b, float t) => a+pingpong(t,b-a); + public static float2 pingpong(float2 a, float2 b, float2 t) => a+pingpong(t,b-a); + public static float2 pingpong(float2 a, float2 b, float t) => a+pingpong(t,b-a); + public static float pingpong(float a, float b, float t) => a+pingpong(t,b-a); + public static double4 pingpong(double4 a, double4 b, double4 t) => a+pingpong(t,b-a); + public static double4 pingpong(double4 a, double4 b, double t) => a+pingpong(t,b-a); + public static double3 pingpong(double3 a, double3 b, double3 t) => a+pingpong(t,b-a); + public static double3 pingpong(double3 a, double3 b, double t) => a+pingpong(t,b-a); + public static double2 pingpong(double2 a, double2 b, double2 t) => a+pingpong(t,b-a); + public static double2 pingpong(double2 a, double2 b, double t) => a+pingpong(t,b-a); + public static double pingpong(double a, double b, double t) => a+pingpong(t,b-a); + #endregion /// Sample a parabola trajectory From 19b7439b7a40bcdaf613fb5cf1537b63dd4820e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Mon, 8 May 2023 21:42:28 -0300 Subject: [PATCH 21/22] Reordered declarations for movetowards --- Runtime/mathx.Mathf.translations.movetowards.cs | 10 +++++----- Runtime/mathx.common.float.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Runtime/mathx.Mathf.translations.movetowards.cs b/Runtime/mathx.Mathf.translations.movetowards.cs index 3e4968e..08b5d3e 100644 --- a/Runtime/mathx.Mathf.translations.movetowards.cs +++ b/Runtime/mathx.Mathf.translations.movetowards.cs @@ -60,15 +60,15 @@ public static float2 movetowards(this float2 current, float2 target, float maxDi return math.mad(min(deltaLength,maxDistanceDelta),sign(delta),current); } /// - public static float movetowards(this float current, float target, float maxDistanceDelta) + public static float2 movetowards(this Vector2 current, float2 target, float maxDistanceDelta) { - var delta = target - current; - return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); + return movetowards(current.asfloat(), target, maxDistanceDelta); } /// - public static float2 movetowards(this Vector2 current, float2 target, float maxDistanceDelta) + public static float movetowards(this float current, float target, float maxDistanceDelta) { - return movetowards(current.asfloat(), target, maxDistanceDelta); + var delta = target - current; + return math.mad(min(abs(delta),maxDistanceDelta),sign(delta),current); } } } \ No newline at end of file diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index 0ee873b..e6450c0 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -1,4 +1,4 @@ -#region Header +#region Header // ** Copyright (C) 2023 Nicolas Reinhard, @LTMX. All rights reserved. // ** Github Profile: https://github.com/LTMX From 85e8bd782213e9995948d1bcc1269f476b903ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=B4nio=20J=C3=BAnior?= Date: Wed, 10 May 2023 11:19:16 -0300 Subject: [PATCH 22/22] Padronized signature for methods --- Runtime/mathx.common.float.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Runtime/mathx.common.float.cs b/Runtime/mathx.common.float.cs index e6450c0..b124782 100644 --- a/Runtime/mathx.common.float.cs +++ b/Runtime/mathx.common.float.cs @@ -328,13 +328,13 @@ public static partial class mathx #region bitwave /// Samples a square wave that goes between 0 and 1. - [MethodImpl(IL)] public static float4 bitwave(float4 t) => floor(math.fmod(t, 2)); + [MethodImpl(IL)] public static float4 bitwave(float4 x) => floor(math.fmod(x, 2)); /// - [MethodImpl(IL)] public static float3 bitwave(float3 t) => floor(math.fmod(t, 2)); + [MethodImpl(IL)] public static float3 bitwave(float3 x) => floor(math.fmod(x, 2)); /// - [MethodImpl(IL)] public static float2 bitwave(float2 t) => floor(math.fmod(t, 2)); + [MethodImpl(IL)] public static float2 bitwave(float2 x) => floor(math.fmod(x, 2)); /// - [MethodImpl(IL)] public static float bitwave(float t) => floor(math.fmod(t, 2)); + [MethodImpl(IL)] public static float bitwave(float x) => floor(math.fmod(x, 2)); #endregion #region triwave