mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 04:58:24 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
12 changed files with 784842 additions and 0 deletions
57
Brutal.Numerics/Vector/float4/float4.color.gen.cs
Normal file
57
Brutal.Numerics/Vector/float4/float4.color.gen.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// <auto-generated /> - edit Vector.color.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a float4 vector representing an RGB color with full opacity (alpha = 1).
|
||||
/// </summary>
|
||||
/// <param name="r">Red component (0.0 - 1.0).</param>
|
||||
/// <param name="g">Green component (0.0 - 1.0).</param>
|
||||
/// <param name="b">Blue component (0.0 - 1.0).</param>
|
||||
/// <returns>A float4 color with the specified RGB values and alpha set to 1.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Rgb(float r, float g, float b)
|
||||
{
|
||||
return new float4(r, g, b, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a float4 vector representing a grayscale color with full opacity (alpha = 1).
|
||||
/// </summary>
|
||||
/// <param name="v">Single value used for red, green, and blue components (0.0 - 1.0).</param>
|
||||
/// <returns>A float4 grayscale color with the specified value and alpha set to 1.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Grayscale(float v)
|
||||
{
|
||||
return new float4(v, v, v, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a float4 vector representing an RGBA color.
|
||||
/// </summary>
|
||||
/// <param name="r">Red component (0.0 - 1.0).</param>
|
||||
/// <param name="g">Green component (0.0 - 1.0).</param>
|
||||
/// <param name="b">Blue component (0.0 - 1.0).</param>
|
||||
/// <param name="a">Alpha component (0.0 - 1.0).</param>
|
||||
/// <returns>A float4 color with the specified RGBA values.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Rgba(float r, float g, float b, float a)
|
||||
{
|
||||
return new float4(r, g, b, a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a float4 vector representing a grayscale color with a specified alpha value.
|
||||
/// </summary>
|
||||
/// <param name="v">Single value used for red, green, and blue components (0.0 - 1.0).</param>
|
||||
/// <param name="a">Alpha component (0.0 - 1.0).</param>
|
||||
/// <returns>A float4 grayscale color with the specified value and alpha.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Grayscale(float v, float a)
|
||||
{
|
||||
return new float4(v, v, v, a);
|
||||
}
|
||||
}
|
||||
28
Brutal.Numerics/Vector/float4/float4.copy.gen.cs
Normal file
28
Brutal.Numerics/Vector/float4/float4.copy.gen.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// <auto-generated /> - edit Vector.copy.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void CopyTo(Span<float> destination)
|
||||
{
|
||||
if (destination.Length < ComponentCount)
|
||||
throw new ArgumentException("Length must be at least 4.", nameof(destination));
|
||||
|
||||
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(destination)), this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool TryCopyTo(Span<float> destination)
|
||||
{
|
||||
if (destination.Length < ComponentCount)
|
||||
return false;
|
||||
|
||||
Unsafe.WriteUnaligned(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(destination)), this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
41
Brutal.Numerics/Vector/float4/float4.equality.gen.cs
Normal file
41
Brutal.Numerics/Vector/float4/float4.equality.gen.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// <auto-generated /> - edit Vector.equality.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public readonly override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Y, Z, W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(float4 other)
|
||||
{
|
||||
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && W.Equals(other.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly override bool Equals([NotNullWhen(true)] object? obj)
|
||||
{
|
||||
return obj is float4 other && Equals(other);
|
||||
}
|
||||
|
||||
/// <summary>IEEE lane-wise equality over every component: any NaN component makes this false (contrast <see cref="Equals(float4)" />, which is NaN-reflexive), and -0 equals +0.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(float4 a, float4 b)
|
||||
{
|
||||
return a.X == b.X && a.Y == b.Y && a.Z == b.Z && a.W == b.W;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(float4 a, float4 b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
}
|
||||
92
Brutal.Numerics/Vector/float4/float4.format.gen.cs
Normal file
92
Brutal.Numerics/Vector/float4/float4.format.gen.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// <auto-generated /> - edit Vector.format.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4 : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public readonly override string ToString()
|
||||
{
|
||||
return ToString("G", CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.ToString(string?)" />
|
||||
public readonly string ToString(string? format)
|
||||
{
|
||||
return ToString(format, CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public readonly string ToString(string? format, IFormatProvider? formatProvider)
|
||||
{
|
||||
var separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator;
|
||||
return $"<{X.ToString(format, formatProvider)}{separator} {Y.ToString(format, formatProvider)}{separator} {Z.ToString(format, formatProvider)}{separator} {W.ToString(format, formatProvider)}>";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
|
||||
{
|
||||
return StringHelpers.TryFormat<float4, float>(this, destination, out charsWritten, format, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public readonly bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
|
||||
{
|
||||
return StringHelpers.TryFormat<float4, float>(this, destination, out bytesWritten, format, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static float4 Parse(string s, IFormatProvider? provider)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(s);
|
||||
return Parse(s.AsSpan(), NumberStyles.Float, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static float4 Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
|
||||
{
|
||||
return Parse(s, NumberStyles.Float, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static float4 Parse(string s, NumberStyles style, IFormatProvider? provider)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(s);
|
||||
return Parse(s.AsSpan(), style, provider);
|
||||
}
|
||||
|
||||
/// <summary>Parses from the <see cref="ToString()" /> format, <c><1, 2, 3></c>.</summary>
|
||||
/// <exception cref="FormatException">The input is not in a valid format, or a component fails to parse.</exception>
|
||||
public static float4 Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider)
|
||||
{
|
||||
if (!TryParse(s, style, provider, out var result))
|
||||
throw new FormatException($"'{s}' is not in a valid float4 format.");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float4)" />
|
||||
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out float4 result)
|
||||
{
|
||||
return TryParse(s.AsSpan(), NumberStyles.Float, provider, out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float4)" />
|
||||
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out float4 result)
|
||||
{
|
||||
return TryParse(s, NumberStyles.Float, provider, out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out float4)" />
|
||||
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out float4 result)
|
||||
{
|
||||
return TryParse(s.AsSpan(), style, provider, out result);
|
||||
}
|
||||
|
||||
/// <summary>Parses from the <see cref="ToString()" /> format, <c><1, 2, 3></c>.</summary>
|
||||
/// <returns>true if the input parsed as a float4.</returns>
|
||||
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out float4 result)
|
||||
{
|
||||
return StringHelpers.TryParse<float4, float>(s, style, provider, out result);
|
||||
}
|
||||
}
|
||||
148
Brutal.Numerics/Vector/float4/float4.gen.cs
Normal file
148
Brutal.Numerics/Vector/float4/float4.gen.cs
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
// <auto-generated /> - edit Vector.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
/// <summary>
|
||||
/// Implements a 4D vector with float components.
|
||||
/// </summary>
|
||||
[DebuggerTypeProxy(typeof(VectorDebugView4<float4, float, float>))]
|
||||
public partial struct float4 : IVector4<float4, float>
|
||||
, IFloatingVector<float4, float>
|
||||
, IFloatingVector4<float4, float, float2, float3, floatQuat, float4x4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static int ComponentSize => sizeof(float);
|
||||
|
||||
/// <summary>Gets the number of components.</summary>
|
||||
public static int ComponentCount => 4;
|
||||
|
||||
/// <inheritdoc cref="Vector4.X" />
|
||||
[XmlAttribute]
|
||||
public float X;
|
||||
|
||||
/// <inheritdoc cref="Vector4.Y" />
|
||||
[XmlAttribute]
|
||||
public float Y;
|
||||
|
||||
/// <inheritdoc cref="Vector4.Z" />
|
||||
[XmlAttribute]
|
||||
public float Z;
|
||||
|
||||
/// <inheritdoc cref="Vector4.W" />
|
||||
[XmlAttribute]
|
||||
public float W;
|
||||
|
||||
float IVector4<float4, float>.X { readonly get => X; set => X = value; }
|
||||
|
||||
float IVector4<float4, float>.Y { readonly get => Y; set => Y = value; }
|
||||
|
||||
float IVector4<float4, float>.Z { readonly get => Z; set => Z = value; }
|
||||
|
||||
float IVector4<float4, float>.W { readonly get => W; set => W = value; }
|
||||
|
||||
/// <inheritdoc cref="Vector4(float, float, float, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(float x, float y, float z, float w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4(float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(float xyzw)
|
||||
: this(xyzw, xyzw, xyzw, xyzw) { }
|
||||
|
||||
/// <inheritdoc cref="Vector4(Vector3, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(float3 xyz, float w)
|
||||
: this(xyz.X, xyz.Y, xyz.Z, w) { }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="float4" /> from two <see cref="float2" /> instances.
|
||||
/// </summary>
|
||||
/// <param name="xy">The first two components.</param>
|
||||
/// <param name="zw">The last two components.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(float2 xy, float2 zw)
|
||||
: this(xy.X, xy.Y, zw.X, zw.Y) { }
|
||||
|
||||
/// <inheritdoc cref="Vector4(Vector2, float, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(float2 xy, float z, float w)
|
||||
: this(xy.X, xy.Y, z, w) { }
|
||||
|
||||
/// <summary>Creates a vector from the leading 4 elements of a span.</summary>
|
||||
/// <param name="span">The elements to read; must contain at least 4, and any beyond that are ignored.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException"><paramref name="span" /> holds fewer than 4 elements.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float4(ReadOnlySpan<float> span)
|
||||
{
|
||||
if (span.Length < 4)
|
||||
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
|
||||
|
||||
this = Unsafe.ReadUnaligned<float4>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float4(ReadOnlySpan{float})" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static float4 IComponentTuple<float4, float>.Create(ReadOnlySpan<float> span) => new(span);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 UnitX => new(1, 0, 0, 0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 UnitY => new(0, 1, 0, 0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 UnitZ => new(0, 0, 1, 0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 UnitW => new(0, 0, 0, 1);
|
||||
|
||||
/// <inheritdoc />
|
||||
public float this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
readonly get
|
||||
{
|
||||
if ((uint)index >= ComponentCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
return Unsafe.Add(ref Unsafe.AsRef(in X), index);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set
|
||||
{
|
||||
if ((uint)index >= ComponentCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
Unsafe.Add(ref X, index) = value;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly void Deconstruct(out float x, out float y, out float z, out float w)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
w = W;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<float> AsSpan()
|
||||
{
|
||||
return MemoryMarshal.CreateSpan(ref Unsafe.As<float4, float>(ref this), 4);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ReadOnlySpan<float> AsReadOnlySpan()
|
||||
{
|
||||
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<float4, float>(ref Unsafe.AsRef(in this)), 4);
|
||||
}
|
||||
}
|
||||
62
Brutal.Numerics/Vector/float4/float4.math-metric.gen.cs
Normal file
62
Brutal.Numerics/Vector/float4/float4.math-metric.gen.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// <auto-generated /> - edit Vector.math-metric.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly float Length()
|
||||
{
|
||||
return float.Sqrt(LengthSquared());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly float LengthSquared()
|
||||
{
|
||||
return Dot(this, this);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Distance" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Distance(float4 a, float4 b)
|
||||
{
|
||||
return float.Sqrt(DistanceSquared(a, b));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.DistanceSquared" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float DistanceSquared(float4 a, float4 b)
|
||||
{
|
||||
var difference = a - b;
|
||||
return Dot(difference, difference);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Dot" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Dot(float4 a, float4 b)
|
||||
{
|
||||
return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Normalize" />
|
||||
/// <exception cref="DivideByZeroException">Thrown when the input vector is a zero vector.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Normalize(float4 value)
|
||||
{
|
||||
var lengthSquared = Dot(value, value);
|
||||
if (lengthSquared == 0)
|
||||
throw new DivideByZeroException();
|
||||
return value / float.Sqrt(lengthSquared);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 NormalizeOrZero(float4 value)
|
||||
{
|
||||
var length = float.Sqrt(Dot(value, value));
|
||||
return length == 0 ? Zero : value / length;
|
||||
}
|
||||
}
|
||||
93
Brutal.Numerics/Vector/float4/float4.math.gen.cs
Normal file
93
Brutal.Numerics/Vector/float4/float4.math.gen.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
// <auto-generated /> - edit Vector.math.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
/// <inheritdoc cref="float4.Multiply(float4, float4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Multiply(float4 vector, float4x4 matrix)
|
||||
{
|
||||
var result = matrix.X * vector.X;
|
||||
|
||||
result += matrix.Y * vector.Y;
|
||||
result += matrix.Z * vector.Z;
|
||||
result += matrix.W * vector.W;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Multiply(float4, float4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator *(float4 vector, float4x4 matrix)
|
||||
{
|
||||
return Multiply(vector, matrix);
|
||||
}
|
||||
|
||||
/// <summary>Reflects a vector off the hyperplane with the given unit normal.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Reflect(float4 vector, float4 normal)
|
||||
{
|
||||
return vector - 2 * Dot(vector, normal) * normal;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector2, Matrix4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float2 position, float4x4 matrix)
|
||||
{
|
||||
var result = matrix.X * position.X;
|
||||
|
||||
result += matrix.Y * position.Y;
|
||||
result += matrix.W;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector2, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float2 value, floatQuat rotation)
|
||||
{
|
||||
// widen in a register: x, y, 0, 1
|
||||
var wide = Unsafe.BitCast<Vector128<float>, float4>(Vector128.Create(value.X, value.Y, 0.0f, 1.0f));
|
||||
return Transform(wide, rotation);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector3, Matrix4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float3 position, float4x4 matrix)
|
||||
{
|
||||
var result = matrix.X * position.X;
|
||||
|
||||
result += matrix.Y * position.Y;
|
||||
result += matrix.Z * position.Z;
|
||||
result += matrix.W;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector3, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float3 value, floatQuat rotation)
|
||||
{
|
||||
// widen in a register: x, y, z, 1
|
||||
var wide = Unsafe.BitCast<Vector128<float>, float4>(Vector128.Create(value.X, value.Y, value.Z, 1.0f));
|
||||
return Transform(wide, rotation);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector4, Matrix4x4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float4 vector, float4x4 matrix)
|
||||
{
|
||||
return Multiply(vector, matrix);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Transform(Vector4, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Transform(float4 value, floatQuat rotation)
|
||||
{
|
||||
var conjugate = floatQuat.Conjugate(rotation);
|
||||
var temp = floatQuat.Concatenate(conjugate, Unsafe.BitCast<float4, floatQuat>(value));
|
||||
return Unsafe.BitCast<floatQuat, float4>(floatQuat.Concatenate(temp, rotation));
|
||||
}
|
||||
}
|
||||
54
Brutal.Numerics/Vector/float4/float4.numerics-binary.gen.cs
Normal file
54
Brutal.Numerics/Vector/float4/float4.numerics-binary.gen.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
// <auto-generated /> - edit Vector.numerics-binary.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
// IBinaryNumber
|
||||
public partial struct float4 : IBinaryNumber<float4>
|
||||
{
|
||||
/// <summary>Determines if every component of a value is a power of two.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool IBinaryNumber<float4>.IsPow2(float4 value)
|
||||
{
|
||||
return float.IsPow2(value.X) && float.IsPow2(value.Y) && float.IsPow2(value.Z) && float.IsPow2(value.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static float4 IBitwiseOperators<float4, float4, float4>.operator &(float4 a, float4 b)
|
||||
{
|
||||
return Unsafe.BitCast<int4, float4>(Unsafe.BitCast<float4, int4>(a) & Unsafe.BitCast<float4, int4>(b));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static float4 IBitwiseOperators<float4, float4, float4>.operator |(float4 a, float4 b)
|
||||
{
|
||||
return Unsafe.BitCast<int4, float4>(Unsafe.BitCast<float4, int4>(a) | Unsafe.BitCast<float4, int4>(b));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static float4 IBitwiseOperators<float4, float4, float4>.operator ^(float4 a, float4 b)
|
||||
{
|
||||
return Unsafe.BitCast<int4, float4>(Unsafe.BitCast<float4, int4>(a) ^ Unsafe.BitCast<float4, int4>(b));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static float4 IBitwiseOperators<float4, float4, float4>.operator ~(float4 value)
|
||||
{
|
||||
return Unsafe.BitCast<int4, float4>(~Unsafe.BitCast<float4, int4>(value));
|
||||
}
|
||||
}
|
||||
|
||||
// the componentwise predicate mask (no interface to mirror) - the per-lane truth IsPow2 collapses
|
||||
public partial struct float4
|
||||
{
|
||||
/// <summary>Determines which components of a value are powers of two.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsPow2(float4 value)
|
||||
{
|
||||
return new bool4(float.IsPow2(value.X), float.IsPow2(value.Y), float.IsPow2(value.Z), float.IsPow2(value.W));
|
||||
}
|
||||
}
|
||||
447
Brutal.Numerics/Vector/float4/float4.numerics-floating.gen.cs
Normal file
447
Brutal.Numerics/Vector/float4/float4.numerics-floating.gen.cs
Normal file
|
|
@ -0,0 +1,447 @@
|
|||
// <auto-generated /> - edit Vector.numerics-floating.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
// IFloatingPointConstants
|
||||
public partial struct float4 : IFloatingPointConstants<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static float4 E => new(float.E);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 Pi => new(float.Pi);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 Tau => new(float.Tau);
|
||||
}
|
||||
|
||||
// IExponentialFunctions
|
||||
public partial struct float4 : IExponentialFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <remarks>NOTE: the vectorized float kernel is not exact at zero.
|
||||
/// It returns 1 ulp above <c>One</c>, so <c>Exp(Zero)</c> does not give back <c>One</c>.
|
||||
/// Legal under the vectorized-math accuracy contract, and the double kernel is exact.
|
||||
/// Upstream: https://github.com/dotnet/runtime/issues/118841.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Exp(float4 value)
|
||||
{
|
||||
return new(float.Exp(value.X), float.Exp(value.Y), float.Exp(value.Z), float.Exp(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Exp2(float4 value)
|
||||
{
|
||||
return new float4(float.Exp2(value.X), float.Exp2(value.Y), float.Exp2(value.Z), float.Exp2(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Exp10(float4 value)
|
||||
{
|
||||
return new float4(float.Exp10(value.X), float.Exp10(value.Y), float.Exp10(value.Z), float.Exp10(value.W));
|
||||
}
|
||||
}
|
||||
|
||||
// ILogarithmicFunctions
|
||||
public partial struct float4 : ILogarithmicFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Log(float4 value)
|
||||
{
|
||||
return new(float.Log(value.X), float.Log(value.Y), float.Log(value.Z), float.Log(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Log(float4 value, float4 newBase)
|
||||
{
|
||||
return new float4(float.Log(value.X, newBase.X), float.Log(value.Y, newBase.Y), float.Log(value.Z, newBase.Z), float.Log(value.W, newBase.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Log2(float4 value)
|
||||
{
|
||||
return new(float.Log2(value.X), float.Log2(value.Y), float.Log2(value.Z), float.Log2(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Log10(float4 value)
|
||||
{
|
||||
return new float4(float.Log10(value.X), float.Log10(value.Y), float.Log10(value.Z), float.Log10(value.W));
|
||||
}
|
||||
}
|
||||
|
||||
// IPowerFunctions
|
||||
public partial struct float4 : IPowerFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Pow(float4 value, float4 power)
|
||||
{
|
||||
return new float4(float.Pow(value.X, power.X), float.Pow(value.Y, power.Y), float.Pow(value.Z, power.Z), float.Pow(value.W, power.W));
|
||||
}
|
||||
}
|
||||
|
||||
// IRootFunctions
|
||||
public partial struct float4 : IRootFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Cbrt(float4 value)
|
||||
{
|
||||
return new float4(float.Cbrt(value.X), float.Cbrt(value.Y), float.Cbrt(value.Z), float.Cbrt(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Hypot(float4 a, float4 b)
|
||||
{
|
||||
return new(float.Hypot(a.X, b.X), float.Hypot(a.Y, b.Y), float.Hypot(a.Z, b.Z), float.Hypot(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 RootN(float4 value, int n)
|
||||
{
|
||||
return new float4(float.RootN(value.X, n), float.RootN(value.Y, n), float.RootN(value.Z, n), float.RootN(value.W, n));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Sqrt(float4 value)
|
||||
{
|
||||
return new(float.Sqrt(value.X), float.Sqrt(value.Y), float.Sqrt(value.Z), float.Sqrt(value.W));
|
||||
}
|
||||
}
|
||||
|
||||
// ITrigonometricFunctions
|
||||
public partial struct float4 : ITrigonometricFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Sin(float4 value)
|
||||
{
|
||||
return new(float.Sin(value.X), float.Sin(value.Y), float.Sin(value.Z), float.Sin(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Cos(float4 value)
|
||||
{
|
||||
return new(float.Cos(value.X), float.Cos(value.Y), float.Cos(value.Z), float.Cos(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static (float4 Sin, float4 Cos) SinCos(float4 value)
|
||||
{
|
||||
var (sinX, cosX) = float.SinCos(value.X);
|
||||
var (sinY, cosY) = float.SinCos(value.Y);
|
||||
var (sinZ, cosZ) = float.SinCos(value.Z);
|
||||
var (sinW, cosW) = float.SinCos(value.W);
|
||||
return (new(sinX, sinY, sinZ, sinW), new(cosX, cosY, cosZ, cosW));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Tan(float4 value)
|
||||
{
|
||||
return new float4(float.Tan(value.X), float.Tan(value.Y), float.Tan(value.Z), float.Tan(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Asin(float4 value)
|
||||
{
|
||||
return new float4(float.Asin(value.X), float.Asin(value.Y), float.Asin(value.Z), float.Asin(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Acos(float4 value)
|
||||
{
|
||||
return new float4(float.Acos(value.X), float.Acos(value.Y), float.Acos(value.Z), float.Acos(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Atan(float4 value)
|
||||
{
|
||||
return new float4(float.Atan(value.X), float.Atan(value.Y), float.Atan(value.Z), float.Atan(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 SinPi(float4 value)
|
||||
{
|
||||
return new float4(float.SinPi(value.X), float.SinPi(value.Y), float.SinPi(value.Z), float.SinPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 CosPi(float4 value)
|
||||
{
|
||||
return new float4(float.CosPi(value.X), float.CosPi(value.Y), float.CosPi(value.Z), float.CosPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 TanPi(float4 value)
|
||||
{
|
||||
return new float4(float.TanPi(value.X), float.TanPi(value.Y), float.TanPi(value.Z), float.TanPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 AsinPi(float4 value)
|
||||
{
|
||||
return new float4(float.AsinPi(value.X), float.AsinPi(value.Y), float.AsinPi(value.Z), float.AsinPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 AcosPi(float4 value)
|
||||
{
|
||||
return new float4(float.AcosPi(value.X), float.AcosPi(value.Y), float.AcosPi(value.Z), float.AcosPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 AtanPi(float4 value)
|
||||
{
|
||||
return new float4(float.AtanPi(value.X), float.AtanPi(value.Y), float.AtanPi(value.Z), float.AtanPi(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static (float4 SinPi, float4 CosPi) SinCosPi(float4 value)
|
||||
{
|
||||
return (SinPi(value), CosPi(value));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.DegreesToRadians" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 DegreesToRadians(float4 degrees)
|
||||
{
|
||||
return new(float.DegreesToRadians(degrees.X), float.DegreesToRadians(degrees.Y), float.DegreesToRadians(degrees.Z), float.DegreesToRadians(degrees.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.RadiansToDegrees" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 RadiansToDegrees(float4 radians)
|
||||
{
|
||||
return new(float.RadiansToDegrees(radians.X), float.RadiansToDegrees(radians.Y), float.RadiansToDegrees(radians.Z), float.RadiansToDegrees(radians.W));
|
||||
}
|
||||
}
|
||||
|
||||
// IHyperbolicFunctions
|
||||
public partial struct float4 : IHyperbolicFunctions<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Sinh(float4 value)
|
||||
{
|
||||
return new float4(float.Sinh(value.X), float.Sinh(value.Y), float.Sinh(value.Z), float.Sinh(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Cosh(float4 value)
|
||||
{
|
||||
return new float4(float.Cosh(value.X), float.Cosh(value.Y), float.Cosh(value.Z), float.Cosh(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Tanh(float4 value)
|
||||
{
|
||||
return new float4(float.Tanh(value.X), float.Tanh(value.Y), float.Tanh(value.Z), float.Tanh(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Asinh(float4 value)
|
||||
{
|
||||
return new float4(float.Asinh(value.X), float.Asinh(value.Y), float.Asinh(value.Z), float.Asinh(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Acosh(float4 value)
|
||||
{
|
||||
return new float4(float.Acosh(value.X), float.Acosh(value.Y), float.Acosh(value.Z), float.Acosh(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Atanh(float4 value)
|
||||
{
|
||||
return new float4(float.Atanh(value.X), float.Atanh(value.Y), float.Atanh(value.Z), float.Atanh(value.W));
|
||||
}
|
||||
}
|
||||
|
||||
// IFloatingPoint
|
||||
public partial struct float4 : IFloatingPoint<float4>
|
||||
{
|
||||
/// <inheritdoc cref="float.Floor(float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Floor(float4 value)
|
||||
{
|
||||
return new(float.Floor(value.X), float.Floor(value.Y), float.Floor(value.Z), float.Floor(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Ceiling(float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Ceiling(float4 value)
|
||||
{
|
||||
return new(float.Ceiling(value.X), float.Ceiling(value.Y), float.Ceiling(value.Z), float.Ceiling(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Round(float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Round(float4 value)
|
||||
{
|
||||
return new(float.Round(value.X), float.Round(value.Y), float.Round(value.Z), float.Round(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Truncate(float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Truncate(float4 value)
|
||||
{
|
||||
return new(float.Truncate(value.X), float.Truncate(value.Y), float.Truncate(value.Z), float.Truncate(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Round(float, int, MidpointRounding)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Round(float4 value, int digits, MidpointRounding mode)
|
||||
{
|
||||
return new float4(float.Round(value.X, digits, mode), float.Round(value.Y, digits, mode), float.Round(value.Z, digits, mode), float.Round(value.W, digits, mode));
|
||||
}
|
||||
|
||||
// One exponent and significand PER LANE, so there is no single honest answer: explicit and throwing.
|
||||
|
||||
int IFloatingPoint<float4>.GetExponentByteCount() =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one exponent per component.");
|
||||
|
||||
int IFloatingPoint<float4>.GetExponentShortestBitLength() =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one exponent per component.");
|
||||
|
||||
int IFloatingPoint<float4>.GetSignificandBitLength() =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one significand per component.");
|
||||
|
||||
int IFloatingPoint<float4>.GetSignificandByteCount() =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one significand per component.");
|
||||
|
||||
bool IFloatingPoint<float4>.TryWriteExponentBigEndian(Span<byte> destination, out int bytesWritten) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one exponent per component.");
|
||||
|
||||
bool IFloatingPoint<float4>.TryWriteExponentLittleEndian(Span<byte> destination, out int bytesWritten) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one exponent per component.");
|
||||
|
||||
bool IFloatingPoint<float4>.TryWriteSignificandBigEndian(Span<byte> destination, out int bytesWritten) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one significand per component.");
|
||||
|
||||
bool IFloatingPoint<float4>.TryWriteSignificandLittleEndian(Span<byte> destination, out int bytesWritten) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one significand per component.");
|
||||
}
|
||||
|
||||
// IFloatingPointIeee754
|
||||
public partial struct float4 : IFloatingPointIeee754<float4>
|
||||
{
|
||||
/// <summary>Gets a vector whose components are NaN.</summary>
|
||||
public static float4 NaN => new(float.NaN);
|
||||
|
||||
/// <inheritdoc cref="float.Epsilon" />
|
||||
public static float4 Epsilon => new(float.Epsilon);
|
||||
|
||||
/// <inheritdoc cref="float.NegativeZero" />
|
||||
public static float4 NegativeZero => new(float.NegativeZero);
|
||||
|
||||
/// <inheritdoc cref="float.PositiveInfinity" />
|
||||
public static float4 PositiveInfinity => new(float.PositiveInfinity);
|
||||
|
||||
/// <inheritdoc cref="float.NegativeInfinity" />
|
||||
public static float4 NegativeInfinity => new(float.NegativeInfinity);
|
||||
|
||||
/// <inheritdoc cref="float.Atan2" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Atan2(float4 y, float4 x)
|
||||
{
|
||||
return new float4(float.Atan2(y.X, x.X), float.Atan2(y.Y, x.Y), float.Atan2(y.Z, x.Z), float.Atan2(y.W, x.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Atan2Pi" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Atan2Pi(float4 y, float4 x)
|
||||
{
|
||||
return new float4(float.Atan2Pi(y.X, x.X), float.Atan2Pi(y.Y, x.Y), float.Atan2Pi(y.Z, x.Z), float.Atan2Pi(y.W, x.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.BitDecrement" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 BitDecrement(float4 value)
|
||||
{
|
||||
return new float4(float.BitDecrement(value.X), float.BitDecrement(value.Y), float.BitDecrement(value.Z), float.BitDecrement(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.BitIncrement" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 BitIncrement(float4 value)
|
||||
{
|
||||
return new float4(float.BitIncrement(value.X), float.BitIncrement(value.Y), float.BitIncrement(value.Z), float.BitIncrement(value.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.FusedMultiplyAdd" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 FusedMultiplyAdd(float4 a, float4 b, float4 addend)
|
||||
{
|
||||
return new(float.FusedMultiplyAdd(a.X, b.X, addend.X), float.FusedMultiplyAdd(a.Y, b.Y, addend.Y), float.FusedMultiplyAdd(a.Z, b.Z, addend.Z), float.FusedMultiplyAdd(a.W, b.W, addend.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.MultiplyAddEstimate" />
|
||||
/// <remarks>Permitted but not required to fuse; use <see cref="FusedMultiplyAdd" /> where the single rounding is required.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MultiplyAddEstimate(float4 a, float4 b, float4 addend)
|
||||
{
|
||||
return new(float.MultiplyAddEstimate(a.X, b.X, addend.X), float.MultiplyAddEstimate(a.Y, b.Y, addend.Y), float.MultiplyAddEstimate(a.Z, b.Z, addend.Z), float.MultiplyAddEstimate(a.W, b.W, addend.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.Ieee754Remainder" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Ieee754Remainder(float4 a, float4 b)
|
||||
{
|
||||
return new float4(float.Ieee754Remainder(a.X, b.X), float.Ieee754Remainder(a.Y, b.Y), float.Ieee754Remainder(a.Z, b.Z), float.Ieee754Remainder(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float.ScaleB" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 ScaleB(float4 value, int n)
|
||||
{
|
||||
return new float4(float.ScaleB(value.X, n), float.ScaleB(value.Y, n), float.ScaleB(value.Z, n), float.ScaleB(value.W, n));
|
||||
}
|
||||
|
||||
// ILogB's int return cannot hold one exponent per lane - same shape as Sign
|
||||
static int IFloatingPointIeee754<float4>.ILogB(float4 value) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has one exponent per component.");
|
||||
|
||||
/// <inheritdoc cref="Vector4.Lerp(Vector4, Vector4, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Lerp(float4 a, float4 b, float amount)
|
||||
{
|
||||
return new(float.Lerp(a.X, b.X, amount), float.Lerp(a.Y, b.Y, amount), float.Lerp(a.Z, b.Z, amount), float.Lerp(a.W, b.W, amount));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Sqrt" />
|
||||
[Obsolete("Renamed to Sqrt (the generic-math name; SquareRoot was the System.Numerics vector spelling).")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 SquareRoot(float4 value)
|
||||
{
|
||||
return Sqrt(value);
|
||||
}
|
||||
}
|
||||
545
Brutal.Numerics/Vector/float4/float4.numerics.gen.cs
Normal file
545
Brutal.Numerics/Vector/float4/float4.numerics.gen.cs
Normal file
|
|
@ -0,0 +1,545 @@
|
|||
// <auto-generated /> - edit Vector.numerics.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
// INumberBase
|
||||
public partial struct float4 : INumberBase<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static float4 Zero => new(0);
|
||||
|
||||
/// <inheritdoc />
|
||||
public static float4 One => new(1);
|
||||
|
||||
static float4 IAdditiveIdentity<float4, float4>.AdditiveIdentity => Zero;
|
||||
|
||||
static float4 IMultiplicativeIdentity<float4, float4>.MultiplicativeIdentity => One;
|
||||
|
||||
static int INumberBase<float4>.Radix => 2; // every component type is binary
|
||||
|
||||
/// <inheritdoc cref="Vector4.Abs" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Abs(float4 value)
|
||||
{
|
||||
return new(float.Abs(value.X), float.Abs(value.Y), float.Abs(value.Z), float.Abs(value.W));
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.IsCanonical(float4 value) => true;
|
||||
|
||||
static bool INumberBase<float4>.IsComplexNumber(float4 value) => false;
|
||||
|
||||
static bool INumberBase<float4>.IsImaginaryNumber(float4 value) => false;
|
||||
|
||||
/// <summary>Determines if every component of a value is zero.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsZero(float4 value)
|
||||
{
|
||||
return value == Zero;
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is an even integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsEvenInteger(float4 value)
|
||||
{
|
||||
return float.IsEvenInteger(value.X) && float.IsEvenInteger(value.Y) && float.IsEvenInteger(value.Z) && float.IsEvenInteger(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is an odd integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsOddInteger(float4 value)
|
||||
{
|
||||
return float.IsOddInteger(value.X) && float.IsOddInteger(value.Y) && float.IsOddInteger(value.Z) && float.IsOddInteger(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is negative.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsNegative(float4 value)
|
||||
{
|
||||
return float.IsNegative(value.X) && float.IsNegative(value.Y) && float.IsNegative(value.Z) && float.IsNegative(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is positive.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsPositive(float4 value)
|
||||
{
|
||||
return float.IsPositive(value.X) && float.IsPositive(value.Y) && float.IsPositive(value.Z) && float.IsPositive(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is finite.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsFinite(float4 value)
|
||||
{
|
||||
return float.IsFinite(value.X) && float.IsFinite(value.Y) && float.IsFinite(value.Z) && float.IsFinite(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is infinite.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsInfinity(float4 value)
|
||||
{
|
||||
return float.IsInfinity(value.X) && float.IsInfinity(value.Y) && float.IsInfinity(value.Z) && float.IsInfinity(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is negative infinity.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsNegativeInfinity(float4 value)
|
||||
{
|
||||
return float.IsNegativeInfinity(value.X) && float.IsNegativeInfinity(value.Y) && float.IsNegativeInfinity(value.Z) && float.IsNegativeInfinity(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is positive infinity.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsPositiveInfinity(float4 value)
|
||||
{
|
||||
return float.IsPositiveInfinity(value.X) && float.IsPositiveInfinity(value.Y) && float.IsPositiveInfinity(value.Z) && float.IsPositiveInfinity(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is an integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsInteger(float4 value)
|
||||
{
|
||||
return float.IsInteger(value.X) && float.IsInteger(value.Y) && float.IsInteger(value.Z) && float.IsInteger(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is a real value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsRealNumber(float4 value)
|
||||
{
|
||||
return float.IsRealNumber(value.X) && float.IsRealNumber(value.Y) && float.IsRealNumber(value.Z) && float.IsRealNumber(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if any component of a value is NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsNaN(float4 value)
|
||||
{
|
||||
return float.IsNaN(value.X) || float.IsNaN(value.Y) || float.IsNaN(value.Z) || float.IsNaN(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is normal.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsNormal(float4 value)
|
||||
{
|
||||
return float.IsNormal(value.X) && float.IsNormal(value.Y) && float.IsNormal(value.Z) && float.IsNormal(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines if every component of a value is subnormal.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static bool INumberBase<float4>.IsSubnormal(float4 value)
|
||||
{
|
||||
return float.IsSubnormal(value.X) && float.IsSubnormal(value.Y) && float.IsSubnormal(value.Z) && float.IsSubnormal(value.W);
|
||||
}
|
||||
|
||||
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MaxMagnitude(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MaxMagnitude(a.X, b.X), float.MaxMagnitude(a.Y, b.Y), float.MaxMagnitude(a.Z, b.Z), float.MaxMagnitude(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Computes, componentwise, the value whose magnitude is greater, preferring numbers over NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MaxMagnitudeNumber(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MaxMagnitudeNumber(a.X, b.X), float.MaxMagnitudeNumber(a.Y, b.Y), float.MaxMagnitudeNumber(a.Z, b.Z), float.MaxMagnitudeNumber(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MinMagnitude(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MinMagnitude(a.X, b.X), float.MinMagnitude(a.Y, b.Y), float.MinMagnitude(a.Z, b.Z), float.MinMagnitude(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Computes, componentwise, the value whose magnitude is smaller, preferring numbers over NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MinMagnitudeNumber(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MinMagnitudeNumber(a.X, b.X), float.MinMagnitudeNumber(a.Y, b.Y), float.MinMagnitudeNumber(a.Z, b.Z), float.MinMagnitudeNumber(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Add" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Add(float4 a, float4 b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Divide(Vector4, Vector4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Divide(float4 a, float4 b)
|
||||
{
|
||||
return a / b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Multiply(Vector4, Vector4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Multiply(float4 a, float4 b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Negate" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Negate(float4 value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Subtract" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Subtract(float4 a, float4 b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator +(float4 a, float4 b)
|
||||
{
|
||||
return new(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator -(float4 a, float4 b)
|
||||
{
|
||||
return new(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator *(float4 a, float4 b)
|
||||
{
|
||||
return new(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator /(float4 a, float4 b)
|
||||
{
|
||||
return new(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator -(float4 a)
|
||||
{
|
||||
return new(-a.X, -a.Y, -a.Z, -a.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator +(float4 a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
|
||||
|
||||
static float4 IIncrementOperators<float4>.operator ++(float4 value) => value + One;
|
||||
|
||||
static float4 IDecrementOperators<float4>.operator --(float4 value) => value - One;
|
||||
|
||||
|
||||
static bool INumberBase<float4>.TryConvertFromChecked<TOther>(TOther value, out float4 result)
|
||||
{
|
||||
return NumberConversion.TryConvertFrom<float4, float, TOther, NumberConversion.Checked>(value, out result);
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.TryConvertToChecked<TOther>(float4 value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.TryConvertFromSaturating<TOther>(TOther value, out float4 result)
|
||||
{
|
||||
return NumberConversion.TryConvertFrom<float4, float, TOther, NumberConversion.Saturating>(value, out result);
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.TryConvertToSaturating<TOther>(float4 value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.TryConvertFromTruncating<TOther>(TOther value, out float4 result)
|
||||
{
|
||||
return NumberConversion.TryConvertFrom<float4, float, TOther, NumberConversion.Truncating>(value, out result);
|
||||
}
|
||||
|
||||
static bool INumberBase<float4>.TryConvertToTruncating<TOther>(float4 value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
|
||||
public partial struct float4
|
||||
: IMultiplyOperators<float4, float, float4>
|
||||
, IDivisionOperators<float4, float, float4>
|
||||
{
|
||||
/// <inheritdoc cref="Vector4.Divide(Vector4, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Divide(float4 a, float b)
|
||||
{
|
||||
return a / b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Multiply(Vector4, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Multiply(float4 a, float b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Multiply(float, Vector4)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Multiply(float a, float4 b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator *(float4 a, float b)
|
||||
{
|
||||
return new(a.X * b, a.Y * b, a.Z * b, a.W * b);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator /(float4 a, float b)
|
||||
{
|
||||
return new(a.X / b, a.Y / b, a.Z / b, a.W / b);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator *(float a, float4 b)
|
||||
{
|
||||
return new(a * b.X, a * b.Y, a * b.Z, a * b.W);
|
||||
}
|
||||
}
|
||||
|
||||
// INumber
|
||||
public partial struct float4 : INumber<float4>
|
||||
{
|
||||
/// <inheritdoc cref="Vector4.Clamp" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Clamp(float4 value, float4 min, float4 max)
|
||||
{
|
||||
// HLSL contract when min > max: max wins (clamp is Max-then-Min); pinned in
|
||||
// Clamp_InvertedBounds_MatchesBcl. NOT scalar T.Clamp, which throws on inversion.
|
||||
return Min(Max(value, min), max);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Max" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Max(float4 a, float4 b)
|
||||
{
|
||||
return new(float.Max(a.X, b.X), float.Max(a.Y, b.Y), float.Max(a.Z, b.Z), float.Max(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Vector4.Min" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 Min(float4 a, float4 b)
|
||||
{
|
||||
return new(float.Min(a.X, b.X), float.Min(a.Y, b.Y), float.Min(a.Z, b.Z), float.Min(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Selects, componentwise, the larger value, preferring numbers over NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MaxNumber(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MaxNumber(a.X, b.X), float.MaxNumber(a.Y, b.Y), float.MaxNumber(a.Z, b.Z), float.MaxNumber(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Selects, componentwise, the smaller value, preferring numbers over NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 MinNumber(float4 a, float4 b)
|
||||
{
|
||||
return new(float.MinNumber(a.X, b.X), float.MinNumber(a.Y, b.Y), float.MinNumber(a.Z, b.Z), float.MinNumber(a.W, b.W));
|
||||
}
|
||||
|
||||
/// <summary>Copies, componentwise, the sign of <paramref name="sign" /> onto the magnitude of <paramref name="value" />.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 CopySign(float4 value, float4 sign)
|
||||
{
|
||||
return new(float.CopySign(value.X, sign.X), float.CopySign(value.Y, sign.Y), float.CopySign(value.Z, sign.Z), float.CopySign(value.W, sign.W));
|
||||
}
|
||||
|
||||
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
|
||||
static float4 INumber<float4>.ClampNative(float4 value, float4 min, float4 max) => Clamp(value, min, max);
|
||||
|
||||
static float4 INumber<float4>.MaxNative(float4 a, float4 b) => Max(a, b);
|
||||
|
||||
static float4 INumber<float4>.MinNative(float4 a, float4 b) => Min(a, b);
|
||||
|
||||
// Sign's int return cannot hold a per-lane answer, and a collapsed one would lie for mixed signs
|
||||
static int INumber<float4>.Sign(float4 value) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no scalar sign.");
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator %(float4 a, float4 b)
|
||||
{
|
||||
return new float4(a.X % b.X, a.Y % b.Y, a.Z % b.Z, a.W % b.W);
|
||||
}
|
||||
|
||||
int IComparable.CompareTo(object? obj) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
|
||||
int IComparable<float4>.CompareTo(float4 other) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
|
||||
static bool IComparisonOperators<float4, float4, bool>.operator <(float4 a, float4 b) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
|
||||
static bool IComparisonOperators<float4, float4, bool>.operator <=(float4 a, float4 b) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
|
||||
static bool IComparisonOperators<float4, float4, bool>.operator >(float4 a, float4 b) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
|
||||
static bool IComparisonOperators<float4, float4, bool>.operator >=(float4 a, float4 b) =>
|
||||
throw new NotSupportedException($"{nameof(float4)} has no total order.");
|
||||
}
|
||||
|
||||
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
|
||||
public partial struct float4 : IComponentwiseComparison<float4, bool4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 operator <(float4 a, float4 b)
|
||||
{
|
||||
return new bool4(a.X < b.X, a.Y < b.Y, a.Z < b.Z, a.W < b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 operator <=(float4 a, float4 b)
|
||||
{
|
||||
return new bool4(a.X <= b.X, a.Y <= b.Y, a.Z <= b.Z, a.W <= b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 operator >(float4 a, float4 b)
|
||||
{
|
||||
return new bool4(a.X > b.X, a.Y > b.Y, a.Z > b.Z, a.W > b.W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 operator >=(float4 a, float4 b)
|
||||
{
|
||||
return new bool4(a.X >= b.X, a.Y >= b.Y, a.Z >= b.Z, a.W >= b.W);
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are zero.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsZero(float4 value)
|
||||
{
|
||||
return new bool4(value.X == 0, value.Y == 0, value.Z == 0, value.W == 0);
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are an even integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsEvenInteger(float4 value)
|
||||
{
|
||||
return new bool4(float.IsEvenInteger(value.X), float.IsEvenInteger(value.Y), float.IsEvenInteger(value.Z), float.IsEvenInteger(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are an odd integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsOddInteger(float4 value)
|
||||
{
|
||||
return new bool4(float.IsOddInteger(value.X), float.IsOddInteger(value.Y), float.IsOddInteger(value.Z), float.IsOddInteger(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are negative.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsNegative(float4 value)
|
||||
{
|
||||
return new bool4(float.IsNegative(value.X), float.IsNegative(value.Y), float.IsNegative(value.Z), float.IsNegative(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are positive.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsPositive(float4 value)
|
||||
{
|
||||
return new bool4(float.IsPositive(value.X), float.IsPositive(value.Y), float.IsPositive(value.Z), float.IsPositive(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are finite.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsFinite(float4 value)
|
||||
{
|
||||
return new bool4(float.IsFinite(value.X), float.IsFinite(value.Y), float.IsFinite(value.Z), float.IsFinite(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are infinite.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsInfinity(float4 value)
|
||||
{
|
||||
return new bool4(float.IsInfinity(value.X), float.IsInfinity(value.Y), float.IsInfinity(value.Z), float.IsInfinity(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are negative infinity.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsNegativeInfinity(float4 value)
|
||||
{
|
||||
return new bool4(float.IsNegativeInfinity(value.X), float.IsNegativeInfinity(value.Y), float.IsNegativeInfinity(value.Z), float.IsNegativeInfinity(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are positive infinity.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsPositiveInfinity(float4 value)
|
||||
{
|
||||
return new bool4(float.IsPositiveInfinity(value.X), float.IsPositiveInfinity(value.Y), float.IsPositiveInfinity(value.Z), float.IsPositiveInfinity(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are an integral value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsInteger(float4 value)
|
||||
{
|
||||
return new bool4(float.IsInteger(value.X), float.IsInteger(value.Y), float.IsInteger(value.Z), float.IsInteger(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are a real value.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsRealNumber(float4 value)
|
||||
{
|
||||
return new bool4(float.IsRealNumber(value.X), float.IsRealNumber(value.Y), float.IsRealNumber(value.Z), float.IsRealNumber(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are NaN.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsNaN(float4 value)
|
||||
{
|
||||
return new bool4(float.IsNaN(value.X), float.IsNaN(value.Y), float.IsNaN(value.Z), float.IsNaN(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are normal.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsNormal(float4 value)
|
||||
{
|
||||
return new bool4(float.IsNormal(value.X), float.IsNormal(value.Y), float.IsNormal(value.Z), float.IsNormal(value.W));
|
||||
}
|
||||
|
||||
/// <summary>Determines which components of a value are subnormal.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool4 IsSubnormal(float4 value)
|
||||
{
|
||||
return new bool4(float.IsSubnormal(value.X), float.IsSubnormal(value.Y), float.IsSubnormal(value.Z), float.IsSubnormal(value.W));
|
||||
}
|
||||
}
|
||||
|
||||
// ISignedNumber
|
||||
public partial struct float4 : ISignedNumber<float4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static float4 NegativeOne => new(-1);
|
||||
}
|
||||
210
Brutal.Numerics/Vector/float4/float4.pack.gen.cs
Normal file
210
Brutal.Numerics/Vector/float4/float4.pack.gen.cs
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
// <auto-generated /> - edit Vector.pack.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct float4
|
||||
{
|
||||
public static float4 Unpack(in sbyte4 vector, Func<sbyte, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in byte4 vector, Func<byte, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in short4 vector, Func<short, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in ushort4 vector, Func<ushort, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in int4 vector, Func<int, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in uint4 vector, Func<uint, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Pack(in double4 vector, Func<double, float> elementConverter)
|
||||
{
|
||||
VectorPack.Pack(vector, out float4 result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float4 Unpack(in sbyte4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.SByte.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Unpack(in byte4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.Byte.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Unpack(in short4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.Short.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Unpack(in ushort4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.UShort.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Unpack(in int4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.Int.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Unpack(in uint4 vector, Unpack.Float mode = Numerics.Unpack.Float.Cast)
|
||||
{
|
||||
return Unpack(vector, PackUtils.UInt.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static float4 Pack(in double4 vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
|
||||
{
|
||||
return Pack(vector, PackUtils.Double.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<sbyte4> source,
|
||||
Span<float4> destination,
|
||||
Func<sbyte, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<byte4> source,
|
||||
Span<float4> destination,
|
||||
Func<byte, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<short4> source,
|
||||
Span<float4> destination,
|
||||
Func<short, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<ushort4> source,
|
||||
Span<float4> destination,
|
||||
Func<ushort, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<int4> source,
|
||||
Span<float4> destination,
|
||||
Func<int, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<uint4> source,
|
||||
Span<float4> destination,
|
||||
Func<uint, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void PackSpan(
|
||||
in ReadOnlySpan<double4> source,
|
||||
Span<float4> destination,
|
||||
Func<double, float> elementConverter
|
||||
)
|
||||
{
|
||||
VectorPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<sbyte4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.SByte.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<byte4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.Byte.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<short4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.Short.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<ushort4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.UShort.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<int4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.Int.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void UnpackSpan(
|
||||
in ReadOnlySpan<uint4> source,
|
||||
Span<float4> destination,
|
||||
Unpack.Float mode = Numerics.Unpack.Float.Cast
|
||||
)
|
||||
{
|
||||
UnpackSpan(source, destination, PackUtils.UInt.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void PackSpan(
|
||||
in ReadOnlySpan<double4> source,
|
||||
Span<float4> destination,
|
||||
Pack.Float mode = Numerics.Pack.Float.Truncate
|
||||
)
|
||||
{
|
||||
PackSpan(source, destination, PackUtils.Double.ToFloat(mode));
|
||||
}
|
||||
}
|
||||
1963
Brutal.Numerics/Vector/float4/float4.swizzle.gen.cs
Normal file
1963
Brutal.Numerics/Vector/float4/float4.swizzle.gen.cs
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue