using System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp { /// /// A that maps the int2 HLSL type /// [StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 2)] public struct Int2 { /// /// Gets an value with all components set to 0 /// public static Int2 Zero { get; } = 0; /// /// Gets an value with all components set to 1 /// public static Int2 One { get; } = 1; /// /// Gets an value with the component set to 1, and the others to 0 /// public static Int2 UnitX { get; } = new Int2(1, 0); /// /// Gets an value with the component set to 1, and the others to 0 /// public static Int2 UnitY { get; } = new Int2(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)}"); } /// /// Gets or sets a specific component in the current instance /// /// The index of the component to access public int this[int i] { get => throw new InvalidExecutionContextException($"{nameof(Int2)}[int]"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}[int]"); } /// /// Gets an value with the value for all components /// public Int2 XX => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XX)}"); /// /// Gets or sets an value with the and values /// public Int2 XY { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XY)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(XY)}"); } /// /// Gets an value with the and values /// public Int2 YX { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YX)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YX)}"); } /// /// Gets an value with the value for all components /// public Int2 YY => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(YY)}"); /// /// Gets an value with the value for all components /// public Int2 RR => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RR)}"); /// /// Gets or sets an value with the and values /// public Int2 RG { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RG)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(RG)}"); } /// /// Gets an value with the and values /// public Int2 GR { get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GR)}"); set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GR)}"); } /// /// Gets an value with the value for all components /// public Int2 GG => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(GG)}"); /// /// 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 Int2(x, x); /// /// Sums two values /// /// The first value to sum /// The second value to sum public static Int2 operator +(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.+"); /// /// Divides two values /// /// The first value to divide /// The second value to divide public static Int2 operator /(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}./"); /// /// Multiplies two values /// /// The first value to multiply /// The second value to multiply public static Int2 operator *(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.*"); /// /// Subtracts two values /// /// The first value to subtract /// The second value to subtract public static Int2 operator -(Int2 left, Int2 right) => throw new InvalidExecutionContextException($"{nameof(Int2)}.-"); } }