// - edit Vector.tt to modify #nullable enable namespace Brutal.Numerics; /// /// Implements a 4D vector with sbyte components. /// [DebuggerTypeProxy(typeof(VectorDebugView4))] public partial struct sbyte4 : IVector4 , ISignedIntegerVector { /// public static int ComponentSize => sizeof(sbyte); /// Gets the number of components. public static int ComponentCount => 4; /// [XmlAttribute] public sbyte X; /// [XmlAttribute] public sbyte Y; /// [XmlAttribute] public sbyte Z; /// [XmlAttribute] public sbyte W; sbyte IVector4.X { readonly get => X; set => X = value; } sbyte IVector4.Y { readonly get => Y; set => Y = value; } sbyte IVector4.Z { readonly get => Z; set => Z = value; } sbyte IVector4.W { readonly get => W; set => W = value; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(sbyte x, sbyte y, sbyte z, sbyte w) { X = x; Y = y; Z = z; W = w; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(sbyte xyzw) : this(xyzw, xyzw, xyzw, xyzw) { } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(sbyte3 xyz, sbyte w) : this(xyz.X, xyz.Y, xyz.Z, w) { } /// /// Creates a new instance of from two instances. /// /// The first two components. /// The last two components. [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(sbyte2 xy, sbyte2 zw) : this(xy.X, xy.Y, zw.X, zw.Y) { } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(sbyte2 xy, sbyte z, sbyte w) : this(xy.X, xy.Y, z, w) { } /// Creates a vector from the leading 4 elements of a span. /// The elements to read; must contain at least 4, and any beyond that are ignored. /// holds fewer than 4 elements. [MethodImpl(MethodImplOptions.AggressiveInlining)] public sbyte4(ReadOnlySpan span) { if (span.Length < 4) throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 4."); this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(span))); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] static sbyte4 IComponentTuple.Create(ReadOnlySpan span) => new(span); /// public static sbyte4 UnitX => new(1, 0, 0, 0); /// public static sbyte4 UnitY => new(0, 1, 0, 0); /// public static sbyte4 UnitZ => new(0, 0, 1, 0); /// public static sbyte4 UnitW => new(0, 0, 0, 1); /// public sbyte 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 sbyte x, out sbyte y, out sbyte z, out sbyte w) { x = X; y = Y; z = Z; w = W; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan() { return MemoryMarshal.CreateSpan(ref Unsafe.As(ref this), 4); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ReadOnlySpan AsReadOnlySpan() { return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As(ref Unsafe.AsRef(in this)), 4); } }