mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-27 21:48:25 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
8 changed files with 768360 additions and 0 deletions
|
|
@ -0,0 +1,28 @@
|
|||
// <auto-generated /> - edit Vector.copy.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// <auto-generated /> - edit Vector.equality.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public readonly override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(X, Y, Z, W);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool Equals(floatQuat 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 floatQuat other && Equals(other);
|
||||
}
|
||||
|
||||
/// <summary>IEEE lane-wise equality over every component: any NaN component makes this false (contrast <see cref="Equals(floatQuat)" />, which is NaN-reflexive), and -0 equals +0.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(floatQuat a, floatQuat 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 !=(floatQuat a, floatQuat b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
// <auto-generated /> - edit Vector.format.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat : ISpanFormattable, IUtf8SpanFormattable, ISpanParsable<floatQuat>
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
var separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator;
|
||||
// the handler takes a string format (an IFormattable legacy) - null on the default path stays alloc-free
|
||||
var formatString = format.IsEmpty ? null : format.ToString();
|
||||
var handler = new MemoryExtensions.TryWriteInterpolatedStringHandler(5, 7, destination, provider, out var shouldAppend);
|
||||
_ = shouldAppend
|
||||
&& handler.AppendLiteral("<")
|
||||
&& handler.AppendFormatted(X, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(Y, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(Z, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(W, formatString)
|
||||
&& handler.AppendLiteral(">");
|
||||
return destination.TryWrite(ref handler, out charsWritten);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public readonly bool TryFormat(Span<byte> destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
|
||||
{
|
||||
var separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator;
|
||||
// the handler takes a string format (an IFormattable legacy) - null on the default path stays alloc-free
|
||||
var formatString = format.IsEmpty ? null : format.ToString();
|
||||
var handler = new Utf8.TryWriteInterpolatedStringHandler(5, 7, destination, provider, out var shouldAppend);
|
||||
_ = shouldAppend
|
||||
&& handler.AppendLiteral("<")
|
||||
&& handler.AppendFormatted(X, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(Y, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(Z, formatString)
|
||||
&& handler.AppendFormatted(separator) && handler.AppendLiteral(" ")
|
||||
&& handler.AppendFormatted(W, formatString)
|
||||
&& handler.AppendLiteral(">");
|
||||
return Utf8.TryWrite(destination, ref handler, out bytesWritten);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static floatQuat Parse(string s, IFormatProvider? provider)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(s);
|
||||
return Parse(s.AsSpan(), NumberStyles.Float, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static floatQuat Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
|
||||
{
|
||||
return Parse(s, NumberStyles.Float, provider);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Parse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?)" />
|
||||
public static floatQuat 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 floatQuat 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 floatQuat format.");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out floatQuat)" />
|
||||
public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, out floatQuat result)
|
||||
{
|
||||
return TryParse(s.AsSpan(), NumberStyles.Float, provider, out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out floatQuat)" />
|
||||
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out floatQuat result)
|
||||
{
|
||||
return TryParse(s, NumberStyles.Float, provider, out result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryParse(ReadOnlySpan{char}, NumberStyles, IFormatProvider?, out floatQuat)" />
|
||||
public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out floatQuat 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 floatQuat.</returns>
|
||||
public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider? provider, out floatQuat result)
|
||||
{
|
||||
result = default;
|
||||
s = s.Trim();
|
||||
if (s.Length < 2 || s[0] != '<' || s[^1] != '>')
|
||||
return false;
|
||||
s = s[1..^1];
|
||||
var separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator;
|
||||
var separatorIndex = s.IndexOf(separator);
|
||||
// trimmed: TryFormat writes "separator + space", which must not demand AllowLeadingWhite
|
||||
if (separatorIndex < 0 || !float.TryParse(s[..separatorIndex].Trim(), style, provider, out var x))
|
||||
return false;
|
||||
s = s[(separatorIndex + separator.Length)..];
|
||||
separatorIndex = s.IndexOf(separator);
|
||||
// trimmed: TryFormat writes "separator + space", which must not demand AllowLeadingWhite
|
||||
if (separatorIndex < 0 || !float.TryParse(s[..separatorIndex].Trim(), style, provider, out var y))
|
||||
return false;
|
||||
s = s[(separatorIndex + separator.Length)..];
|
||||
separatorIndex = s.IndexOf(separator);
|
||||
// trimmed: TryFormat writes "separator + space", which must not demand AllowLeadingWhite
|
||||
if (separatorIndex < 0 || !float.TryParse(s[..separatorIndex].Trim(), style, provider, out var z))
|
||||
return false;
|
||||
s = s[(separatorIndex + separator.Length)..];
|
||||
if (!float.TryParse(s.Trim(), style, provider, out var w))
|
||||
return false;
|
||||
result = new(x, y, z, w);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
// <auto-generated /> - edit Vector.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
/// <summary>
|
||||
/// Implements a quaternion with float components.
|
||||
/// </summary>
|
||||
[DebuggerTypeProxy(typeof(QuaternionDebugView<floatQuat, float>))]
|
||||
public partial struct floatQuat : IQuaternion<floatQuat, float>
|
||||
, IMultiplyOperators<floatQuat, float2, float2>
|
||||
, IMultiplyOperators<floatQuat, float3, float3>
|
||||
, IMultiplyOperators<floatQuat, float4, float4>
|
||||
, IQuaternionFactories<floatQuat, float, float3, float4x4>
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public static int ComponentSize => sizeof(float);
|
||||
|
||||
/// <summary>Gets the number of components.</summary>
|
||||
public static int ComponentCount => 4;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.X" />
|
||||
[XmlAttribute]
|
||||
public float X;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Y" />
|
||||
[XmlAttribute]
|
||||
public float Y;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Z" />
|
||||
[XmlAttribute]
|
||||
public float Z;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.W" />
|
||||
[XmlAttribute]
|
||||
public float W;
|
||||
|
||||
/// <inheritdoc cref="Quaternion(float, float, float, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public floatQuat(float x, float y, float z, float w)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion(Vector3, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public floatQuat(float3 vectorPart, float scalarPart)
|
||||
{
|
||||
X = vectorPart.X;
|
||||
Y = vectorPart.Y;
|
||||
Z = vectorPart.Z;
|
||||
W = scalarPart;
|
||||
}
|
||||
|
||||
/// <summary>Creates a quaternion 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 floatQuat(ReadOnlySpan<float> span)
|
||||
{
|
||||
if (span.Length < 4)
|
||||
throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4.");
|
||||
|
||||
this = Unsafe.ReadUnaligned<floatQuat>(ref Unsafe.As<float, byte>(ref MemoryMarshal.GetReference(span)));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="floatQuat(ReadOnlySpan{float})" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
static floatQuat IComponentTuple<floatQuat, float>.Create(ReadOnlySpan<float> span) => new(span);
|
||||
|
||||
/// <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<floatQuat, float>(ref this), 4);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly ReadOnlySpan<float> AsReadOnlySpan()
|
||||
{
|
||||
return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As<floatQuat, float>(ref Unsafe.AsRef(in this)), 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
// <auto-generated /> - edit Vector.math-metric.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat
|
||||
{
|
||||
/// <inheritdoc cref="Quaternion.Length" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly float Length()
|
||||
{
|
||||
return float.Sqrt(LengthSquared());
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.LengthSquared" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly float LengthSquared()
|
||||
{
|
||||
return Dot(this, this);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Dot" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Dot(floatQuat a, floatQuat b)
|
||||
{
|
||||
return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Normalize" />
|
||||
/// <exception cref="DivideByZeroException">Thrown when the input quaternion is a zero quaternion.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Normalize(floatQuat value)
|
||||
{
|
||||
var lengthSquared = Dot(value, value);
|
||||
if (lengthSquared == 0)
|
||||
throw new DivideByZeroException();
|
||||
return value / float.Sqrt(lengthSquared);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Normalize" />
|
||||
/// <remarks>Returns zero if the input quaternion is zero.</remarks>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat NormalizeOrZero(floatQuat value)
|
||||
{
|
||||
var length = float.Sqrt(Dot(value, value));
|
||||
return length == 0 ? Zero : value / length;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
// <auto-generated /> - edit Quat.math.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat
|
||||
{
|
||||
/// <inheritdoc cref="Quaternion.IsIdentity" />
|
||||
public readonly bool IsIdentity => this == Identity;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Concatenate(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Concatenate(floatQuat a, floatQuat b)
|
||||
{
|
||||
return b * a;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Conjugate(Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Conjugate(floatQuat value)
|
||||
{
|
||||
// -x, -y, -z, w
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(Unsafe.BitCast<floatQuat, Vector128<float>>(value) ^ Vector128.Create(-0.0f, -0.0f, -0.0f, 0.0f));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.CreateFromAxisAngle(Vector3, float)" />
|
||||
public static floatQuat CreateFromAxisAngle(float3 axis, float angle)
|
||||
{
|
||||
floatQuat ans;
|
||||
|
||||
var halfAngle = angle * 0.5f;
|
||||
var (s, c) = float.SinCos(halfAngle);
|
||||
|
||||
ans.X = axis.X * s;
|
||||
ans.Y = axis.Y * s;
|
||||
ans.Z = axis.Z * s;
|
||||
ans.W = c;
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.CreateFromRotationMatrix(Matrix4x4)" />
|
||||
public static floatQuat CreateFromRotationMatrix(float4x4 matrix)
|
||||
{
|
||||
var trace = matrix.M11 + matrix.M22 + matrix.M33;
|
||||
|
||||
floatQuat q = default;
|
||||
|
||||
if (trace > 0.0)
|
||||
{
|
||||
var s = float.Sqrt(trace + 1);
|
||||
q.W = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
q.X = (matrix.M23 - matrix.M32) * s;
|
||||
q.Y = (matrix.M31 - matrix.M13) * s;
|
||||
q.Z = (matrix.M12 - matrix.M21) * s;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (matrix.M11 >= matrix.M22 && matrix.M11 >= matrix.M33)
|
||||
{
|
||||
var s = float.Sqrt(1 + matrix.M11 - matrix.M22 - matrix.M33);
|
||||
var invS = 0.5f / s;
|
||||
q.X = 0.5f * s;
|
||||
q.Y = (matrix.M12 + matrix.M21) * invS;
|
||||
q.Z = (matrix.M13 + matrix.M31) * invS;
|
||||
q.W = (matrix.M23 - matrix.M32) * invS;
|
||||
}
|
||||
else if (matrix.M22 > matrix.M33)
|
||||
{
|
||||
var s = float.Sqrt(1 + matrix.M22 - matrix.M11 - matrix.M33);
|
||||
var invS = 0.5f / s;
|
||||
q.X = (matrix.M21 + matrix.M12) * invS;
|
||||
q.Y = 0.5f * s;
|
||||
q.Z = (matrix.M32 + matrix.M23) * invS;
|
||||
q.W = (matrix.M31 - matrix.M13) * invS;
|
||||
}
|
||||
else
|
||||
{
|
||||
var s = float.Sqrt(1 + matrix.M33 - matrix.M11 - matrix.M22);
|
||||
var invS = 0.5f / s;
|
||||
q.X = (matrix.M31 + matrix.M13) * invS;
|
||||
q.Y = (matrix.M32 + matrix.M23) * invS;
|
||||
q.Z = 0.5f * s;
|
||||
q.W = (matrix.M12 - matrix.M21) * invS;
|
||||
}
|
||||
}
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.CreateFromYawPitchRoll(float, float, float)" />
|
||||
public static floatQuat CreateFromYawPitchRoll(float yaw, float pitch, float roll)
|
||||
{
|
||||
// Roll first, about axis the object is facing, then
|
||||
// pitch upward, then yaw to face into the new heading
|
||||
var (sr, cr) = float.SinCos(roll * 0.5f);
|
||||
var (sp, cp) = float.SinCos(pitch * 0.5f);
|
||||
var (sy, cy) = float.SinCos(yaw * 0.5f);
|
||||
|
||||
floatQuat result;
|
||||
|
||||
result.X = cy * sp * cr + sy * cp * sr;
|
||||
result.Y = sy * cp * cr - cy * sp * sr;
|
||||
result.Z = cy * cp * sr - sy * sp * cr;
|
||||
result.W = cy * cp * cr + sy * sp * sr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Inverse(Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Inverse(floatQuat value)
|
||||
{
|
||||
// -1 ( a -v )
|
||||
// q = ( ------------- ------------- )
|
||||
// ( a^2 + |v|^2 , a^2 + |v|^2 )
|
||||
|
||||
return Conjugate(value) / value.LengthSquared();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Lerp(Quaternion, Quaternion, float)" />
|
||||
public static floatQuat Lerp(floatQuat a, floatQuat b, float amount)
|
||||
{
|
||||
var t = amount;
|
||||
var t1 = 1 - t;
|
||||
|
||||
var dot = Dot(a, b);
|
||||
|
||||
var r = dot >= 0
|
||||
? a * t1 + b * t
|
||||
: a * t1 - b * t;
|
||||
|
||||
// Normalize it.
|
||||
var invNorm = 1 / float.Sqrt(r.LengthSquared());
|
||||
return r * invNorm;
|
||||
}
|
||||
|
||||
private const float SlerpEpsilon = 1e-6f;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Slerp(Quaternion, Quaternion, float)" />
|
||||
public static floatQuat Slerp(floatQuat a, floatQuat b, float amount)
|
||||
{
|
||||
var t = amount;
|
||||
|
||||
var cosOmega = Dot(a, b);
|
||||
|
||||
var flip = false;
|
||||
|
||||
if (cosOmega < 0)
|
||||
{
|
||||
flip = true;
|
||||
cosOmega = -cosOmega;
|
||||
}
|
||||
|
||||
float s1,
|
||||
s2;
|
||||
|
||||
if (cosOmega > 1 - SlerpEpsilon)
|
||||
{
|
||||
// Too close, do straight linear interpolation.
|
||||
s1 = 1 - t;
|
||||
s2 = flip ? -t : t;
|
||||
}
|
||||
else
|
||||
{
|
||||
var omega = float.Acos(cosOmega);
|
||||
var invSinOmega = 1 / float.Sin(omega);
|
||||
|
||||
s1 = float.Sin((1 - t) * omega) * invSinOmega;
|
||||
s2 = flip ? -float.Sin(t * omega) * invSinOmega : float.Sin(t * omega) * invSinOmega;
|
||||
}
|
||||
|
||||
return a * s1 + b * s2;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float2.Transform(float2, floatQuat)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float2 operator *(floatQuat rotation, float2 vector)
|
||||
{
|
||||
return float2.Transform(vector, rotation);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float3.Transform(float3, floatQuat)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float3 operator *(floatQuat rotation, float3 vector)
|
||||
{
|
||||
return float3.Transform(vector, rotation);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="float4.Transform(float4, floatQuat)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float4 operator *(floatQuat rotation, float4 vector)
|
||||
{
|
||||
return float4.Transform(vector, rotation);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,496 @@
|
|||
// <auto-generated /> - edit Quat.numerics.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
// INumberBase
|
||||
public partial struct floatQuat : INumberBase<floatQuat>
|
||||
{
|
||||
/// <inheritdoc cref="Quaternion.Zero" />
|
||||
public static floatQuat Zero => default;
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Identity" />
|
||||
public static floatQuat Identity => new(0, 0, 0, 1);
|
||||
|
||||
/* One is the multiplicative identity - the identity quaternion - which the concrete API
|
||||
* already names Identity; a public One would read as all-ones. */
|
||||
static floatQuat INumberBase<floatQuat>.One => Identity;
|
||||
|
||||
static floatQuat IAdditiveIdentity<floatQuat, floatQuat>.AdditiveIdentity => Zero;
|
||||
|
||||
static floatQuat IMultiplicativeIdentity<floatQuat, floatQuat>.MultiplicativeIdentity => Identity;
|
||||
|
||||
static int INumberBase<floatQuat>.Radix => 2;
|
||||
|
||||
// Abs is the norm, embedded on the real axis as a scalar quaternion (cf. Complex.Abs)
|
||||
static floatQuat INumberBase<floatQuat>.Abs(floatQuat value) => new(0, 0, 0, value.Length());
|
||||
|
||||
static bool INumberBase<floatQuat>.IsCanonical(floatQuat value) => true;
|
||||
|
||||
static bool INumberBase<floatQuat>.IsComplexNumber(floatQuat value) =>
|
||||
value.W != 0 && !(value.X == 0 && value.Y == 0 && value.Z == 0);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsImaginaryNumber(floatQuat value) =>
|
||||
value.W == 0 && float.IsRealNumber(value.X) && float.IsRealNumber(value.Y) && float.IsRealNumber(value.Z);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsRealNumber(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsRealNumber(value.W);
|
||||
|
||||
/// <summary>Determines if a value is zero.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool IsZero(floatQuat value)
|
||||
{
|
||||
return value == Zero;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.IsEvenInteger(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsEvenInteger(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsOddInteger(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsOddInteger(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsInteger(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsInteger(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsNegative(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsRealNumber(value.W) && float.IsNegative(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsPositive(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsRealNumber(value.W) && float.IsPositive(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsFinite(floatQuat value) =>
|
||||
float.IsFinite(value.X) && float.IsFinite(value.Y) && float.IsFinite(value.Z) && float.IsFinite(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsInfinity(floatQuat value) =>
|
||||
float.IsInfinity(value.X) || float.IsInfinity(value.Y) || float.IsInfinity(value.Z) || float.IsInfinity(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsNegativeInfinity(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsNegativeInfinity(value.W);
|
||||
|
||||
static bool INumberBase<floatQuat>.IsPositiveInfinity(floatQuat value) =>
|
||||
value.X == 0 && value.Y == 0 && value.Z == 0 && float.IsPositiveInfinity(value.W);
|
||||
|
||||
// NaN present and no infinity - infinity dominates, per Complex
|
||||
static bool INumberBase<floatQuat>.IsNaN(floatQuat value) =>
|
||||
(float.IsNaN(value.X) || float.IsNaN(value.Y) || float.IsNaN(value.Z) || float.IsNaN(value.W))
|
||||
&& !(float.IsInfinity(value.X) || float.IsInfinity(value.Y) || float.IsInfinity(value.Z) || float.IsInfinity(value.W));
|
||||
|
||||
static bool INumberBase<floatQuat>.IsNormal(floatQuat value) =>
|
||||
float.IsNormal(value.W)
|
||||
&& (value.X == 0 && value.Y == 0 && value.Z == 0 || (float.IsNormal(value.X) && float.IsNormal(value.Y) && float.IsNormal(value.Z)));
|
||||
|
||||
static bool INumberBase<floatQuat>.IsSubnormal(floatQuat value) =>
|
||||
float.IsSubnormal(value.X) || float.IsSubnormal(value.Y) || float.IsSubnormal(value.Z) || float.IsSubnormal(value.W);
|
||||
|
||||
static floatQuat INumberBase<floatQuat>.MaxMagnitude(floatQuat a, floatQuat b)
|
||||
{
|
||||
var magnitudeA = a.LengthSquared();
|
||||
var magnitudeB = b.LengthSquared();
|
||||
if (float.IsNaN(magnitudeA))
|
||||
return a;
|
||||
if (float.IsNaN(magnitudeB))
|
||||
return b;
|
||||
return magnitudeA >= magnitudeB ? a : b;
|
||||
}
|
||||
|
||||
static floatQuat INumberBase<floatQuat>.MaxMagnitudeNumber(floatQuat a, floatQuat b)
|
||||
{
|
||||
var magnitudeA = a.LengthSquared();
|
||||
var magnitudeB = b.LengthSquared();
|
||||
if (float.IsNaN(magnitudeA))
|
||||
return b;
|
||||
if (float.IsNaN(magnitudeB))
|
||||
return a;
|
||||
return magnitudeA >= magnitudeB ? a : b;
|
||||
}
|
||||
|
||||
static floatQuat INumberBase<floatQuat>.MinMagnitude(floatQuat a, floatQuat b)
|
||||
{
|
||||
var magnitudeA = a.LengthSquared();
|
||||
var magnitudeB = b.LengthSquared();
|
||||
if (float.IsNaN(magnitudeA))
|
||||
return a;
|
||||
if (float.IsNaN(magnitudeB))
|
||||
return b;
|
||||
return magnitudeA <= magnitudeB ? a : b;
|
||||
}
|
||||
|
||||
static floatQuat INumberBase<floatQuat>.MinMagnitudeNumber(floatQuat a, floatQuat b)
|
||||
{
|
||||
var magnitudeA = a.LengthSquared();
|
||||
var magnitudeB = b.LengthSquared();
|
||||
if (float.IsNaN(magnitudeA))
|
||||
return b;
|
||||
if (float.IsNaN(magnitudeB))
|
||||
return a;
|
||||
return magnitudeA <= magnitudeB ? a : b;
|
||||
}
|
||||
|
||||
/* ++/-- add/subtract One = Identity, bumping W - exactly what Complex does. Generic-plane
|
||||
* only: a footgun on a concrete quat. */
|
||||
|
||||
static floatQuat IIncrementOperators<floatQuat>.operator ++(floatQuat value) => value + Identity;
|
||||
|
||||
static floatQuat IDecrementOperators<floatQuat>.operator --(floatQuat value) => value - Identity;
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertFromChecked<TOther>(TOther value, out floatQuat result)
|
||||
{
|
||||
if (typeof(TOther) == typeof(floatQuat))
|
||||
{
|
||||
result = (floatQuat)(object)value!;
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(doubleQuat))
|
||||
{
|
||||
var other = (doubleQuat)(object)value!;
|
||||
result = new(float.CreateChecked(other.X), float.CreateChecked(other.Y), float.CreateChecked(other.Z), float.CreateChecked(other.W));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(sbyte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((sbyte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(byte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((byte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(short))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((short)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ushort))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((ushort)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(int))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((int)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(uint))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((uint)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(long))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((long)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ulong))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((ulong)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(float))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((float)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(double))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateChecked((double)(object)value!));
|
||||
return true;
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertToChecked<TOther>(floatQuat value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertFromSaturating<TOther>(TOther value, out floatQuat result)
|
||||
{
|
||||
if (typeof(TOther) == typeof(floatQuat))
|
||||
{
|
||||
result = (floatQuat)(object)value!;
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(doubleQuat))
|
||||
{
|
||||
var other = (doubleQuat)(object)value!;
|
||||
result = new(float.CreateSaturating(other.X), float.CreateSaturating(other.Y), float.CreateSaturating(other.Z), float.CreateSaturating(other.W));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(sbyte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((sbyte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(byte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((byte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(short))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((short)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ushort))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((ushort)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(int))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((int)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(uint))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((uint)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(long))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((long)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ulong))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((ulong)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(float))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((float)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(double))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateSaturating((double)(object)value!));
|
||||
return true;
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertToSaturating<TOther>(floatQuat value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertFromTruncating<TOther>(TOther value, out floatQuat result)
|
||||
{
|
||||
if (typeof(TOther) == typeof(floatQuat))
|
||||
{
|
||||
result = (floatQuat)(object)value!;
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(doubleQuat))
|
||||
{
|
||||
var other = (doubleQuat)(object)value!;
|
||||
result = new(float.CreateTruncating(other.X), float.CreateTruncating(other.Y), float.CreateTruncating(other.Z), float.CreateTruncating(other.W));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(sbyte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((sbyte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(byte))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((byte)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(short))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((short)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ushort))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((ushort)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(int))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((int)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(uint))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((uint)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(long))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((long)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(ulong))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((ulong)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(float))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((float)(object)value!));
|
||||
return true;
|
||||
}
|
||||
if (typeof(TOther) == typeof(double))
|
||||
{
|
||||
result = new(0, 0, 0, float.CreateTruncating((double)(object)value!));
|
||||
return true;
|
||||
}
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool INumberBase<floatQuat>.TryConvertToTruncating<TOther>(floatQuat value, [MaybeNullWhen(false)] out TOther result)
|
||||
{
|
||||
result = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Addition(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Add(floatQuat a, floatQuat b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Divide(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Divide(floatQuat a, floatQuat b)
|
||||
{
|
||||
return a / b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Multiply(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Multiply(floatQuat a, floatQuat b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Negate(Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Negate(floatQuat value)
|
||||
{
|
||||
return -value;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.Subtract(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Subtract(floatQuat a, floatQuat b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Addition(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator +(floatQuat a, floatQuat b)
|
||||
{
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(Unsafe.BitCast<floatQuat, Vector128<float>>(a) + Unsafe.BitCast<floatQuat, Vector128<float>>(b));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Division(Quaternion, Quaternion)" />
|
||||
public static floatQuat operator /(floatQuat a, floatQuat b)
|
||||
{
|
||||
floatQuat ans;
|
||||
|
||||
var ax = a.X;
|
||||
var ay = a.Y;
|
||||
var az = a.Z;
|
||||
var aw = a.W;
|
||||
|
||||
//-------------------------------------
|
||||
// Inverse part.
|
||||
var ls = b.X * b.X + b.Y * b.Y + b.Z * b.Z + b.W * b.W;
|
||||
var invNorm = 1 / ls;
|
||||
|
||||
var bx = -b.X * invNorm;
|
||||
var by = -b.Y * invNorm;
|
||||
var bz = -b.Z * invNorm;
|
||||
var bw = b.W * invNorm;
|
||||
|
||||
//-------------------------------------
|
||||
// Multiply part.
|
||||
|
||||
// cross(av, bv)
|
||||
var cx = ay * bz - az * by;
|
||||
var cy = az * bx - ax * bz;
|
||||
var cz = ax * by - ay * bx;
|
||||
|
||||
var dot = ax * bx + ay * by + az * bz;
|
||||
|
||||
ans.X = ax * bw + bx * aw + cx;
|
||||
ans.Y = ay * bw + by * aw + cy;
|
||||
ans.Z = az * bw + bz * aw + cz;
|
||||
ans.W = aw * bw - dot;
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Multiply(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator *(floatQuat a, floatQuat b)
|
||||
{
|
||||
var left = Unsafe.BitCast<floatQuat, Vector128<float>>(a);
|
||||
var right = Unsafe.BitCast<floatQuat, Vector128<float>>(b);
|
||||
|
||||
var result = right * left.GetElement(3);
|
||||
result = Vector128.MultiplyAddEstimate(Vector128.ShuffleNative(right, Vector128.Create(3, 2, 1, 0)) * left.GetElement(0), Vector128.Create(+1.0f, -1.0f, +1.0f, -1.0f), result);
|
||||
result = Vector128.MultiplyAddEstimate(Vector128.ShuffleNative(right, Vector128.Create(2, 3, 0, 1)) * left.GetElement(1), Vector128.Create(+1.0f, +1.0f, -1.0f, -1.0f), result);
|
||||
result = Vector128.MultiplyAddEstimate(Vector128.ShuffleNative(right, Vector128.Create(1, 0, 3, 2)) * left.GetElement(2), Vector128.Create(-1.0f, +1.0f, +1.0f, -1.0f), result);
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(result);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Subtraction(Quaternion, Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator -(floatQuat a, floatQuat b)
|
||||
{
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(Unsafe.BitCast<floatQuat, Vector128<float>>(a) - Unsafe.BitCast<floatQuat, Vector128<float>>(b));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_UnaryNegation(Quaternion)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator -(floatQuat value)
|
||||
{
|
||||
return Zero - value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator +(floatQuat value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
|
||||
public partial struct floatQuat
|
||||
: IMultiplyOperators<floatQuat, float, floatQuat>
|
||||
, IDivisionOperators<floatQuat, float, floatQuat>
|
||||
{
|
||||
/// <inheritdoc cref="Quaternion.Multiply(Quaternion, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat Multiply(floatQuat a, float b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Quaternion.op_Multiply(Quaternion, float)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator *(floatQuat a, float b)
|
||||
{
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(Unsafe.BitCast<floatQuat, Vector128<float>>(a) * Vector128.Create(b));
|
||||
}
|
||||
|
||||
/// <summary>Divides a quaternion by a scalar, componentwise.</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static floatQuat operator /(floatQuat a, float b)
|
||||
{
|
||||
return Unsafe.BitCast<Vector128<float>, floatQuat>(Unsafe.BitCast<floatQuat, Vector128<float>>(a) / Vector128.Create(b));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// <auto-generated /> - edit Vector.pack.tt to modify
|
||||
#nullable enable
|
||||
|
||||
namespace Brutal.Numerics;
|
||||
|
||||
public partial struct floatQuat
|
||||
{
|
||||
public static floatQuat Pack(in doubleQuat vector, Func<double, float> elementConverter)
|
||||
{
|
||||
QuaternionPack.Pack(vector, out floatQuat result, elementConverter);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static floatQuat Pack(in doubleQuat vector, Pack.Float mode = Numerics.Pack.Float.Truncate)
|
||||
{
|
||||
return Pack(vector, PackUtils.Double.ToFloat(mode));
|
||||
}
|
||||
|
||||
public static void Pack(
|
||||
in ReadOnlySpan<doubleQuat> source,
|
||||
Span<floatQuat> destination,
|
||||
Func<double, float> elementConverter
|
||||
)
|
||||
{
|
||||
QuaternionPack.Pack(source, destination, elementConverter);
|
||||
}
|
||||
|
||||
public static void Pack(
|
||||
in ReadOnlySpan<doubleQuat> source,
|
||||
Span<floatQuat> destination,
|
||||
Pack.Float mode = Numerics.Pack.Float.Truncate
|
||||
)
|
||||
{
|
||||
Pack(source, destination, PackUtils.Double.ToFloat(mode));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue