reckfellENGINE

Vector2I

A 2-component int vector for coordinates and indices.

On this page
struct Vector2IReckfellSharpInherits ValueType

A C# struct with 2 int components: X and Y. 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.

Vector2I has no C# conversion to bool. Compare with Vector2I.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

Vector2IConstructor
# Vector2I
C#
public Vector2I(int x, int y);

Stores x and y without rounding, normalization or clamping. Each component is int; default(Vector2I) is (0, 0). This is a struct: assignment copies the value.

Parameters
NameTypeDefault
xint—
yint—
x

Initial signed int component X.

y

Initial signed int component Y.

Properties9

DownProperty
# Down
C#
public static Vector2I Down { get; }

(0, 1). Down in 2D: positive Y. Returns a value copy: changing a local copy does not change the constant.

ItemProperty
# Item
C#
public int this[int index] { get; set; }

Index 0 reads or writes X; index 1 reads or writes Y. Any other index throws ArgumentOutOfRangeException in both getter and setter. Mutates this struct variable; a previously assigned copy remains unchanged.

LeftProperty
# Left
C#
public static Vector2I Left { get; }

(-1, 0). Negative X. Returns a value copy: changing a local copy does not change the constant.

MaxValueProperty
# MaxValue
C#
public static Vector2I MaxValue { get; }

(int.MaxValue, int.MaxValue). Finite maximum ints, not infinity. Arithmetic using them can overflow. Returns a value copy: changing a local copy does not change the constant.

MinValueProperty
# MinValue
C#
public static Vector2I MinValue { get; }

(int.MinValue, int.MinValue). Finite minimum ints, not negative infinity. Abs() on this value throws OverflowException. Returns a value copy: changing a local copy does not change the constant.

OneProperty
# One
C#
public static Vector2I One { get; }

(1, 1). Both components are one; this is not unit length. Returns a value copy: changing a local copy does not change the constant.

RightProperty
# Right
C#
public static Vector2I Right { get; }

(1, 0). Positive X. Returns a value copy: changing a local copy does not change the constant.

UpProperty
# Up
C#
public static Vector2I Up { get; }

(0, -1). Up in 2D: negative Y. Returns a value copy: changing a local copy does not change the constant.

ZeroProperty
# Zero
C#
public static Vector2I Zero { get; }

(0, 0). Zero vector, equal to default(Vector2I). Returns a value copy: changing a local copy does not change the constant.

Methods42

AbsVector2I
# Abs
C#
public Vector2I 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.

Returns Vector2I

(abs(X), abs(Y)) when both absolute values fit int.

Aspectfloat
# Aspect
C#
public float Aspect();

Divides X by Y as float, not as integer division. (3, 2) gives 1.5. Y == 0 produces signed Infinity, or NaN for (0, 0), rather than DivideByZeroException. Large int values lose precision when converted to float.

Returns float

X / (float)Y; the result can be infinite or NaN.

Clamp2 overloads
# Clamp · 1/2
C#
public Vector2I Clamp(Vector2I min, Vector2I 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.

Parameters
NameTypeDefault
minVector2I—
maxVector2I—
min

Inclusive lower bound, no greater than its corresponding upper bound.

max

Inclusive upper bound, no less than its corresponding lower bound.

Returns Vector2I

Vector with each component inside its specified range.

# Clamp · 2/2
C#
public Vector2I Clamp(int min, int max);

Returns a copy with components clamped to inclusive bounds. The same min and max apply to both axes. Throws ArgumentException if any lower bound exceeds its upper bound; bounds are not swapped.

Parameters
NameTypeDefault
minint—
maxint—
min

Inclusive lower bound, no greater than its corresponding upper bound.

max

Inclusive upper bound, no less than its corresponding lower bound.

Returns Vector2I

Vector with each component inside its specified range.

Deconstructvoid
# Deconstruct
C#
public void Deconstruct(out int x, out int y);

Copies X and Y into the output arguments, enabling var (x, y) = vector. Leaves the vector unchanged.

Parameters
NameTypeDefault
xint—
yint—
x

Output copy of component X.

y

Output copy of component Y.

DistanceSquaredToint
# DistanceSquaredTo
C#
public int DistanceSquaredTo(Vector2I 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.

Parameters
NameTypeDefault
toVector2I—
to

Other point coordinates; the difference from this point is first computed as int.

Returns int

Squared distance only when every intermediate integer operation fits int.

DistanceTofloat
# DistanceTo
C#
public float DistanceTo(Vector2I to);

Computes (to - this).Length(). A float return type does not prevent int overflow during subtraction or squaring. Between (int.MinValue, 0) and (int.MaxValue, 0), the current SDK returns 1 instead of 4294967295.

WideDistance converts components to double before subtraction. CellAt uses Floor: position (-1, 33) with cell size 16 gives (-1, 2). A plain Vector2I cast truncates toward zero and is unsuitable for negative cell coordinates.

C#
using System;
using Reckfell;

public static class IntegerGridExamples
{
    public static Vector2I CellAt(Vector2 position, int cellSize)
    {
        if (cellSize <= 0) throw new ArgumentOutOfRangeException(nameof(cellSize));
        Vector2 cell = (position / cellSize).Floor();
        if (!cell.IsFinite() || (double)cell.X < int.MinValue || (double)cell.X > int.MaxValue
            || (double)cell.Y < int.MinValue || (double)cell.Y > int.MaxValue)
            throw new ArgumentOutOfRangeException(nameof(position));
        return (Vector2I)cell;
    }

    public static double WideDistance(Vector2I from, Vector2I to)
    {
        double dx = (double)to.X - from.X;
        double dy = (double)to.Y - from.Y;
        return Math.Sqrt(dx * dx + dy * dy);
    }
}
Parameters
NameTypeDefault
toVector2I—
to

Other point coordinates; the difference from this point is first computed as int.

Returns float

Euclidean distance as float when intermediates do not overflow; otherwise it may be incorrect or NaN.

Equals2 overloads
# Equals · 1/2
C#
public bool Equals(Vector2I other);

Compares X and Y exactly. Does not compare approximately or compare lengths.

Parameters
NameTypeDefault
otherVector2I—
other

Other Vector2I for exact comparison of X and Y.

Returns bool

true only when both components match and the type is compatible.

# Equals · 2/2
C#
public override bool Equals(object? obj);

Compares X and Y exactly. The object must contain a Vector2I: Vector2 with matching coordinates, null and other types return false.

Parameters
NameTypeDefault
objobject—
obj

Object to test; only a boxed Vector2I with matching X and Y can match.

Returns bool

true only when both components match and the type is compatible.

GetHashCodeint
# GetHashCode
C#
public override int GetHashCode();

Uses HashCode.Combine(X, Y). Equal vectors have equal hashes, but a matching hash does not prove equality. Suitable for Dictionary<Vector2I, T> keys; do not persist the hash as an identifier across runs.

Returns int

Hash of both integer components.

Lengthfloat
# Length
C#
public float Length();

Computes XX and YY and their sum as int before taking a float square root. (3, -4) yields 5. In the current SDK, (50000, 0) yields NaN and (65536, 0) yields 0 due to overflow. For a wide range, use Math.Sqrt((double)X * X + (double)Y * Y).

Returns float

Length when intermediate values fit; overflow makes the result unreliable.

LengthSquaredint
# LengthSquared
C#
public int LengthSquared();

Computes XX + YY as int without a square root. Both squaring and addition can overflow: (50000, 0) yields a negative result and (65536, 0) yields 0. This is not a safe Length alternative for arbitrary ints. For a wide range, promote operands to double before multiplication.

Returns int

Squared length if the products and sum fit int.

Max2 overloads
# Max · 1/2
C#
public Vector2I Max(Vector2I with);

Larger values are selected separately for X and Y, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.

Parameters
NameTypeDefault
withVector2I—
with

Components, or one shared value, for per-component comparison.

Returns Vector2I

Component-wise maxima.

# Max · 2/2
C#
public Vector2I Max(int with);

Larger values are selected separately for X and Y, returning a copy. One value is compared with both components. This does not select an entire vector using < or > ordering.

Parameters
NameTypeDefault
withint—
with

Components, or one shared value, for per-component comparison.

Returns Vector2I

Component-wise maxima.

MaxAxisIndexVector2I.Axis
# MaxAxisIndex
C#
public Vector2I.Axis MaxAxisIndex();

Selects the axis of the larger signed component, not the larger magnitude. Returns Axis.X when X == Y. For example, (-9, 2) yields Axis.Y.

Returns Vector2I.Axis

Axis.X when X >= Y; otherwise Axis.Y.

Min2 overloads
# Min · 1/2
C#
public Vector2I Min(Vector2I with);

Smaller values are selected separately for X and Y, returning a copy. The argument supplies per-axis values. This does not select an entire vector using < or > ordering.

Parameters
NameTypeDefault
withVector2I—
with

Components, or one shared value, for per-component comparison.

Returns Vector2I

Component-wise minima.

# Min · 2/2
C#
public Vector2I Min(int with);

Smaller values are selected separately for X and Y, returning a copy. One value is compared with both components. This does not select an entire vector using < or > ordering.

Parameters
NameTypeDefault
withint—
with

Components, or one shared value, for per-component comparison.

Returns Vector2I

Component-wise minima.

MinAxisIndexVector2I.Axis
# MinAxisIndex
C#
public Vector2I.Axis MinAxisIndex();

Selects the axis of the smaller signed component, not the smaller magnitude. Returns Axis.Y when X == Y. For example, (-9, 2) yields Axis.X.

Returns Vector2I.Axis

Axis.X when X < Y; otherwise Axis.Y.

SignVector2I
# Sign
C#
public Vector2I 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) stays (1, 1).

Returns Vector2I

Component signs, each -1, 0 or 1.

Snapped2 overloads
# Snapped · 1/2
C#
public Vector2I Snapped(Vector2I 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).Snapped(4) gives (8, -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.

Parameters
NameTypeDefault
stepVector2I—
step

Per-axis or shared step. A positive step is recommended; 0 preserves the corresponding component.

Returns Vector2I

New struct with snapped components; the source is unchanged.

# Snapped · 2/2
C#
public Vector2I 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).Snapped(4) gives (8, -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.

Parameters
NameTypeDefault
stepint—
step

Per-axis or shared step. A positive step is recommended; 0 preserves the corresponding component.

Returns Vector2I

New struct with snapped components; the source is unchanged.

ToString2 overloads
# ToString · 1/2
C#
public override string ToString();

Returns "(X, Y)" using CultureInfo.InvariantCulture regardless of the current culture. Equivalent to ToString(null).

Returns string

Both components as a string in the selected numeric format.

# ToString · 2/2
C#
public string ToString(string? format);

Returns "(X, Y)" using CultureInfo.InvariantCulture regardless of the current culture. Applies format to each int separately: (3, -4) with "D4" yields "(0003, -0004)". Invalid formatting throws FormatException.

Parameters
NameTypeDefault
formatstring—
format

int numeric format applied to both components, such as "D4"; null uses default formatting. An invalid format throws FormatException.

Returns string

Both components as a string in the selected numeric format.

op_AdditionVector2I
# op_Addition
C#
public static Vector2I operator +(Vector2I left, Vector2I right);

Returns (left.X + right.X, left.Y + right.Y) 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.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns Vector2I

Component-wise result; caller variables are unchanged.

op_Division2 overloads
# op_Division · 1/2
C#
public static Vector2I operator /(Vector2I vec, Vector2I divisorv);

Divides each integer component, truncating toward zero: (-7, 7) / 2 gives (-3, 3). A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. Divisors are supplied per axis.

Parameters
NameTypeDefault
vecVector2I—
divisorvVector2I—
vec

Vector operand; a new struct value is returned.

divisorv

Nonzero divisors for the corresponding X and Y components.

Returns Vector2I

Integer quotients for X and Y.

# op_Division · 2/2
C#
public static Vector2I operator /(Vector2I vec, int divisor);

Divides each integer component, truncating toward zero: (-7, 7) / 2 gives (-3, 3). A zero divisor throws DivideByZeroException. A component containing int.MinValue with divisor -1 throws OverflowException in the installed SDK. One divisor applies to both axes.

Parameters
NameTypeDefault
vecVector2I—
divisorint—
vec

Vector operand; a new struct value is returned.

divisor

Shared nonzero divisor for X and Y.

Returns Vector2I

Integer quotients for X and Y.

op_Equalitybool
# op_Equality
C#
public static bool operator ==(Vector2I left, Vector2I right);

Compares both integer components exactly. Does not compare lengths or use approximate tolerance.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true if both X and Y match.

op_ExplicitVector2I
# op_Explicit
C#
public static explicit operator Vector2I(Vector2 value);

Casts Vector2 components to int by truncating fractions toward zero: (-1.9, 1.9) gives (-1, 1), not (-2, 1). For cells with negative coordinates, use Floor first. Check finiteness and int range before casting; do not rely on portable results for NaN, Infinity or out-of-range values.

Parameters
NameTypeDefault
valueVector2—
value

Source vector; precision and range restrictions are described by the conversion.

Returns Vector2I

Integer components truncated toward zero for inputs within the valid range.

op_GreaterThanbool
# op_GreaterThan
C#
public static bool operator >(Vector2I left, Vector2I right);

Lexicographic comparison: X first, then Y when X matches. This is neither a component-wise bounds test nor a length comparison. For example, (1, 100) < (2, -100) is true. For rectangular bounds, compare axes explicitly or use Rect2I.HasPoint.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true when left > right holds in the stated order.

op_GreaterThanOrEqualbool
# op_GreaterThanOrEqual
C#
public static bool operator >=(Vector2I left, Vector2I right);

Lexicographic comparison: X first, then Y when X matches. This is neither a component-wise bounds test nor a length comparison. For example, (1, 100) < (2, -100) is true. For rectangular bounds, compare axes explicitly or use Rect2I.HasPoint.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true when left >= right holds in the stated order.

op_ImplicitVector2
# op_Implicit
C#
public static implicit operator Vector2(Vector2I value);

Converts each int component to the installed SDK’s float Vector2 component. Large integers can lose precision: 16777217 becomes 16777216. Keep Vector2I for exact grid arithmetic until the presentation step.

Parameters
NameTypeDefault
valueVector2I—
value

Source vector; precision and range restrictions are described by the conversion.

Returns Vector2

Vector2 with converted components; large int precision is not guaranteed.

op_Inequalitybool
# op_Inequality
C#
public static bool operator !=(Vector2I left, Vector2I right);

Negates ==. Does not compare lengths or use approximate tolerance.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true if at least one component differs.

op_LessThanbool
# op_LessThan
C#
public static bool operator <(Vector2I left, Vector2I right);

Lexicographic comparison: X first, then Y when X matches. This is neither a component-wise bounds test nor a length comparison. For example, (1, 100) < (2, -100) is true. For rectangular bounds, compare axes explicitly or use Rect2I.HasPoint.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true when left < right holds in the stated order.

op_LessThanOrEqualbool
# op_LessThanOrEqual
C#
public static bool operator <=(Vector2I left, Vector2I right);

Lexicographic comparison: X first, then Y when X matches. This is neither a component-wise bounds test nor a length comparison. For example, (1, 100) < (2, -100) is true. For rectangular bounds, compare axes explicitly or use Rect2I.HasPoint.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns bool

true when left <= right holds in the stated order.

op_Modulus2 overloads
# op_Modulus · 1/2
C#
public static Vector2I operator %(Vector2I vec, Vector2I divisorv);

Computes C# remainders from truncated division: (10, -20) % 7 gives (3, -6). 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.

Parameters
NameTypeDefault
vecVector2I—
divisorvVector2I—
vec

Vector operand; a new struct value is returned.

divisorv

Nonzero divisors for the corresponding X and Y components.

Returns Vector2I

Remainders for X and Y, with the dividend’s sign or zero.

# op_Modulus · 2/2
C#
public static Vector2I operator %(Vector2I vec, int divisor);

Computes C# remainders from truncated division: (10, -20) % 7 gives (3, -6). 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 both axes.

Parameters
NameTypeDefault
vecVector2I—
divisorint—
vec

Vector operand; a new struct value is returned.

divisor

Shared nonzero divisor for X and Y.

Returns Vector2I

Remainders for X and Y, with the dividend’s sign or zero.

op_Multiply3 overloads
# op_Multiply · 1/3
C#
public static Vector2I operator *(Vector2I left, Vector2I right);

Returns (left.X * right.X, left.Y * right.Y) as a new struct. An int scales both 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. Negating int.MinValue leaves int.MinValue.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns Vector2I

Component-wise result; caller variables are unchanged.

# op_Multiply · 2/3
C#
public static Vector2I operator *(Vector2I vec, int scale);

Returns (vec.X * scale, vec.Y * scale) as a new struct. An int scales both 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. Negating int.MinValue leaves int.MinValue.

Parameters
NameTypeDefault
vecVector2I—
scaleint—
vec

Vector operand; a new struct value is returned.

scale

Integer multiplier for both components; each product must fit int.

Returns Vector2I

Component-wise result; caller variables are unchanged.

# op_Multiply · 3/3
C#
public static Vector2I operator *(int scale, Vector2I vec);

Returns (vec.X * scale, vec.Y * scale) as a new struct. An int scales both 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. Negating int.MinValue leaves int.MinValue.

Parameters
NameTypeDefault
scaleint—
vecVector2I—
scale

Integer multiplier for both components; each product must fit int.

vec

Vector operand; a new struct value is returned.

Returns Vector2I

Component-wise result; caller variables are unchanged.

op_SubtractionVector2I
# op_Subtraction
C#
public static Vector2I operator -(Vector2I left, Vector2I right);

Returns (left.X - right.X, left.Y - right.Y) 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.

Parameters
NameTypeDefault
leftVector2I—
rightVector2I—
left

Left vector; the operation does not mutate the caller’s variable.

right

Right vector; the operation does not mutate the caller’s variable.

Returns Vector2I

Component-wise result; caller variables are unchanged.

op_UnaryNegationVector2I
# op_UnaryNegation
C#
public static Vector2I operator -(Vector2I vec);

Returns (-X, -Y) 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.

Parameters
NameTypeDefault
vecVector2I—
vec

Vector operand; a new struct value is returned.

Returns Vector2I

Component-wise result; caller variables are unchanged.

op_UnaryPlusVector2I
# op_UnaryPlus
C#
public static Vector2I operator +(Vector2I vec);

Returns (X, Y) as a new struct. Unary plus leaves the value unchanged.

Parameters
NameTypeDefault
vecVector2I—
vec

Vector operand; a new struct value is returned.

Returns Vector2I

Component-wise result; caller variables are unchanged.

Fields and constants2

XField
# X
C#
public int X;

Mutable signed 32-bit X component, also accessible through [0]. Assignment does not clamp the coordinate or change Y.

YField
# Y
C#
public int Y;

Mutable signed 32-bit Y component, also accessible through [1]. In conventional 2D screen coordinates, positive Y points down.

Vector2I.Axis

ValueDescription
X = 0

Enumerated value for the X axis. Returned by Vector2I.MaxAxisIndex and Vector2I.MinAxisIndex.

Y = 1

Enumerated value for the Y axis. Returned by Vector2I.MaxAxisIndex and Vector2I.MinAxisIndex.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.