Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt

Use this file to discover all available pages before exploring further.

Int4 is a 4-component vector backed by int (32-bit signed integer) values. It is defined in the Prowl.Vector namespace and marked [Serializable]. Common uses include packed RGBA color channels (0–255), shader register indices, and 4D discrete coordinates.
Int4 does not provide Normalize, Length, Cross, Slerp, or other floating-point geometric methods. Use Float4 or Double4 when those operations are required. Int4 does expose a Dot method that returns an int.

Declaration

[Serializable]
public partial struct Int4 : IEquatable<Int4>, IFormattable

Fields

FieldTypeDescription
XintThe X component.
YintThe Y component.
ZintThe Z component.
WintThe W component.

Static Constants

PropertyValueDescription
Zero(0, 0, 0, 0)The zero vector.
One(1, 1, 1, 1)A vector with all components set to one.
UnitX(1, 0, 0, 0)The unit vector along the X-axis.
UnitY(0, 1, 0, 0)The unit vector along the Y-axis.
UnitZ(0, 0, 1, 0)The unit vector along the Z-axis.
UnitW(0, 0, 0, 1)The unit vector along the W-axis.

Constructors

SignatureDescription
Int4(int scalar)Sets all four components to scalar.
Int4(int x, int y, int z, int w)Sets X, Y, Z, and W individually.
Int4(Int4 v)Copy constructor.
Int4(int[] array)Reads components from an int[] of at least length 4.
Int4(IEnumerable<int> values)Reads components from an enumerable of at least 4 elements.
Int4(ReadOnlySpan<int> span)Reads components from a read-only span of at least length 4.
Int4(Span<int> span)Reads components from a span of at least length 4.
Int4(Int2 xy, int z, int w)Constructs from an Int2 for XY and separate Z/W scalars.
Int4(int x, Int2 yz, int w)Constructs from a separate X, an Int2 for YZ, and a separate W.
Int4(int x, int y, Int2 zw)Constructs from separate X/Y and an Int2 for ZW.
Int4(Int2 xy, Int2 zw)Constructs from two Int2 values.
Int4(Int3 xyz, int w)Constructs from an Int3 and a separate W scalar.
Int4(int x, Int3 yzw)Constructs from a separate X and an Int3 for YZW.
Int4(Float4 v)Truncates a Float4 to integer components (explicit cast).
Int4(Double4 v)Truncates a Double4 to integer components (explicit cast).

Properties

PropertyTypeDescription
this[int index]intGets or sets a component by index. 0X, 1Y, 2Z, 3W. Throws IndexOutOfRangeException for any other value.

Operators

Arithmetic — vector × vector (component-wise)

OperatorSignatureDescription
+Int4 + Int4Component-wise addition.
-Int4 - Int4Component-wise subtraction.
*Int4 * Int4Component-wise multiplication.
/Int4 / Int4Component-wise integer division.
%Int4 % Int4Component-wise remainder.

Arithmetic — vector × scalar

OperatorSignatureDescription
+Int4 + int / int + Int4Adds scalar to each component.
-Int4 - int / int - Int4Subtracts scalar from each component (or vice-versa).
*Int4 * int / int * Int4Scales each component.
/Int4 / int / int / Int4Divides each component by scalar (or divides scalar by each component).
%Int4 % int / int % Int4Remainder with scalar.

Bitwise

OperatorSignatureDescription
&Int4 & Int4Component-wise bitwise AND.
|Int4 | Int4Component-wise bitwise OR.
^Int4 ^ Int4Component-wise bitwise XOR.
~~Int4Component-wise bitwise NOT.
<<Int4 << intShifts each component left by the given amount.
>>Int4 >> intShifts each component right by the given amount.

Unary & comparison

OperatorSignatureDescription
Unary --Int4Negates all four components.
==Int4 == Int4Component-wise equality.
!=Int4 != Int4Component-wise inequality.

Casts

ConversionKindDescription
Int2Int4implicitExtends to 4D with Z = 0, W = 0.
Int3Int4implicitExtends to 4D with W = 0.
Int4Int2explicitDrops Z and W.
Int4Int3explicitDrops W.
Float4Int4explicitTruncates float components to int.
Double4Int4explicitTruncates double components to int.

Static Methods

SignatureDescription
static int Dot(Int4 x, Int4 y)Returns the integer dot product x.X*y.X + x.Y*y.Y + x.Z*y.Z + x.W*y.W.

Swizzles

Int4 exposes all GLSL-style 2-, 3-, and 4-component swizzle properties (auto-generated). Read-write swizzles reassign the underlying components; read-only swizzles (where any component repeats) are computed getters. Examples:
Int4 v = new Int4(1, 2, 3, 4);

Int2 xy   = v.XY;    // (1, 2) — get/set
Int3 zyx  = v.ZYX;   // (3, 2, 1) — get/set
Int4 wzyx = v.WZYX;  // (4, 3, 2, 1) — get/set
Int4 xxxx = v.XXXX;  // (1, 1, 1, 1) — get-only

Instance Methods

SignatureDescription
int[] ToArray()Returns [X, Y, Z, W] as a new array.
string ToString()Formats as (X, Y, Z, W) using the current culture.
string ToString(string format)Formats each component with the given numeric format string.
string ToString(string format, IFormatProvider formatProvider)Fully customizable format output.
bool Equals(Int4 other)Component-wise equality.
int GetHashCode()Combined hash of all four components.

Code Example

using Prowl.Vector;

// Packed RGBA color (0–255 per channel)
Int4 red   = new Int4(255, 0,   0,   255);
Int4 blue  = new Int4(0,   0,   255, 255);

// Blend two colors at 50% (integer midpoint)
Int4 blended = (red + blue) / 2;  // (127, 0, 127, 255)

// Bit-mask to strip alpha
Int4 noAlpha = blended & new Int4(0xFF, 0xFF, 0xFF, 0);

// Dot product (e.g. luminance approximation scaled ×1000)
Int4 lumWeights = new Int4(299, 587, 114, 0);
int  luminance  = Int4.Dot(red, lumWeights) / 1000;  // ≈ 76

// Implicit widening from Int3
Int3 xyz = new Int3(10, 20, 30);
Int4 xyzw = xyz;  // implicit — W = 0

Console.WriteLine($"Blended  : {blended}");
Console.WriteLine($"No alpha : {noAlpha}");
Console.WriteLine($"Luminance: {luminance}");
Console.WriteLine($"From Int3: {xyzw}");

Build docs developers (and LLMs) love