mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-25 20:48:24 +01:00
438 lines
15 KiB
C#
438 lines
15 KiB
C#
// <auto-generated /> - edit Vector.numerics.tt to modify
|
|
#nullable enable
|
|
|
|
namespace Brutal.Numerics;
|
|
|
|
// INumberBase
|
|
public partial struct short2 : INumberBase<short2>
|
|
{
|
|
/// <inheritdoc />
|
|
public static short2 Zero => new(0);
|
|
|
|
/// <inheritdoc />
|
|
public static short2 One => new(1);
|
|
|
|
static short2 IAdditiveIdentity<short2, short2>.AdditiveIdentity => Zero;
|
|
|
|
static short2 IMultiplicativeIdentity<short2, short2>.MultiplicativeIdentity => One;
|
|
|
|
static int INumberBase<short2>.Radix => 2; // every component type is binary
|
|
|
|
/// <inheritdoc cref="Vector2.Abs" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Abs(short2 value)
|
|
{
|
|
return new short2(WrappingAbs(value.X), WrappingAbs(value.Y));
|
|
}
|
|
|
|
/* |MinValue| is unrepresentable, so that lane keeps MinValue and Abs can return a NEGATIVE
|
|
* number. Deliberate, settled 2026-08-25: Math.Abs throws there instead, which kills a whole
|
|
* vector for one pathological lane. Everyone else wraps - HLSL, GLSL, SPIR-V SAbs, LLVM's
|
|
* llvm.abs on its non-poison branch, and .NET's own Vector128.Abs, whose Scalar<T>.Abs even
|
|
* carries the comment "avoid Math.Abs for integers since it throws for MinValue".
|
|
* unchecked is explicit because the wrap IS the contract here: on the narrow types the
|
|
* truncating cast is what performs it (-short.MinValue widens to 32768, which no short holds),
|
|
* so this must not depend on the project's overflow setting. */
|
|
private static short WrappingAbs(short value) =>
|
|
unchecked((short)(value < 0 ? -value : value));
|
|
|
|
static bool INumberBase<short2>.IsCanonical(short2 value) => true;
|
|
|
|
static bool INumberBase<short2>.IsComplexNumber(short2 value) => false;
|
|
|
|
static bool INumberBase<short2>.IsImaginaryNumber(short2 value) => false;
|
|
|
|
/// <summary>Determines if every component of a value is zero.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<short2>.IsZero(short2 value)
|
|
{
|
|
return value == Zero;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is an even integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<short2>.IsEvenInteger(short2 value)
|
|
{
|
|
return (value.X & 1) == 0 && (value.Y & 1) == 0;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is an odd integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<short2>.IsOddInteger(short2 value)
|
|
{
|
|
return (value.X & 1) == 1 && (value.Y & 1) == 1;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is negative.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<short2>.IsNegative(short2 value)
|
|
{
|
|
return value.X < 0 && value.Y < 0;
|
|
}
|
|
|
|
/// <summary>Determines if every component of a value is positive.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
static bool INumberBase<short2>.IsPositive(short2 value)
|
|
{
|
|
return value.X >= 0 && value.Y >= 0;
|
|
}
|
|
|
|
static bool INumberBase<short2>.IsFinite(short2 value) => true;
|
|
|
|
static bool INumberBase<short2>.IsInfinity(short2 value) => false;
|
|
|
|
static bool INumberBase<short2>.IsNegativeInfinity(short2 value) => false;
|
|
|
|
static bool INumberBase<short2>.IsPositiveInfinity(short2 value) => false;
|
|
|
|
static bool INumberBase<short2>.IsInteger(short2 value) => true;
|
|
|
|
static bool INumberBase<short2>.IsRealNumber(short2 value) => true;
|
|
|
|
static bool INumberBase<short2>.IsNaN(short2 value) => false;
|
|
|
|
static bool INumberBase<short2>.IsNormal(short2 value) => value.X != 0 && value.Y != 0;
|
|
|
|
static bool INumberBase<short2>.IsSubnormal(short2 value) => false;
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 MaxMagnitude(short2 a, short2 b)
|
|
{
|
|
return new short2(short.MaxMagnitude(a.X, b.X), short.MaxMagnitude(a.Y, b.Y));
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is greater.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 MaxMagnitudeNumber(short2 a, short2 b)
|
|
{
|
|
return new short2(short.MaxMagnitude(a.X, b.X), short.MaxMagnitude(a.Y, b.Y));
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 MinMagnitude(short2 a, short2 b)
|
|
{
|
|
return new short2(short.MinMagnitude(a.X, b.X), short.MinMagnitude(a.Y, b.Y));
|
|
}
|
|
|
|
/// <summary>Computes, componentwise, the value whose magnitude is smaller.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 MinMagnitudeNumber(short2 a, short2 b)
|
|
{
|
|
return new short2(short.MinMagnitude(a.X, b.X), short.MinMagnitude(a.Y, b.Y));
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Add" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Add(short2 a, short2 b)
|
|
{
|
|
return a + b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Divide(Vector2, Vector2)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Divide(short2 a, short2 b)
|
|
{
|
|
return a / b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Multiply(Vector2, Vector2)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Multiply(short2 a, short2 b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Negate" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Negate(short2 value)
|
|
{
|
|
return -value;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Subtract" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Subtract(short2 a, short2 b)
|
|
{
|
|
return a - b;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator +(short2 a, short2 b)
|
|
{
|
|
return new((short)(a.X + b.X), (short)(a.Y + b.Y));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator -(short2 a, short2 b)
|
|
{
|
|
return new((short)(a.X - b.X), (short)(a.Y - b.Y));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator *(short2 a, short2 b)
|
|
{
|
|
return new((short)(a.X * b.X), (short)(a.Y * b.Y));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator /(short2 a, short2 b)
|
|
{
|
|
return new((short)(a.X / b.X), (short)(a.Y / b.Y));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator -(short2 a)
|
|
{
|
|
return new((short)(-a.X), (short)(-a.Y));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator +(short2 a)
|
|
{
|
|
return a;
|
|
}
|
|
|
|
// ++/-- are well-defined (+/- One) but a footgun on a concrete vector: generic-plane only.
|
|
|
|
static short2 IIncrementOperators<short2>.operator ++(short2 value) => value + One;
|
|
|
|
static short2 IDecrementOperators<short2>.operator --(short2 value) => value - One;
|
|
|
|
|
|
static bool INumberBase<short2>.TryConvertFromChecked<TOther>(TOther value, out short2 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<short2, short, TOther, NumberConversion.Checked>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<short2>.TryConvertToChecked<TOther>(short2 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
|
|
static bool INumberBase<short2>.TryConvertFromSaturating<TOther>(TOther value, out short2 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<short2, short, TOther, NumberConversion.Saturating>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<short2>.TryConvertToSaturating<TOther>(short2 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
|
|
static bool INumberBase<short2>.TryConvertFromTruncating<TOther>(TOther value, out short2 result)
|
|
{
|
|
return NumberConversion.TryConvertFrom<short2, short, TOther, NumberConversion.Truncating>(value, out result);
|
|
}
|
|
|
|
static bool INumberBase<short2>.TryConvertToTruncating<TOther>(short2 value, [MaybeNullWhen(false)] out TOther result)
|
|
{
|
|
result = default;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// IMultiplyOperators<TSelf, TComponent, TSelf>, IDivisionOperators<TSelf, TComponent, TSelf>
|
|
public partial struct short2
|
|
: IMultiplyOperators<short2, short, short2>
|
|
, IDivisionOperators<short2, short, short2>
|
|
{
|
|
/// <inheritdoc cref="Vector2.Divide(Vector2, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Divide(short2 a, short b)
|
|
{
|
|
return a / b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Multiply(Vector2, float)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Multiply(short2 a, short b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Multiply(float, Vector2)" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Multiply(short a, short2 b)
|
|
{
|
|
return a * b;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator *(short2 a, short b)
|
|
{
|
|
return new((short)(a.X * b), (short)(a.Y * b));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator /(short2 a, short b)
|
|
{
|
|
return new((short)(a.X / b), (short)(a.Y / b));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator *(short a, short2 b)
|
|
{
|
|
return new((short)(a * b.X), (short)(a * b.Y));
|
|
}
|
|
}
|
|
|
|
// INumber
|
|
public partial struct short2 : INumber<short2>
|
|
{
|
|
/// <inheritdoc cref="Vector2.Clamp" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Clamp(short2 value, short2 min, short2 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="Vector2.Max" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Max(short2 a, short2 b)
|
|
{
|
|
return new(short.Max(a.X, b.X), short.Max(a.Y, b.Y));
|
|
}
|
|
|
|
/// <inheritdoc cref="Vector2.Min" />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 Min(short2 a, short2 b)
|
|
{
|
|
return new(short.Min(a.X, b.X), short.Min(a.Y, b.Y));
|
|
}
|
|
|
|
static short2 INumber<short2>.MaxNumber(short2 a, short2 b) => Max(a, b);
|
|
|
|
static short2 INumber<short2>.MinNumber(short2 a, short2 b) => Min(a, b);
|
|
|
|
/// <summary>Copies, componentwise, the sign of <paramref name="sign" /> onto the magnitude of <paramref name="value" />.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 CopySign(short2 value, short2 sign)
|
|
{
|
|
return new short2(short.CopySign(value.X, sign.X), short.CopySign(value.Y, sign.Y));
|
|
}
|
|
|
|
// the Native variants permit either NaN/signed-zero behavior - forwarding is always legal
|
|
static short2 INumber<short2>.ClampNative(short2 value, short2 min, short2 max) => Clamp(value, min, max);
|
|
|
|
static short2 INumber<short2>.MaxNative(short2 a, short2 b) => Max(a, b);
|
|
|
|
static short2 INumber<short2>.MinNative(short2 a, short2 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<short2>.Sign(short2 value) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no scalar sign.");
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static short2 operator %(short2 a, short2 b)
|
|
{
|
|
return new short2((short)(a.X % b.X), (short)(a.Y % b.Y));
|
|
}
|
|
|
|
int IComparable.CompareTo(object? obj) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
|
|
int IComparable<short2>.CompareTo(short2 other) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
|
|
static bool IComparisonOperators<short2, short2, bool>.operator <(short2 a, short2 b) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
|
|
static bool IComparisonOperators<short2, short2, bool>.operator <=(short2 a, short2 b) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
|
|
static bool IComparisonOperators<short2, short2, bool>.operator >(short2 a, short2 b) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
|
|
static bool IComparisonOperators<short2, short2, bool>.operator >=(short2 a, short2 b) =>
|
|
throw new NotSupportedException($"{nameof(short2)} has no total order.");
|
|
}
|
|
|
|
// IComponentwiseComparison + the componentwise predicate masks (no interface to mirror)
|
|
public partial struct short2 : IComponentwiseComparison<short2, bool2>
|
|
{
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 operator <(short2 a, short2 b)
|
|
{
|
|
return new bool2(a.X < b.X, a.Y < b.Y);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 operator <=(short2 a, short2 b)
|
|
{
|
|
return new bool2(a.X <= b.X, a.Y <= b.Y);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 operator >(short2 a, short2 b)
|
|
{
|
|
return new bool2(a.X > b.X, a.Y > b.Y);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 operator >=(short2 a, short2 b)
|
|
{
|
|
return new bool2(a.X >= b.X, a.Y >= b.Y);
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are zero.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 IsZero(short2 value)
|
|
{
|
|
return new bool2(value.X == 0, value.Y == 0);
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are an even integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 IsEvenInteger(short2 value)
|
|
{
|
|
return new bool2(short.IsEvenInteger(value.X), short.IsEvenInteger(value.Y));
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are an odd integral value.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 IsOddInteger(short2 value)
|
|
{
|
|
return new bool2(short.IsOddInteger(value.X), short.IsOddInteger(value.Y));
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are negative.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 IsNegative(short2 value)
|
|
{
|
|
return new bool2(short.IsNegative(value.X), short.IsNegative(value.Y));
|
|
}
|
|
|
|
/// <summary>Determines which components of a value are positive.</summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static bool2 IsPositive(short2 value)
|
|
{
|
|
return new bool2(short.IsPositive(value.X), short.IsPositive(value.Y));
|
|
}
|
|
}
|
|
|
|
// ISignedNumber
|
|
public partial struct short2 : ISignedNumber<short2>
|
|
{
|
|
/// <inheritdoc />
|
|
public static short2 NegativeOne => new(-1);
|
|
}
|