mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
389 lines
14 KiB
C#
389 lines
14 KiB
C#
// <auto-generated /> - edit Vector.numerics.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
// INumberBase
|
|
public partial struct byte4 : INumberBase<byte4>
|
|
{
|
|
/// <inheritdoc />
|
|
public static byte4 Zero => new(0);
|
|
|
|
/// <inheritdoc />
|
|
public static byte4 One => new(1);
|
|
|
|
static byte4 IAdditiveIdentity<byte4, byte4>.AdditiveIdentity => Zero;
|
|
|
|
static byte4 IMultiplicativeIdentity<byte4, byte4>.MultiplicativeIdentity => One;
|
|
|
|
static int INumberBase<byte4>.Radix => 2; // every component type is binary
|
|
|
|
static byte4 INumberBase<byte4>.Abs(byte4 value) => value;
|
|
|
|
static bool INumberBase<byte4>.IsCanonical(byte4 value) => true;
|
|
|
|
static bool INumberBase<byte4>.IsComplexNumber(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsImaginaryNumber(byte4 value) => false;
|
|
|
|
/// <summary>Determines if every component of a value is zero.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<byte4>.IsZero(byte4 value)
|
|
{
|
|
return value == Zero;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is an even integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<byte4>.IsEvenInteger(byte4 value)
|
|
{
|
|
return (value.X & 1) == 0 && (value.Y & 1) == 0 && (value.Z & 1) == 0 && (value.W & 1) == 0;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is an odd integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<byte4>.IsOddInteger(byte4 value)
|
|
{
|
|
return (value.X & 1) == 1 && (value.Y & 1) == 1 && (value.Z & 1) == 1 && (value.W & 1) == 1;
|
|
}
|
|
|
|
static bool INumberBase<byte4>.IsNegative(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsPositive(byte4 value) => true;
|
|
|
|
static bool INumberBase<byte4>.IsFinite(byte4 value) => true;
|
|
|
|
static bool INumberBase<byte4>.IsInfinity(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsNegativeInfinity(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsPositiveInfinity(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsInteger(byte4 value) => true;
|
|
|
|
static bool INumberBase<byte4>.IsRealNumber(byte4 value) => true;
|
|
|
|
static bool INumberBase<byte4>.IsNaN(byte4 value) => false;
|
|
|
|
static bool INumberBase<byte4>.IsNormal(byte4 value) => value.X != 0 && value.Y != 0 && value.Z != 0 && value.W != 0;
|
|
|
|
static bool INumberBase<byte4>.IsSubnormal(byte4 value) => false;
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 MaxMagnitude(byte4 a, byte4 b)
|
|
{
|
|
return Max(a, b);
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 MaxMagnitudeNumber(byte4 a, byte4 b)
|
|
{
|
|
return Max(a, b);
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 MinMagnitude(byte4 a, byte4 b)
|
|
{
|
|
return Min(a, b);
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 MinMagnitudeNumber(byte4 a, byte4 b)
|
|
{
|
|
return Min(a, b);
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Add" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Add(byte4 a, byte4 b)
|
|
{
|
|
return a + b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Divide(Vector4, Vector4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Divide(byte4 a, byte4 b)
|
|
{
|
|
return a / b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Multiply(Vector4, Vector4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Multiply(byte4 a, byte4 b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Negate" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Negate(byte4 value)
|
|
{
|
|
return -value;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Subtract" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Subtract(byte4 a, byte4 b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator +(byte4 a, byte4 b)
|
|
{
|
|
return new((byte)(a.X + b.X), (byte)(a.Y + b.Y), (byte)(a.Z + b.Z), (byte)(a.W + b.W));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator -(byte4 a, byte4 b)
|
|
{
|
|
return new((byte)(a.X - b.X), (byte)(a.Y - b.Y), (byte)(a.Z - b.Z), (byte)(a.W - b.W));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator *(byte4 a, byte4 b)
|
|
{
|
|
return new((byte)(a.X * b.X), (byte)(a.Y * b.Y), (byte)(a.Z * b.Z), (byte)(a.W * b.W));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator /(byte4 a, byte4 b)
|
|
{
|
|
return new((byte)(a.X / b.X), (byte)(a.Y / b.Y), (byte)(a.Z / b.Z), (byte)(a.W / b.W));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator -(byte4 a)
|
|
{
|
|
return new((byte)(0 - a.X), (byte)(0 - a.Y), (byte)(0 - a.Z), (byte)(0 - a.W));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator +(byte4 a)
|
|
{
|
|
return a;
|
|
}
|
|
|
|
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
|
|
|
|
static byte4 IIncrementOperators<byte4>.operator ++(byte4 value) => value + One;
|
|
|
|
static byte4 IDecrementOperators<byte4>.operator --(byte4 value) => value - One;
|
|
|
|
|
|
static bool INumberBase<byte4>.TryConvertFromChecked<TOther>(TOther value, out byte4 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<byte4, byte, TOther, NumberConversion.Checked>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<byte4>.TryConvertToChecked<TOther>(byte4 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
|
|
static bool INumberBase<byte4>.TryConvertFromSaturating<TOther>(TOther value, out byte4 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<byte4, byte, TOther, NumberConversion.Saturating>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<byte4>.TryConvertToSaturating<TOther>(byte4 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
|
|
static bool INumberBase<byte4>.TryConvertFromTruncating<TOther>(TOther value, out byte4 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<byte4, byte, TOther, NumberConversion.Truncating>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<byte4>.TryConvertToTruncating<TOther>(byte4 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
|
|
public partial struct byte4
|
|
: IMultiplyOperators<byte4, byte, byte4>
|
|
, IDivisionOperators<byte4, byte, byte4>
|
|
{
|
|
/// <inheritdoc cref="Vector4.Divide(Vector4, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Divide(byte4 a, byte b)
|
|
{
|
|
return a / b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Multiply(Vector4, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Multiply(byte4 a, byte b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Multiply(float, Vector4)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Multiply(byte a, byte4 b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator *(byte4 a, byte b)
|
|
{
|
|
return new((byte)(a.X * b), (byte)(a.Y * b), (byte)(a.Z * b), (byte)(a.W * b));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator /(byte4 a, byte b)
|
|
{
|
|
return new((byte)(a.X / b), (byte)(a.Y / b), (byte)(a.Z / b), (byte)(a.W / b));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator *(byte a, byte4 b)
|
|
{
|
|
return new((byte)(a * b.X), (byte)(a * b.Y), (byte)(a * b.Z), (byte)(a * b.W));
|
|
}
|
|
}
|
|
|
|
// INumber
|
|
public partial struct byte4 : INumber<byte4>
|
|
{
|
|
/// <inheritdoc cref="Vector4.Clamp" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Clamp(byte4 value, byte4 min, byte4 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 byte4 Max(byte4 a, byte4 b)
|
|
{
|
|
return new(byte.Max(a.X, b.X), byte.Max(a.Y, b.Y), byte.Max(a.Z, b.Z), byte.Max(a.W, b.W));
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector4.Min" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 Min(byte4 a, byte4 b)
|
|
{
|
|
return new(byte.Min(a.X, b.X), byte.Min(a.Y, b.Y), byte.Min(a.Z, b.Z), byte.Min(a.W, b.W));
|
|
}
|
|
|
|
static byte4 INumber<byte4>.MaxNumber(byte4 a, byte4 b) => Max(a, b);
|
|
|
|
static byte4 INumber<byte4>.MinNumber(byte4 a, byte4 b) => Min(a, b);
|
|
|
|
static byte4 INumber<byte4>.CopySign(byte4 value, byte4 sign) => value;
|
|
|
|
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
|
|
static byte4 INumber<byte4>.ClampNative(byte4 value, byte4 min, byte4 max) => Clamp(value, min, max);
|
|
|
|
static byte4 INumber<byte4>.MaxNative(byte4 a, byte4 b) => Max(a, b);
|
|
|
|
static byte4 INumber<byte4>.MinNative(byte4 a, byte4 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<byte4>.Sign(byte4 value) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no scalar sign.");
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static byte4 operator %(byte4 a, byte4 b)
|
|
{
|
|
return new byte4((byte)(a.X % b.X), (byte)(a.Y % b.Y), (byte)(a.Z % b.Z), (byte)(a.W % b.W));
|
|
}
|
|
|
|
int IComparable.CompareTo(object? obj) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
|
|
int IComparable<byte4>.CompareTo(byte4 other) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
|
|
static bool IComparisonOperators<byte4, byte4, bool>.operator <(byte4 a, byte4 b) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
|
|
static bool IComparisonOperators<byte4, byte4, bool>.operator <=(byte4 a, byte4 b) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
|
|
static bool IComparisonOperators<byte4, byte4, bool>.operator >(byte4 a, byte4 b) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
|
|
static bool IComparisonOperators<byte4, byte4, bool>.operator >=(byte4 a, byte4 b) =>
|
|
throw new NotSupportedException($"{nameof(byte4)} has no total order.");
|
|
}
|
|
|
|
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
|
|
public partial struct byte4 : IComponentwiseComparison<byte4, bool4>
|
|
{
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool4 operator <(byte4 a, byte4 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 <=(byte4 a, byte4 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 >(byte4 a, byte4 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 >=(byte4 a, byte4 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(byte4 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(byte4 value)
|
|
{
|
|
return new bool4(byte.IsEvenInteger(value.X), byte.IsEvenInteger(value.Y), byte.IsEvenInteger(value.Z), byte.IsEvenInteger(value.W));
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are an odd integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool4 IsOddInteger(byte4 value)
|
|
{
|
|
return new bool4(byte.IsOddInteger(value.X), byte.IsOddInteger(value.Y), byte.IsOddInteger(value.Z), byte.IsOddInteger(value.W));
|
|
}
|
|
}
|
|
|
|
// IUnsignedNumber - a marker, so there is nothing to implement
|
|
public partial struct byte4 : IUnsignedNumber<byte4>;
|