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