Use in over ref modifier in Math functions input parameters

This commit is contained in:
2025-12-06 23:32:47 +02:00
parent ecf074801f
commit bc4b94d2bc
136 changed files with 1824 additions and 1824 deletions

View File

@@ -330,7 +330,7 @@ namespace FlaxEngine
/// <param name="left">The first vector to add.</param>
/// <param name="right">The second vector to add.</param>
/// <param name="result">When the method completes, contains the sum of the two vectors.</param>
public static void Add(ref Float4 left, ref Float4 right, out Float4 result)
public static void Add(in Float4 left, in Float4 right, out Float4 result)
{
result = new Float4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W);
}
@@ -352,7 +352,7 @@ namespace FlaxEngine
/// <param name="left">The input vector</param>
/// <param name="right">The scalar value to be added to elements</param>
/// <param name="result">The vector with added scalar for each element.</param>
public static void Add(ref Float4 left, ref float right, out Float4 result)
public static void Add(in Float4 left, float right, out Float4 result)
{
result = new Float4(left.X + right, left.Y + right, left.Z + right, left.W + right);
}
@@ -374,7 +374,7 @@ namespace FlaxEngine
/// <param name="left">The first vector to subtract.</param>
/// <param name="right">The second vector to subtract.</param>
/// <param name="result">When the method completes, contains the difference of the two vectors.</param>
public static void Subtract(ref Float4 left, ref Float4 right, out Float4 result)
public static void Subtract(in Float4 left, in Float4 right, out Float4 result)
{
result = new Float4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W);
}
@@ -396,7 +396,7 @@ namespace FlaxEngine
/// <param name="left">The input vector</param>
/// <param name="right">The scalar value to be subtracted from elements</param>
/// <param name="result">The vector with subtracted scalar for each element.</param>
public static void Subtract(ref Float4 left, ref float right, out Float4 result)
public static void Subtract(in Float4 left, float right, out Float4 result)
{
result = new Float4(left.X - right, left.Y - right, left.Z - right, left.W - right);
}
@@ -418,7 +418,7 @@ namespace FlaxEngine
/// <param name="left">The scalar value to be subtracted from elements</param>
/// <param name="right">The input vector.</param>
/// <param name="result">The vector with subtracted scalar for each element.</param>
public static void Subtract(ref float left, ref Float4 right, out Float4 result)
public static void Subtract(float left, in Float4 right, out Float4 result)
{
result = new Float4(left - right.X, left - right.Y, left - right.Z, left - right.W);
}
@@ -440,7 +440,7 @@ namespace FlaxEngine
/// <param name="value">The vector to scale.</param>
/// <param name="scale">The amount by which to scale the vector.</param>
/// <param name="result">When the method completes, contains the scaled vector.</param>
public static void Multiply(ref Float4 value, float scale, out Float4 result)
public static void Multiply(in Float4 value, float scale, out Float4 result)
{
result = new Float4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale);
}
@@ -462,7 +462,7 @@ namespace FlaxEngine
/// <param name="left">The first vector to multiply.</param>
/// <param name="right">The second vector to multiply.</param>
/// <param name="result">When the method completes, contains the multiplied vector.</param>
public static void Multiply(ref Float4 left, ref Float4 right, out Float4 result)
public static void Multiply(in Float4 left, in Float4 right, out Float4 result)
{
result = new Float4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W);
}
@@ -484,7 +484,7 @@ namespace FlaxEngine
/// <param name="value">The vector to scale.</param>
/// <param name="scale">The amount by which to scale the vector.</param>
/// <param name="result">When the method completes, contains the scaled vector.</param>
public static void Divide(ref Float4 value, float scale, out Float4 result)
public static void Divide(in Float4 value, float scale, out Float4 result)
{
result = new Float4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale);
}
@@ -506,7 +506,7 @@ namespace FlaxEngine
/// <param name="scale">The amount by which to scale the vector.</param>
/// <param name="value">The vector to scale.</param>
/// <param name="result">When the method completes, contains the scaled vector.</param>
public static void Divide(float scale, ref Float4 value, out Float4 result)
public static void Divide(float scale, in Float4 value, out Float4 result)
{
result = new Float4(scale / value.X, scale / value.Y, scale / value.Z, scale / value.W);
}
@@ -527,7 +527,7 @@ namespace FlaxEngine
/// </summary>
/// <param name="value">The vector to negate.</param>
/// <param name="result">When the method completes, contains a vector facing in the opposite direction.</param>
public static void Negate(ref Float4 value, out Float4 result)
public static void Negate(in Float4 value, out Float4 result)
{
result = new Float4(-value.X, -value.Y, -value.Z, -value.W);
}
@@ -551,7 +551,7 @@ namespace FlaxEngine
/// <param name="amount1">Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in <paramref name="value2" />).</param>
/// <param name="amount2">Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in <paramref name="value3" />).</param>
/// <param name="result">When the method completes, contains the 4D Cartesian coordinates of the specified point.</param>
public static void Barycentric(ref Float4 value1, ref Float4 value2, ref Float4 value3, float amount1, float amount2, out Float4 result)
public static void Barycentric(in Float4 value1, in Float4 value2, in Float4 value3, float amount1, float amount2, out Float4 result)
{
result = new Float4(value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X),
value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y),
@@ -570,7 +570,7 @@ namespace FlaxEngine
/// <returns>A new <see cref="Float4" /> containing the 4D Cartesian coordinates of the specified point.</returns>
public static Float4 Barycentric(Float4 value1, Float4 value2, Float4 value3, float amount1, float amount2)
{
Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out Float4 result);
Barycentric(in value1, in value2, in value3, amount1, amount2, out Float4 result);
return result;
}
@@ -581,7 +581,7 @@ namespace FlaxEngine
/// <param name="min">The minimum value.</param>
/// <param name="max">The maximum value.</param>
/// <param name="result">When the method completes, contains the clamped value.</param>
public static void Clamp(ref Float4 value, ref Float4 min, ref Float4 max, out Float4 result)
public static void Clamp(in Float4 value, in Float4 min, in Float4 max, out Float4 result)
{
float x = value.X;
x = x > max.X ? max.X : x;
@@ -607,7 +607,7 @@ namespace FlaxEngine
/// <returns>The clamped value.</returns>
public static Float4 Clamp(Float4 value, Float4 min, Float4 max)
{
Clamp(ref value, ref min, ref max, out Float4 result);
Clamp(in value, in min, in max, out Float4 result);
return result;
}
@@ -617,8 +617,8 @@ namespace FlaxEngine
/// <param name="value1">The first vector.</param>
/// <param name="value2">The second vector.</param>
/// <param name="result">When the method completes, contains the distance between the two vectors.</param>
/// <remarks><see cref="Float4.DistanceSquared(ref Float4, ref Float4, out float)" /> may be preferred when only the relative distance is needed and speed is of the essence.</remarks>
public static void Distance(ref Float4 value1, ref Float4 value2, out float result)
/// <remarks><see cref="Float4.DistanceSquared(in Float4, in Float4, out float)" /> may be preferred when only the relative distance is needed and speed is of the essence.</remarks>
public static void Distance(in Float4 value1, in Float4 value2, out float result)
{
float x = value1.X - value2.X;
float y = value1.Y - value2.Y;
@@ -649,7 +649,7 @@ namespace FlaxEngine
/// <param name="value1">The first vector.</param>
/// <param name="value2">The second vector.</param>
/// <param name="result">When the method completes, contains the squared distance between the two vectors.</param>
public static void DistanceSquared(ref Float4 value1, ref Float4 value2, out float result)
public static void DistanceSquared(in Float4 value1, in Float4 value2, out float result)
{
float x = value1.X - value2.X;
float y = value1.Y - value2.Y;
@@ -682,7 +682,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if left and right are near another, <c>false</c> otherwise</returns>
public static bool NearEqual(Float4 left, Float4 right, float epsilon = Mathf.Epsilon)
{
return NearEqual(ref left, ref right, epsilon);
return NearEqual(in left, in right, epsilon);
}
/// <summary>
@@ -692,7 +692,7 @@ namespace FlaxEngine
/// <param name="right">The right vector.</param>
/// <param name="epsilon">The epsilon.</param>
/// <returns><c>true</c> if left and right are near another, <c>false</c> otherwise</returns>
public static bool NearEqual(ref Float4 left, ref Float4 right, float epsilon = Mathf.Epsilon)
public static bool NearEqual(in Float4 left, in Float4 right, float epsilon = Mathf.Epsilon)
{
return Mathf.WithinEpsilon(left.X, right.X, epsilon) && Mathf.WithinEpsilon(left.Y, right.Y, epsilon) && Mathf.WithinEpsilon(left.Z, right.Z, epsilon) && Mathf.WithinEpsilon(left.W, right.W, epsilon);
}
@@ -703,7 +703,7 @@ namespace FlaxEngine
/// <param name="left">First source vector</param>
/// <param name="right">Second source vector.</param>
/// <param name="result">When the method completes, contains the dot product of the two vectors.</param>
public static void Dot(ref Float4 left, ref Float4 right, out float result)
public static void Dot(in Float4 left, in Float4 right, out float result)
{
result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
}
@@ -724,7 +724,7 @@ namespace FlaxEngine
/// </summary>
/// <param name="value">The vector to normalize.</param>
/// <param name="result">When the method completes, contains the normalized vector.</param>
public static void Normalize(ref Float4 value, out Float4 result)
public static void Normalize(in Float4 value, out Float4 result)
{
result = value;
result.Normalize();
@@ -800,7 +800,7 @@ namespace FlaxEngine
/// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end" />.</param>
/// <param name="result">When the method completes, contains the linear interpolation of the two vectors.</param>
/// <remarks>Passing <paramref name="amount" /> a value of 0 will cause <paramref name="start" /> to be returned; a value of 1 will cause <paramref name="end" /> to be returned.</remarks>
public static void Lerp(ref Float4 start, ref Float4 end, float amount, out Float4 result)
public static void Lerp(in Float4 start, in Float4 end, float amount, out Float4 result)
{
result.X = Mathf.Lerp(start.X, end.X, amount);
result.Y = Mathf.Lerp(start.Y, end.Y, amount);
@@ -818,7 +818,7 @@ namespace FlaxEngine
/// <remarks>Passing <paramref name="amount" /> a value of 0 will cause <paramref name="start" /> to be returned; a value of 1 will cause <paramref name="end" /> to be returned.</remarks>
public static Float4 Lerp(Float4 start, Float4 end, float amount)
{
Lerp(ref start, ref end, amount, out Float4 result);
Lerp(in start, in end, amount, out Float4 result);
return result;
}
@@ -829,10 +829,10 @@ namespace FlaxEngine
/// <param name="end">End vector.</param>
/// <param name="amount">Value between 0 and 1 indicating the weight of <paramref name="end" />.</param>
/// <param name="result">When the method completes, contains the cubic interpolation of the two vectors.</param>
public static void SmoothStep(ref Float4 start, ref Float4 end, float amount, out Float4 result)
public static void SmoothStep(in Float4 start, in Float4 end, float amount, out Float4 result)
{
amount = Mathf.SmoothStep(amount);
Lerp(ref start, ref end, amount, out result);
Lerp(in start, in end, amount, out result);
}
/// <summary>
@@ -844,7 +844,7 @@ namespace FlaxEngine
/// <returns>The cubic interpolation of the two vectors.</returns>
public static Float4 SmoothStep(Float4 start, Float4 end, float amount)
{
SmoothStep(ref start, ref end, amount, out Float4 result);
SmoothStep(in start, in end, amount, out Float4 result);
return result;
}
@@ -857,7 +857,7 @@ namespace FlaxEngine
/// <param name="tangent2">Second source tangent vector.</param>
/// <param name="amount">Weighting factor.</param>
/// <param name="result">When the method completes, contains the result of the Hermite spline interpolation.</param>
public static void Hermite(ref Float4 value1, ref Float4 tangent1, ref Float4 value2, ref Float4 tangent2, float amount, out Float4 result)
public static void Hermite(in Float4 value1, in Float4 tangent1, in Float4 value2, in Float4 tangent2, float amount, out Float4 result)
{
float squared = amount * amount;
float cubed = amount * squared;
@@ -882,7 +882,7 @@ namespace FlaxEngine
/// <returns>The result of the Hermite spline interpolation.</returns>
public static Float4 Hermite(Float4 value1, Float4 tangent1, Float4 value2, Float4 tangent2, float amount)
{
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out Float4 result);
Hermite(in value1, in tangent1, in value2, in tangent2, amount, out Float4 result);
return result;
}
@@ -895,7 +895,7 @@ namespace FlaxEngine
/// <param name="value4">The fourth position in the interpolation.</param>
/// <param name="amount">Weighting factor.</param>
/// <param name="result">When the method completes, contains the result of the Catmull-Rom interpolation.</param>
public static void CatmullRom(ref Float4 value1, ref Float4 value2, ref Float4 value3, ref Float4 value4, float amount, out Float4 result)
public static void CatmullRom(in Float4 value1, in Float4 value2, in Float4 value3, in Float4 value4, float amount, out Float4 result)
{
float squared = amount * amount;
float cubed = amount * squared;
@@ -916,7 +916,7 @@ namespace FlaxEngine
/// <returns>A vector that is the result of the Catmull-Rom interpolation.</returns>
public static Float4 CatmullRom(Float4 value1, Float4 value2, Float4 value3, Float4 value4, float amount)
{
CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out Float4 result);
CatmullRom(in value1, in value2, in value3, in value4, amount, out Float4 result);
return result;
}
@@ -926,7 +926,7 @@ namespace FlaxEngine
/// <param name="left">The first source vector.</param>
/// <param name="right">The second source vector.</param>
/// <param name="result">When the method completes, contains an new vector composed of the largest components of the source vectors.</param>
public static void Max(ref Float4 left, ref Float4 right, out Float4 result)
public static void Max(in Float4 left, in Float4 right, out Float4 result)
{
result.X = left.X > right.X ? left.X : right.X;
result.Y = left.Y > right.Y ? left.Y : right.Y;
@@ -942,7 +942,7 @@ namespace FlaxEngine
/// <returns>A vector containing the largest components of the source vectors.</returns>
public static Float4 Max(Float4 left, Float4 right)
{
Max(ref left, ref right, out Float4 result);
Max(in left, in right, out Float4 result);
return result;
}
@@ -952,7 +952,7 @@ namespace FlaxEngine
/// <param name="left">The first source vector.</param>
/// <param name="right">The second source vector.</param>
/// <param name="result">When the method completes, contains an new vector composed of the smallest components of the source vectors.</param>
public static void Min(ref Float4 left, ref Float4 right, out Float4 result)
public static void Min(in Float4 left, in Float4 right, out Float4 result)
{
result.X = left.X < right.X ? left.X : right.X;
result.Y = left.Y < right.Y ? left.Y : right.Y;
@@ -968,7 +968,7 @@ namespace FlaxEngine
/// <returns>A vector containing the smallest components of the source vectors.</returns>
public static Float4 Min(Float4 left, Float4 right)
{
Min(ref left, ref right, out Float4 result);
Min(in left, in right, out Float4 result);
return result;
}
@@ -988,7 +988,7 @@ namespace FlaxEngine
/// <param name="vector">The vector to rotate.</param>
/// <param name="rotation">The <see cref="Quaternion" /> rotation to apply.</param>
/// <param name="result">When the method completes, contains the transformed <see cref="Float4" />.</param>
public static void Transform(ref Float4 vector, ref Quaternion rotation, out Float4 result)
public static void Transform(in Float4 vector, in Quaternion rotation, out Float4 result)
{
float x = rotation.X + rotation.X;
float y = rotation.Y + rotation.Y;
@@ -1016,7 +1016,7 @@ namespace FlaxEngine
/// <returns>The transformed <see cref="Float4" />.</returns>
public static Float4 Transform(Float4 vector, Quaternion rotation)
{
Transform(ref vector, ref rotation, out Float4 result);
Transform(in vector, in rotation, out Float4 result);
return result;
}
@@ -1026,7 +1026,7 @@ namespace FlaxEngine
/// <param name="vector">The source vector.</param>
/// <param name="transform">The transformation <see cref="Matrix" />.</param>
/// <param name="result">When the method completes, contains the transformed <see cref="Float4" />.</param>
public static void Transform(ref Float4 vector, ref Matrix transform, out Float4 result)
public static void Transform(in Float4 vector, in Matrix transform, out Float4 result)
{
result = new Float4(vector.X * transform.M11 + vector.Y * transform.M21 + vector.Z * transform.M31 + vector.W * transform.M41,
vector.X * transform.M12 + vector.Y * transform.M22 + vector.Z * transform.M32 + vector.W * transform.M42,
@@ -1042,7 +1042,7 @@ namespace FlaxEngine
/// <returns>The transformed <see cref="Float4" />.</returns>
public static Float4 Transform(Float4 vector, Matrix transform)
{
Transform(ref vector, ref transform, out Float4 result);
Transform(in vector, in transform, out Float4 result);
return result;
}
@@ -1058,7 +1058,7 @@ namespace FlaxEngine
}
/// <summary>
/// Multiplies a vector with another by performing component-wise multiplication equivalent to <see cref="Multiply(ref Float4,ref Float4,out Float4)" />.
/// Multiplies a vector with another by performing component-wise multiplication equivalent to <see cref="Multiply(in Float4,in Float4,out Float4)" />.
/// </summary>
/// <param name="left">The first vector to multiply.</param>
/// <param name="right">The second vector to multiply.</param>
@@ -1288,7 +1288,7 @@ namespace FlaxEngine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Float4 left, Float4 right)
{
return left.Equals(ref right);
return left.Equals(in right);
}
/// <summary>
@@ -1300,7 +1300,7 @@ namespace FlaxEngine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Float4 left, Float4 right)
{
return !left.Equals(ref right);
return !left.Equals(in right);
}
/// <summary>
@@ -1417,7 +1417,7 @@ namespace FlaxEngine
/// </summary>
/// <param name="other">The <see cref="Float4" /> to compare with this instance.</param>
/// <returns><c>true</c> if the specified <see cref="Float4" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public bool Equals(ref Float4 other)
public bool Equals(in Float4 other)
{
return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
}
@@ -1430,7 +1430,7 @@ namespace FlaxEngine
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(Float4 other)
{
return Equals(ref other);
return Equals(in other);
}
/// <summary>
@@ -1440,7 +1440,7 @@ namespace FlaxEngine
/// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
public override bool Equals(object value)
{
return value is Float4 other && Equals(ref other);
return value is Float4 other && Equals(in other);
}
}
}