Vector3I
A 3-component int vector for coordinates and indices.
A C# struct with 3 int components: X, Y and Z. 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.
Vector3I has no C# conversion to bool. Compare with Vector3I.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
Vector3IConstructor
public Vector3I(int x, int y, int z);Stores x, y, z in the corresponding int components without rounding, normalization or clamping. default(Vector3I) contains zeros. This is a struct: assignment copies every component.
| Name | Type | Default |
|---|---|---|
x | int | — |
y | int | — |
z | int | — |
xInitial signed int component X.
yInitial signed int component Y.
zInitial signed int component Z.
Properties11
BackProperty
public static Vector3I Back { get; }(0, 0, 1). Back: positive Z. Returns a value copy; changing it does not change the constant.
DownProperty
public static Vector3I Down { get; }(0, -1, 0). Down: negative Y. Returns a value copy; changing it does not change the constant.
ForwardProperty
public static Vector3I Forward { get; }(0, 0, -1). Forward: negative Z. Returns a value copy; changing it does not change the constant.
ItemProperty
public int this[int index] { get; set; }Component indices: 0 = X, 1 = Y, 2 = Z. Getter and setter outside 0..2 throw ArgumentOutOfRangeException. Mutates this struct variable; a previously assigned copy is unchanged.
LeftProperty
public static Vector3I Left { get; }(-1, 0, 0). Negative X. Returns a value copy; changing it does not change the constant.
MaxValueProperty
public static Vector3I MaxValue { get; }(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 Vector3I MinValue { get; }(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 Vector3I One { get; }(1, 1, 1). All components equal 1; this is not unit length. Returns a value copy; changing it does not change the constant.
RightProperty
public static Vector3I Right { get; }(1, 0, 0). Positive X. Returns a value copy; changing it does not change the constant.
UpProperty
public static Vector3I Up { get; }(0, 1, 0). Up: positive Y. Returns a value copy; changing it does not change the constant.
ZeroProperty
public static Vector3I Zero { get; }(0, 0, 0). Zero vector, equal to default(Vector3I). Returns a value copy; changing it does not change the constant.
Methods41
AbsVector3I
public Vector3I 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.
Vector3IAbsolute values of all components if representable as int.
Clamp2 overloads
public Vector3I Clamp(Vector3I min, Vector3I 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 | Vector3I | — |
max | Vector3I | — |
minInclusive lower bound, no greater than its corresponding upper bound.
maxInclusive upper bound, no less than its corresponding lower bound.
Vector3IVector with each component inside its specified range.
public Vector3I 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.
Vector3IVector with each component inside its specified range.
Deconstructvoid
public void Deconstruct(out int x, out int y, out int z);Copies components into output arguments in X, Y, Z order. Enables var (x, y, z) = vector; leaves the source unchanged.
| Name | Type | Default |
|---|---|---|
x | int | — |
y | int | — |
z | int | — |
xOutput copy of component X.
yOutput copy of component Y.
zOutput copy of component Z.
DistanceSquaredToint
public int DistanceSquaredTo(Vector3I 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 | Vector3I | — |
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(Vector3I to);Computes (to - this).Length(). A float result does not prevent int overflow during subtraction or squaring. From (int.MinValue, 0, 0) to (int.MaxValue, 0, 0), the installed SDK returns 1 instead of 4294967295.
WideDistance promotes each component to double before subtraction. CellAt uses Floor: (-1, 33, -17) with step 16 gives (-1, 2, -2); nonpositive steps and unrepresentable coordinates are rejected.
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 | Vector3I | — |
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(Vector3I other);Compares X, Y, Z exactly. Does not compare approximately or compare lengths.
| Name | Type | Default |
|---|---|---|
other | Vector3I | — |
otherOther Vector3I for exact comparison of X, Y, Z.
booltrue only when all components match and the type is compatible.
public override bool Equals(object? obj);Compares X, Y, Z exactly. The object must contain a Vector3I: Vector3 with matching coordinates, null and other types return false.
| Name | Type | Default |
|---|---|---|
obj | object | — |
objObject to test; only a boxed Vector3I with matching X, Y, Z can match.
booltrue only when all components match and the type is compatible.
GetHashCodeint
public override int GetHashCode();Uses HashCode.Combine(X, Y, Z). Equal vectors have equal hashes, but a matching hash does not prove equality. Suitable for Dictionary<Vector3I, T> keys; do not persist the hash as an identifier across runs.
intHash of all integer components.
Lengthfloat
public float Length();Computes XX + YY + Z*Z as int, then takes a float square root. Squaring and addition can overflow: (50000, 0, 0) yields NaN, while (65536, 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 + Z*Z as int, without a square root. Squaring and addition can overflow: (50000, 0, 0) yields a negative squared length, while (65536, 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 Vector3I Max(Vector3I with);Larger values are selected separately for X, Y, Z, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | Vector3I | — |
withComponents, or one shared value, for per-component comparison.
Vector3IComponent-wise maxima.
public Vector3I Max(int with);Larger values are selected separately for X, Y, Z, 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.
Vector3IComponent-wise maxima.
MaxAxisIndexVector3I.Axis
public Vector3I.Axis MaxAxisIndex();Selects the axis of the largest signed component, not magnitude. Ties select the first axis in X, Y, Z order. When all components match, the result is Axis.X.
Vector3I.AxisFirst axis with the maximum signed component.
Min2 overloads
public Vector3I Min(Vector3I with);Smaller values are selected separately for X, Y, Z, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.
| Name | Type | Default |
|---|---|---|
with | Vector3I | — |
withComponents, or one shared value, for per-component comparison.
Vector3IComponent-wise minima.
public Vector3I Min(int with);Smaller values are selected separately for X, Y, Z, 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.
Vector3IComponent-wise minima.
MinAxisIndexVector3I.Axis
public Vector3I.Axis MinAxisIndex();Selects the axis of the smallest signed component, not magnitude. Ties select the last axis in X, Y, Z order. When all components match, the result is Axis.Z.
Vector3I.AxisLast axis with the minimum signed component.
SignVector3I
public Vector3I 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) stays (1, 1, 1).
Vector3IComponent signs, each -1, 0 or 1.
Snapped2 overloads
public Vector3I Snapped(Vector3I 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).Snapped(4) gives (8, -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 | Vector3I | — |
stepPer-axis or shared step. A positive step is recommended; 0 preserves the corresponding component.
Vector3INew struct with snapped components; the source is unchanged.
public Vector3I 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).Snapped(4) gives (8, -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.
Vector3INew 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) returns "(3, -4, 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) returns "(3, -4, 2)". Applies format to each int: "D4" gives "(0003, -0004, 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_AdditionVector3I
public static Vector3I operator +(Vector3I left, Vector3I right);Returns (left.X + right.X, left.Y + right.Y, left.Z + right.Z) 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 | Vector3I | — |
right | Vector3I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector3IComponent-wise result; caller variables are unchanged.
op_Division2 overloads
public static Vector3I operator /(Vector3I vec, Vector3I divisorv);Divides each integer component, truncating toward zero: (-7, 7, 0) / (2, 2, 2) gives (-3, 3, 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 | Vector3I | — |
divisorv | Vector3I | — |
vecVector operand; a new struct value is returned.
divisorvNonzero divisors for the corresponding X, Y, Z components.
Vector3IInteger quotients for X, Y, Z.
public static Vector3I operator /(Vector3I vec, int divisor);Divides each integer component, truncating toward zero: (-7, 7, 0) / 2 gives (-3, 3, 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 | Vector3I | — |
divisor | int | — |
vecVector operand; a new struct value is returned.
divisorShared nonzero divisor for X, Y, Z.
Vector3IInteger quotients for X, Y, Z.
op_Equalitybool
public static bool operator ==(Vector3I left, Vector3I right);Compares all integer components exactly. Does not compare lengths or use approximate tolerance.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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 match.
op_ExplicitVector3I
public static explicit operator Vector3I(Vector3 value);Casts each Vector3 component to int by truncating toward zero: (-1.9, 1.9, -2.9) gives (-1, 1, -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 | Vector3 | — |
valueSource vector; precision and range restrictions are described by the conversion.
Vector3IInteger components truncated toward zero for inputs within the valid range.
op_GreaterThanbool
public static bool operator >(Vector3I left, Vector3I right);Lexicographic comparison in X, Y, Z 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) < (2, -100, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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 >=(Vector3I left, Vector3I right);Lexicographic comparison in X, Y, Z 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) < (2, -100, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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_ImplicitVector3
public static implicit operator Vector3(Vector3I value);Converts each int component to the installed SDK’s float Vector3 component. Large integers can lose precision: 16777217 becomes 16777216. Keep Vector3I for exact grid arithmetic until the presentation step.
| Name | Type | Default |
|---|---|---|
value | Vector3I | — |
valueSource vector; precision and range restrictions are described by the conversion.
Vector3Vector3 with converted components; large int precision is not guaranteed.
op_Inequalitybool
public static bool operator !=(Vector3I left, Vector3I right);Negates ==. Does not compare lengths or use approximate tolerance.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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 <(Vector3I left, Vector3I right);Lexicographic comparison in X, Y, Z 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) < (2, -100, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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 <=(Vector3I left, Vector3I right);Lexicographic comparison in X, Y, Z 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) < (2, -100, 0) is true despite the larger Y on the left. Test axes explicitly for bounds.
| Name | Type | Default |
|---|---|---|
left | Vector3I | — |
right | Vector3I | — |
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 Vector3I operator %(Vector3I vec, Vector3I divisorv);Computes C# remainders from truncated division: (10, -20, 0) % (7, 7, 7) gives (3, -6, 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 | Vector3I | — |
divisorv | Vector3I | — |
vecVector operand; a new struct value is returned.
divisorvNonzero divisors for the corresponding X, Y, Z components.
Vector3IRemainders for X, Y, Z, with the dividend’s sign or zero.
public static Vector3I operator %(Vector3I vec, int divisor);Computes C# remainders from truncated division: (10, -20, 0) % 7 gives (3, -6, 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 | Vector3I | — |
divisor | int | — |
vecVector operand; a new struct value is returned.
divisorShared nonzero divisor for X, Y, Z.
Vector3IRemainders for X, Y, Z, with the dividend’s sign or zero.
op_Multiply3 overloads
public static Vector3I operator *(Vector3I left, Vector3I right);Returns (left.X * right.X, left.Y * right.Y, left.Z * right.Z) 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 | Vector3I | — |
right | Vector3I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector3IComponent-wise result; caller variables are unchanged.
public static Vector3I operator *(Vector3I vec, int scale);Returns (vec.X * scale, vec.Y * scale, vec.Z * 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 | Vector3I | — |
scale | int | — |
vecVector operand; a new struct value is returned.
scaleInteger multiplier for all components; each product must fit int.
Vector3IComponent-wise result; caller variables are unchanged.
public static Vector3I operator *(int scale, Vector3I vec);Returns (vec.X * scale, vec.Y * scale, vec.Z * 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 | Vector3I | — |
scaleInteger multiplier for all components; each product must fit int.
vecVector operand; a new struct value is returned.
Vector3IComponent-wise result; caller variables are unchanged.
op_SubtractionVector3I
public static Vector3I operator -(Vector3I left, Vector3I right);Returns (left.X - right.X, left.Y - right.Y, left.Z - right.Z) 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 | Vector3I | — |
right | Vector3I | — |
leftLeft vector; the operation does not mutate the caller’s variable.
rightRight vector; the operation does not mutate the caller’s variable.
Vector3IComponent-wise result; caller variables are unchanged.
op_UnaryNegationVector3I
public static Vector3I operator -(Vector3I vec);Returns (-X, -Y, -Z) 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 | Vector3I | — |
vecVector operand; a new struct value is returned.
Vector3IComponent-wise result; caller variables are unchanged.
op_UnaryPlusVector3I
public static Vector3I operator +(Vector3I vec);Returns (X, Y, Z) as a new struct. Unary plus leaves the value unchanged.
| Name | Type | Default |
|---|---|---|
vec | Vector3I | — |
vecVector operand; a new struct value is returned.
Vector3IComponent-wise result; caller variables are unchanged.
Fields and constants3
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. In 3D, positive Y points up.
ZField
public int Z;Mutable signed 32-bit Z component, also accessible through [2]. Assignment does not change other components or clamp the range. Forward points along negative Z.
Vector3I.Axis
| Value | Description |
|---|---|
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 |