Vector4I
A 4-component int vector for coordinates and indices.
A C# struct with 4 int components: X, Y, Z and W. Suitable for integer coordinates and indices; components have Int32 range. Assignment copies the value. This is not a long-component vector.
Keep intermediate sums, differences and products within range. Conversion to a float vector cannot preserve every large integer exactly; changing type does not repair an overflow that already happened.
Vector4I has no C# conversion to bool. Compare with Vector4I.Zero for an exact zero-vector test; a nonzero vector alone does not establish a valid coordinate or index.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Vector4IConstructor
public Vector4I(int x, int y, int z, int w);Stores x, y, z, w in the corresponding int components without rounding, normalization or clamping. default(Vector4I) contains zeros. This is a struct: assignment copies every component.
| Name | Type | Default |
|---|---|---|
x | int | — |
y | int | — |
z | int | — |
w | int | — |
xInitial signed int component X.
yInitial signed int component Y.
zInitial signed int component Z.
wInitial signed int component W.
Properties5
ItemProperty
public int this[int index] { get; set; }Component indices: 0 = X, 1 = Y, 2 = Z, 3 = W. Getter and setter outside 0..3 throw ArgumentOutOfRangeException. Mutates this struct variable; a previously assigned copy is unchanged.
MaxValueProperty
public static Vector4I MaxValue { get; }(int.MaxValue, int.MaxValue, int.MaxValue, int.MaxValue). Finite maximum ints, not infinity; arithmetic can overflow. Returns a value copy; changing it does not change the constant.
MinValueProperty
public static Vector4I MinValue { get; }(int.MinValue, int.MinValue, int.MinValue, int.MinValue). Finite minimum ints, not negative infinity. Abs() throws OverflowException. Returns a value copy; changing it does not change the constant.
OneProperty
public static Vector4I One { get; }(1, 1, 1, 1). All components equal 1; this is not unit length. Returns a value copy; changing it does not change the constant.
ZeroProperty
public static Vector4I Zero { get; }(0, 0, 0, 0). Zero vector, equal to default(Vector4I). Returns a value copy; changing it does not change the constant.
Methods41
AbsVector4I
public Vector4I Abs();Returns a new struct with Math.Abs applied to each component, leaving the source unchanged. int.MinValue has no positive int counterpart and throws OverflowException.
Vector4IAbsolute values of all components if representable as int.
Clamp2 overloads
public Vector4I Clamp(Vector4I min, Vector4I max);Returns a copy with components clamped to inclusive bounds. Each axis has its own min and max. Throws ArgumentException if any lower bound exceeds its upper bound; bounds are not swapped.
| Name | Type | Default |
|---|---|---|
min | Vector4I | — |
max | Vector4I | — |
minInclusive lower bound, no greater than its corresponding upper bound.
maxInclusive upper bound, no less than its corresponding lower bound.
Vector4IVector with each component inside its specified range.
public Vector4I Clamp(int min, int max);Returns a copy with components clamped to inclusive bounds. The same min and max apply to all axes. Throws ArgumentException if any lower bound exceeds its upper bound; bounds are not swapped.
| Name | Type | Default |
|---|---|---|
min | int | — |
max | int | — |
minInclusive lower bound, no greater than its corresponding upper bound.
maxInclusive upper bound, no less than its corresponding lower bound.
Vector4IVector with each component inside its specified range.
Deconstructvoid
public void Deconstruct(out int x, out int y, out int z, out int w);Copies components into output arguments in X, Y, Z, W order. Enables var (x, y, z, w) = vector; leaves the source unchanged.
| Name | Type | Default |
|---|---|---|
x | int | — |
y | int | — |
z | int | — |
w | int | — |
xOutput copy of component X.
yOutput copy of component Y.
zOutput copy of component Z.
wOutput copy of component W.
DistanceSquaredToint
public int DistanceSquaredTo(Vector4I to);Computes (to - this).LengthSquared() using int. Overflow can occur in subtraction and then in squaring or addition; the result can be negative or misleadingly small. Do not use for large coordinates without range checks. For a wide range, convert components to double before subtraction; see the DistanceTo example.
| Name | Type | Default |
|---|---|---|
to | Vector4I | — |
toOther point coordinates; the difference from this point is first computed as int.
intSquared distance only when every intermediate integer operation fits int.
DistanceTofloat
public float DistanceTo(Vector4I to);Computes (to - this).Length(). A float result does not prevent int overflow during subtraction or squaring. From (int.MinValue, 0, 0, 0) to (int.MaxValue, 0, 0, 0), the installed SDK returns 1 instead of 4294967295.
WideDistance promotes each component to double before subtraction. The Vector4I overload includes W: it is an ordinary fourth component, not automatically a homogeneous coordinate.
using System;
using Reckfell;
public static class IntegerSpaceExamples
{
public static Vector3I CellAt(Vector3 position, int cellSize)
{
if (cellSize <= 0) throw new ArgumentOutOfRangeException(nameof(cellSize));
Vector3 cell = (position / cellSize).Floor();
for (int axis = 0; axis < 3; axis++)
if (!float.IsFinite(cell[axis]) || (double)cell[axis] < int.MinValue || (double)cell[axis] > int.MaxValue)
throw new ArgumentOutOfRangeException(nameof(position));
return (Vector3I)cell;
}
public static double WideDistance(Vector3I from, Vector3I to)
{
double dx = (double)to.X - from.X;
double dy = (double)to.Y - from.Y;
double dz = (double)to.Z - from.Z;
return Math.Sqrt(dx * dx + dy * dy + dz * dz);
}
public static double WideDistance(Vector4I from, Vector4I to)
{
double dx = (double)to.X - from.X;
double dy = (double)to.Y - from.Y;
double dz = (double)to.Z - from.Z;
double dw = (double)to.W - from.W;
return Math.Sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
}
}| Name | Type | Default |
|---|---|---|
to | Vector4I | — |
toOther point coordinates; the difference from this point is first computed as int.
floatEuclidean distance as float when intermediates do not overflow; otherwise it may be incorrect or NaN.
Equals2 overloads
public bool Equals(Vector4I other);Compares X, Y, Z, W exactly. Does not compare approximately or compare lengths.
| Name | Type | Default |
|---|---|---|
other | Vector4I | — |
otherOther Vector4I for exact comparison of X, Y, Z, W.
booltrue only when all components match and the type is compatible.
public override bool Equals(object? obj);Compares X, Y, Z, W exactly. The object must contain a Vector4I: Vector4 with matching coordinates, null and other types return false.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objObject to test; only a boxed Vector4I with matching X, Y, Z, W can match.
booltrue only when all components match and the type is compatible.
GetHashCodeint
public override int GetHashCode();Uses HashCode.Combine(X, Y, Z, W). Equal vectors have equal hashes, but a matching hash does not prove equality. Suitable for Dictionary<Vector4I, T> keys; do not persist the hash as an identifier across runs.
intHash of all integer components.
Lengthfloat
public float Length();Computes XX + YY + ZZ + WW as int, then takes a float square root. Squaring and addition can overflow: (50000, 0, 0, 0) yields NaN, while (65536, 0, 0, 0) yields 0. For a wide range, promote components to double before multiplication.
floatLength when intermediate values fit; overflow makes the result unreliable.
LengthSquaredint
public int LengthSquared();Computes XX + YY + ZZ + WW as int, without a square root. Squaring and addition can overflow: (50000, 0, 0, 0) yields a negative squared length, while (65536, 0, 0, 0) yields 0. For a wide range, promote components to double before multiplication.
intSquared length if the products and sum fit int.
Max2 overloads
public Vector4I Max(Vector4I with);Larger values are selected separately for X, Y, Z, W, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | Vector4I | — |
withComponents, or one shared value, for per-component comparison.
Vector4IComponent-wise maxima.
public Vector4I Max(int with);Larger values are selected separately for X, Y, Z, W, returning a copy. One value is compared with all components. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | int | — |
withComponents, or one shared value, for per-component comparison.
Vector4IComponent-wise maxima.
MaxAxisIndexVector4I.Axis
public Vector4I.Axis MaxAxisIndex();Selects the axis of the largest signed component, not magnitude. Ties select the first axis in X, Y, Z, W order. When all components match, the result is Axis.X.
Vector4I.AxisFirst axis with the maximum signed component.
Min2 overloads
public Vector4I Min(Vector4I with);Smaller values are selected separately for X, Y, Z, W, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | Vector4I | — |
withComponents, or one shared value, for per-component comparison.
Vector4IComponent-wise minima.
public Vector4I Min(int with);Smaller values are selected separately for X, Y, Z, W, returning a copy. One value is compared with all components. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | int | — |
withComponents, or one shared value, for per-component comparison.
Vector4IComponent-wise minima.
MinAxisIndexVector4I.Axis
public Vector4I.Axis MinAxisIndex();Selects the axis of the smallest signed component, not magnitude. Ties select the last axis in X, Y, Z, W order. When all components match, the result is Axis.W.
Vector4I.AxisLast axis with the minimum signed component.
SignVector4I
public Vector4I Sign();Returns a new struct with each negative component replaced by -1, zero by 0 and each positive component by 1. int.MinValue yields -1 without taking its absolute value. This does not normalize length: (1, 1, 1, 1) stays (1, 1, 1, 1).
Vector4IComponent signs, each -1, 0 or 1.
Snapped2 overloads
public Vector4I Snapped(Vector4I step);Snaps each component using the double formula floor(value / step + 0.5) * step, then casts to int. A positive step rounds half ties toward the larger value: (6, -6, 2, 2).Snapped(4) gives (8, -4, 4, 4). A zero step preserves the component; a negative step changes half ties, so use a positive step. The result must fit int; range clamping is not performed.
| Name | Type | Default |
|---|---|---|
step | Vector4I | — |
stepPer-axis or shared step. A positive step is recommended; 0 preserves the corresponding component.
Vector4INew struct with snapped components; the source is unchanged.
public Vector4I Snapped(int step);Snaps each component using the double formula floor(value / step + 0.5) * step, then casts to int. A positive step rounds half ties toward the larger value: (6, -6, 2, 2).Snapped(4) gives (8, -4, 4, 4). A zero step preserves the component; a negative step changes half ties, so use a positive step. The result must fit int; range clamping is not performed.
| Name | Type | Default |
|---|---|---|
step | int | — |
stepPer-axis or shared step. A positive step is recommended; 0 preserves the corresponding component.
Vector4INew struct with snapped components; the source is unchanged.
ToString2 overloads
public override string ToString();Uses CultureInfo.InvariantCulture regardless of the current culture; vector (3, -4, 2, 2) returns "(3, -4, 2, 2)". Equivalent to ToString(null).
stringBoth components as a string in the selected numeric format.
public string ToString(string? format);Uses CultureInfo.InvariantCulture regardless of the current culture; vector (3, -4, 2, 2) returns "(3, -4, 2, 2)". Applies format to each int: "D4" gives "(0003, -0004, 0002, 0002)". Invalid formatting throws FormatException.
| Name | Type | Default |
|---|---|---|
format | string | — |
formatint numeric format applied to all components, such as "D4"; null uses default formatting. An invalid format throws FormatException.
stringBoth components as a string in the selected numeric format.
op_AdditionVector4I
public static Vector4I operator +(Vector4I left, Vector4I right);Returns (left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W) as a new struct. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector4IComponent-wise result; caller variables are unchanged.
op_Division2 overloads
public static Vector4I operator /(Vector4I vec, Vector4I divisorv);Divides each integer component, truncating toward zero: (-7, 7, 0, 0) / (2, 2, 2, 2) gives (-3, 3, 0, 0). A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. Divisors are supplied per axis.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
divisorv | Vector4I | — |
vecVector operand; a new struct value is returned.
divisorvNonzero divisors for the corresponding X, Y, Z, W components.
Vector4IInteger quotients for X, Y, Z, W.
public static Vector4I operator /(Vector4I vec, int divisor);Divides each integer component, truncating toward zero: (-7, 7, 0, 0) / 2 gives (-3, 3, 0, 0). A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. One divisor applies to all axes.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
divisor | int | — |
vecVector operand; a new struct value is returned.
divisorShared nonzero divisor for X, Y, Z, W.
Vector4IInteger quotients for X, Y, Z, W.
op_Equalitybool
public static bool operator ==(Vector4I left, Vector4I right);Compares all integer components exactly. Does not compare lengths or use approximate tolerance.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue if both X, Y, Z, W match.
op_ExplicitVector4I
public static explicit operator Vector4I(Vector4 value);Casts each Vector4 component to int by truncating toward zero: (-1.9, 1.9, -2.9, -2.9) gives (-1, 1, -2, -2). For negative cell coordinates, use Floor first. Check finiteness and int range before casting; portable results are not guaranteed for NaN, Infinity or out-of-range values.
| Name | Type | Default |
|---|---|---|
value | Vector4 | — |
valueSource vector; precision and range restrictions are described by the conversion.
Vector4IInteger components truncated toward zero for inputs within the valid range.
op_GreaterThanbool
public static bool operator >(Vector4I left, Vector4I right);Lexicographic comparison in X, Y, Z, W order: each next component is checked only when previous components match. This is a sorting order, not a component-wise bounds or length test. (1, 100, 0, 0) < (2, -100, 0, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue when left > right holds in the stated order.
op_GreaterThanOrEqualbool
public static bool operator >=(Vector4I left, Vector4I right);Lexicographic comparison in X, Y, Z, W order: each next component is checked only when previous components match. This is a sorting order, not a component-wise bounds or length test. (1, 100, 0, 0) < (2, -100, 0, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue when left >= right holds in the stated order.
op_ImplicitVector4
public static implicit operator Vector4(Vector4I value);Converts each int component to the installed SDK’s float Vector4 component. Large integers can lose precision: 16777217 becomes 16777216. Keep Vector4I for exact grid arithmetic until the presentation step.
| Name | Type | Default |
|---|---|---|
value | Vector4I | — |
valueSource vector; precision and range restrictions are described by the conversion.
Vector4Vector4 with converted components; large int precision is not guaranteed.
op_Inequalitybool
public static bool operator !=(Vector4I left, Vector4I right);Negates ==. Does not compare lengths or use approximate tolerance.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue if at least one component differs.
op_LessThanbool
public static bool operator <(Vector4I left, Vector4I right);Lexicographic comparison in X, Y, Z, W order: each next component is checked only when previous components match. This is a sorting order, not a component-wise bounds or length test. (1, 100, 0, 0) < (2, -100, 0, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue when left < right holds in the stated order.
op_LessThanOrEqualbool
public static bool operator <=(Vector4I left, Vector4I right);Lexicographic comparison in X, Y, Z, W order: each next component is checked only when previous components match. This is a sorting order, not a component-wise bounds or length test. (1, 100, 0, 0) < (2, -100, 0, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
booltrue when left <= right holds in the stated order.
op_Modulus2 overloads
public static Vector4I operator %(Vector4I vec, Vector4I divisorv);Computes C# remainders from truncated division: (10, -20, 0, 0) % (7, 7, 7, 7) gives (3, -6, 0, 0). This is not positive cyclic wrapping; use Mathf.PosMod with a positive modulus for that. A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. Divisors are supplied per axis.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
divisorv | Vector4I | — |
vecVector operand; a new struct value is returned.
divisorvNonzero divisors for the corresponding X, Y, Z, W components.
Vector4IRemainders for X, Y, Z, W, with the dividend’s sign or zero.
public static Vector4I operator %(Vector4I vec, int divisor);Computes C# remainders from truncated division: (10, -20, 0, 0) % 7 gives (3, -6, 0, 0). This is not positive cyclic wrapping; use Mathf.PosMod with a positive modulus for that. A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. One divisor applies to all axes.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
divisor | int | — |
vecVector operand; a new struct value is returned.
divisorShared nonzero divisor for X, Y, Z, W.
Vector4IRemainders for X, Y, Z, W, with the dividend’s sign or zero.
op_Multiply3 overloads
public static Vector4I operator *(Vector4I left, Vector4I right);Returns (left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W) as a new struct. An int scales all axes; two vectors multiply component-wise, not as a dot product. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector4IComponent-wise result; caller variables are unchanged.
public static Vector4I operator *(Vector4I vec, int scale);Returns (vec.X * scale, vec.Y * scale, vec.Z * scale, vec.W * scale) as a new struct. An int scales all axes; two vectors multiply component-wise, not as a dot product. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
scale | int | — |
vecVector operand; a new struct value is returned.
scaleInteger multiplier for all components; each product must fit int.
Vector4IComponent-wise result; caller variables are unchanged.
public static Vector4I operator *(int scale, Vector4I vec);Returns (vec.X * scale, vec.Y * scale, vec.Z * scale, vec.W * scale) as a new struct. An int scales all axes; two vectors multiply component-wise, not as a dot product. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator.
| Name | Type | Default |
|---|---|---|
scale | int | — |
vec | Vector4I | — |
scaleInteger multiplier for all components; each product must fit int.
vecVector operand; a new struct value is returned.
Vector4IComponent-wise result; caller variables are unchanged.
op_SubtractionVector4I
public static Vector4I operator -(Vector4I left, Vector4I right);Returns (left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W) as a new struct. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator.
| Name | Type | Default |
|---|---|---|
left | Vector4I | — |
right | Vector4I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector4IComponent-wise result; caller variables are unchanged.
op_UnaryNegationVector4I
public static Vector4I operator -(Vector4I vec);Returns (-X, -Y, -Z, -W) as a new struct. In the installed SDK, int overflow wraps without saturation; checked around the call does not change the compiled operator. Negating int.MinValue leaves int.MinValue.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
vecVector operand; a new struct value is returned.
Vector4IComponent-wise result; caller variables are unchanged.
op_UnaryPlusVector4I
public static Vector4I operator +(Vector4I vec);Returns (X, Y, Z, W) as a new struct. Unary plus leaves the value unchanged.
| Name | Type | Default |
|---|---|---|
vec | Vector4I | — |
vecVector operand; a new struct value is returned.
Vector4IComponent-wise result; caller variables are unchanged.
Fields and constants4
WField
public int W;Mutable signed 32-bit W component, also accessible through [3]. Assignment does not change other components or clamp the range.
XField
public int X;Mutable signed 32-bit X component, also accessible through [0]. Assignment does not change other components or clamp the range.
YField
public int Y;Mutable signed 32-bit Y component, also accessible through [1]. Assignment does not change other components or clamp the range.
ZField
public int Z;Mutable signed 32-bit Z component, also accessible through [2]. Assignment does not change other components or clamp the range.
Vector4I.Axis
| Value | Description |
|---|---|
W = 3 | Enumerated value for the W axis. Returned by |
X = 0 | Enumerated value for the X axis. Returned by |
Y = 1 | Enumerated value for the Y axis. Returned by |
Z = 2 | Enumerated value for the Z axis. Returned by |