// - edit Vector.tt to modify #nullable enable namespace Brutal.Numerics; /// /// Implements a 3D vector with bool components. /// public partial struct bool3 : IVector3 , IBooleanVector { /// public static int ComponentSize => sizeof(bool); /// Gets the number of components. public static int ComponentCount => 3; /// [XmlAttribute] public bool X; /// [XmlAttribute] public bool Y; /// [XmlAttribute] public bool Z; bool IVector3.X { readonly get => X; set => X = value; } bool IVector3.Y { readonly get => Y; set => Y = value; } bool IVector3.Z { readonly get => Z; set => Z = value; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool3(bool x, bool y, bool z) { X = x; Y = y; Z = z; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool3(bool xyz) : this(xyz, xyz, xyz) { } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool3(bool2 xy, bool z) : this(xy.X, xy.Y, z) { } /// Creates a vector from the leading 3 elements of a span. /// The elements to read; must contain at least 3, and any beyond that are ignored. /// holds fewer than 3 elements. [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool3(ReadOnlySpan span) { if (span.Length < 3) throw new ArgumentOutOfRangeException(nameof(span), "Length must be at least 3."); this = Unsafe.ReadUnaligned(ref Unsafe.As(ref MemoryMarshal.GetReference(span))); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] static bool3 IComponentTuple.Create(ReadOnlySpan span) => new(span); /// public static bool3 UnitX => new(true, false, false); /// public static bool3 UnitY => new(false, true, false); /// public static bool3 UnitZ => new(false, false, true); /// public bool 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 bool x, out bool y, out bool z) { x = X; y = Y; z = Z; } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan() { return MemoryMarshal.CreateSpan(ref Unsafe.As(ref this), 3); } /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly ReadOnlySpan AsReadOnlySpan() { return MemoryMarshal.CreateReadOnlySpan(in Unsafe.As(ref Unsafe.AsRef(in this)), 3); } }