using System.Diagnostics; using System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp { /// /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] [StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 2)] public partial struct Int2 { /// /// Gets an value with all components set to 0. /// public static Int2 Zero => 0; /// /// Gets an value with all components set to 1. /// public static Int2 One => 1; /// /// Gets an value with the component set to 1, and the others to 0. /// public static Int2 UnitX => new(1, 0); /// /// Gets an value with the component set to 1, and the others to 0. /// public static Int2 UnitY => new(0, 1); /// /// Creates a new instance with the specified parameters. /// /// The value to assign to the first vector component. /// The value to assign to the second vector component. public Int2(int x, int y) { X = x; Y = y; } /// /// Gets or sets the value of the first vector component. /// public int X { get; set; } /// /// Gets or sets the value of the second vector component. /// public int Y { get; set; } /// /// Gets or sets the value of the first color component. /// public int R { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}"); } /// /// Gets or sets the value of the second color component. /// public int G { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}"); } /// /// Creates a new value with the same value for all its components. /// /// The value to use for the components of the new instance. public static implicit operator Int2(int x) => new(x, x); /// /// Casts a value to a one. /// /// The input value to cast. public static explicit operator UInt2(Int2 xy) => throw new InvalidExecutionContextException($"{nameof(Int2)}.({nameof(UInt2)})"); /// /// Casts a value to a one. /// /// The input value to cast. public static implicit operator Float2(Int2 xy) => throw new InvalidExecutionContextException($"{nameof(Int2)}.({nameof(Float2)})"); /// /// Casts a value to a one. /// /// The input value to cast. public static implicit operator Double2(Int2 xy) => throw new InvalidExecutionContextException($"{nameof(Int2)}.({nameof(Double2)})"); } }