Table of Contents

Struct IntVector2

Namespace
PAC.Geometry

A 2-dimensional vector with integer coordinates.

public readonly struct IntVector2 : IEquatable<IntVector2>
Implements
Inherited Members
Extension Methods

Remarks

Can be implicitly cast to/from (int x, int y). This allows writing IntVector2s in a more readable way. For example,

IntVector2 point = (5, 3);

instead of

IntVector2 point = new IntVector2(5, 3);

Constructors

IntVector2(int, int)

Creates a new vector with the given x and y coordinates.

public IntVector2(int x, int y)

Parameters

x int
y int

Fields

down

The vector (0, -1).

public static readonly IntVector2 down

Field Value

IntVector2
See Also

downLeft

The vector (-1, -1).

public static readonly IntVector2 downLeft

Field Value

IntVector2
See Also

downRight

The vector (1, -1).

public static readonly IntVector2 downRight

Field Value

IntVector2
See Also

left

The vector (-1, 0).

public static readonly IntVector2 left

Field Value

IntVector2
See Also

one

The vector (1, 1).

public static readonly IntVector2 one

Field Value

IntVector2

Remarks

An alias for upRight.

right

The vector (1, 0).

public static readonly IntVector2 right

Field Value

IntVector2
See Also

up

The vector (0, 1).

public static readonly IntVector2 up

Field Value

IntVector2
See Also

upDownLeftRight

An IEnumerable<T> over the vectors (0, 1), (0, -1), (-1, 0), (1, 0).

public static readonly IEnumerable<IntVector2> upDownLeftRight

Field Value

IEnumerable<IntVector2>
See Also

upLeft

The vector (-1, 1).

public static readonly IntVector2 upLeft

Field Value

IntVector2
See Also

upRight

The vector (1, 1).

public static readonly IntVector2 upRight

Field Value

IntVector2

Remarks

An alias for one.

See Also

x

The x coordinate.

public readonly int x

Field Value

int
See Also

y

The y coordinate.

public readonly int y

Field Value

int
See Also

zero

The vector (0, 0).

public static readonly IntVector2 zero

Field Value

IntVector2

Properties

l1Norm

The l1 norm of the vector, which is abs(x) + abs(y). Also known as the taxicab/Manhattan norm.

public int l1Norm { get; }

Property Value

int
See Also

magnitude

The standard Euclidean magnitude of the vector, which is sqrt(x^2 + y^2).

public float magnitude { get; }

Property Value

float
See Also

sign

The sign of each component of the vector.

public IntVector2 sign { get; }

Property Value

IntVector2

Remarks

The sign of a component that is 0 is defined to be 0.

See Also

sqrMagnitude

The square of the Euclidean magnitude of the vector, so x^2 + y^2.

public int sqrMagnitude { get; }

Property Value

int

Remarks

This is faster than squaring magnitude.

See Also

supNorm

The supremum norm of the vector, which is max(abs(x), abs(y)). Also known as the Chebyshev norm or l-infinity norm.

public int supNorm { get; }

Property Value

int
See Also

Methods

Abs(IntVector2)

Takes the absolute value component-wise.

public static IntVector2 Abs(IntVector2 a)

Parameters

a IntVector2

Returns

IntVector2

AreColinear(IntVector2, IntVector2)

Returns whether the two vectors lie on the same real line through (0, 0). This is equivalent to whether there is an IntVector2 dividing both of them.

public static bool AreColinear(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

Remarks

For a proof that the two statements given in the summary are logically equivalent, see the source code for this method.

See Also

ArePerpendicular(IntVector2, IntVector2)

Determines whether the two vectors are perpendicular to each other.

public static bool ArePerpendicular(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

Remarks

Being perpendicular is also known as being orthogonal.

See Also

CeilToIntVector2(Vector2)

Ceils the vector component-wise.

public static IntVector2 CeilToIntVector2(Vector2 vector2)

Parameters

vector2 Vector2

Returns

IntVector2

Remarks

Uses Mathf.CeilToInt(float).

See Also

Deconstruct(out int, out int)

Deconstructs the vector into its x and y coordinates.

public void Deconstruct(out int x, out int y)

Parameters

x int
y int

Distance(IntVector2, IntVector2)

Computes the standard Euclidean distance between the two vectors - i.e. the Magnitude(IntVector2) of a - b.

public static float Distance(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

float
See Also

Divides(IntVector2)

Returns whether dividend is an integer multiple of this vector.

For example, (1, 2) divides (3, 6) as (3, 6) = 3 * (1, 2).

public bool Divides(IntVector2 dividend)

Parameters

dividend IntVector2

Returns

bool

Remarks

More precisely, this determines whether there exists an integer n such that dividend = n * this. This means, for example, that (0, 3) divides (0, 6), and that everything divides (0, 0).

See Also

Dot(IntVector2, IntVector2)

Computes the dot product of the two vectors.

public static int Dot(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

int

Equals(IntVector2)

public bool Equals(IntVector2 other)

Parameters

other IntVector2

Returns

bool

Equals(object)

The same as Equals(IntVector2)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

Flip(CardinalOrdinalAxis)

Returns the vector flipped across the given axis.

public IntVector2 Flip(CardinalOrdinalAxis axis)

Parameters

axis CardinalOrdinalAxis

Returns

IntVector2

Exceptions

ArgumentNullException

axis is null.

FloorToIntVector2(Vector2)

Floors the vector component-wise.

public static IntVector2 FloorToIntVector2(Vector2 vector2)

Parameters

vector2 Vector2

Returns

IntVector2

Remarks

Uses Mathf.FloorToInt(float).

See Also

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

IsMultipleOf(IntVector2)

Returns whether this vector is an integer multiple of divisor.

For example, (3, 6) is a multiple of (1, 2) as (3, 6) = 3 * (1, 2).

public bool IsMultipleOf(IntVector2 divisor)

Parameters

divisor IntVector2

Returns

bool

Remarks

More precisely, this determines whether there exists an integer n such that this = n * divisor. This means, for example, that (0, 6) is a multiple of (0, 3), and that (0, 0) is a multiple of everything.

See Also

L1Distance(IntVector2, IntVector2)

Computes the l1 distance between the two vectors - i.e. the L1Norm(IntVector2) of a - b. Also known as the taxicab/Manhattan distance or rectilinear distance.

public static int L1Distance(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

int

L1Norm(IntVector2)

The l1 norm of the vector, which is abs(x) + abs(y). Also known as the taxicab/Manhattan norm.

public static int L1Norm(IntVector2 a)

Parameters

a IntVector2

Returns

int
See Also

Magnitude(IntVector2)

The standard Euclidean magnitude of the vector, which is sqrt(x^2 + y^2).

public static float Magnitude(IntVector2 a)

Parameters

a IntVector2

Returns

float
See Also

Max(IntVector2, IntVector2)

Takes the maximum of the two vectors component-wise.

public static IntVector2 Max(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2
See Also

Max(params IntVector2[])

Takes the maximum of the vectors component-wise.

public static IntVector2 Max(params IntVector2[] vectors)

Parameters

vectors IntVector2[]

Returns

IntVector2

Exceptions

ArgumentNullException

vectors is null.

ArgumentException

vectors is empty.

See Also

Max(IEnumerable<IntVector2>)

Takes the maximum of the vectors component-wise.

public static IntVector2 Max(IEnumerable<IntVector2> vectors)

Parameters

vectors IEnumerable<IntVector2>

Returns

IntVector2

Remarks

This is not provided as an IEnumerable<T> extension method since it seems C# will favour using the LINQ Max<TSource>(IEnumerable<TSource>) instead, which causes errors.

Exceptions

ArgumentNullException

vectors is null.

ArgumentException

vectors is empty.

See Also

Min(IntVector2, IntVector2)

Takes the minimum of the two vectors component-wise.

public static IntVector2 Min(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2
See Also

Min(params IntVector2[])

Takes the minmum of the vectors component-wise.

public static IntVector2 Min(params IntVector2[] vectors)

Parameters

vectors IntVector2[]

Returns

IntVector2

Exceptions

ArgumentNullException

vectors is null.

ArgumentException

vectors is empty.

See Also

Min(IEnumerable<IntVector2>)

Takes the minmum of the vectors component-wise.

public static IntVector2 Min(IEnumerable<IntVector2> vectors)

Parameters

vectors IEnumerable<IntVector2>

Returns

IntVector2

Remarks

This is not provided as an IEnumerable<T> extension method since it seems C# will favour using the LINQ Min<TSource>(IEnumerable<TSource>) instead, which causes errors.

Exceptions

ArgumentNullException

vectors is null.

ArgumentException

vectors is empty.

See Also

Rotate(QuadrantalAngle)

Returns the vector rotated by the given angle.

public IntVector2 Rotate(QuadrantalAngle angle)

Parameters

angle QuadrantalAngle

Returns

IntVector2

RoundToIntVector2(Vector2)

Rounds the vector component-wise.

public static IntVector2 RoundToIntVector2(Vector2 vector2)

Parameters

vector2 Vector2

Returns

IntVector2

Remarks

Uses Mathf.RoundToInt(float).

See Also

Sign(IntVector2)

Returns the sign of each component of the vector.

public static IntVector2 Sign(IntVector2 a)

Parameters

a IntVector2

Returns

IntVector2

Remarks

The sign of a component that is 0 is defined to be 0.

See Also

Simplify(IntVector2)

Scales the vector down so its components are coprime (have no common divisors). In other words, it computes the smallest IntVector2 dividing a.

public static IntVector2 Simplify(IntVector2 a)

Parameters

a IntVector2

Returns

IntVector2

Remarks

Preserves signs.

SqrDistance(IntVector2, IntVector2)

Computes the square of the Euclidean distance between the two vectors - i.e. the SqrMagnitude(IntVector2) of a - b.

public static int SqrDistance(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

int

Remarks

This is faster than squaring Distance(IntVector2, IntVector2).

SqrMagnitude(IntVector2)

The square of the Euclidean magnitude of the vector, so x^2 + y^2.

public static int SqrMagnitude(IntVector2 a)

Parameters

a IntVector2

Returns

int

Remarks

This is faster than squaring Magnitude(IntVector2).

See Also

SupDistance(IntVector2, IntVector2)

Computes the supremum distance between the two vectors - i.e. the SupNorm(IntVector2) of a - b. Also known as the Chebyshev distance or l-infinity distance.

public static int SupDistance(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

int

SupNorm(IntVector2)

The supremum norm of the vector, which is max(abs(x), abs(y)). Also known as the Chebyshev norm or l-infinity norm.

public static int SupNorm(IntVector2 a)

Parameters

a IntVector2

Returns

int
See Also

ToString()

Represents the vector as a string in the form "(x, y)".

public override string ToString()

Returns

string

Operators

operator +(IntVector2, IntVector2)

Adds the two vectors component-wise.

public static IntVector2 operator +(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2

operator /(IntVector2, IntVector2)

Divides (integer division) the two vectors component-wise.

public static IntVector2 operator /(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2

operator /(IntVector2, int)

Divides (integer division) each component of the vector by scalar.

public static IntVector2 operator /(IntVector2 vector, int scalar)

Parameters

vector IntVector2
scalar int

Returns

IntVector2

operator ==(IntVector2, IntVector2)

Whether the two vectors have identical x and y coords.

public static bool operator ==(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool
See Also

explicit operator IntVector2(Vector2)

Casts from Unity's Vector2, by casting each coordinate to int, which truncates them towards zero.

public static explicit operator IntVector2(Vector2 vector)

Parameters

vector Vector2

Returns

IntVector2

explicit operator IntVector2(Vector3)

Casts from Unity's Vector3, by casting each coordinate to int, which truncates them towards zero. The z coordinate is ignored.

public static explicit operator IntVector2(Vector3 vector)

Parameters

vector Vector3

Returns

IntVector2

operator >(IntVector2, IntVector2)

Returns true iff > holds for both components.

public static bool operator >(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

operator >=(IntVector2, IntVector2)

Returns true iff >= holds for both components.

public static bool operator >=(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

implicit operator (int x, int y)(IntVector2)

public static implicit operator (int x, int y)(IntVector2 vector)

Parameters

vector IntVector2

Returns

(int x, int y)

Remarks

This conversion should be inlined by the JIT compiler.

implicit operator Vector2(IntVector2)

Casts to Unity's Vector2, by casting each coordinate to float.

public static implicit operator Vector2(IntVector2 vector)

Parameters

vector IntVector2

Returns

Vector2

implicit operator Vector2Int(IntVector2)

Casts to Unity's Vector2Int.

public static implicit operator Vector2Int(IntVector2 vector)

Parameters

vector IntVector2

Returns

Vector2Int

implicit operator Vector3(IntVector2)

Casts to Unity's Vector3, by casting each coordinate to float, with a 0 in the z-coord.

public static implicit operator Vector3(IntVector2 vector)

Parameters

vector IntVector2

Returns

Vector3

implicit operator IntVector2((int x, int y))

Allows writing IntVector2s in a more readable way

For example,
IntVector2 point = (5, 3);
instead of
IntVector2 point = new IntVector2(5, 3);
public static implicit operator IntVector2((int x, int y) tuple)

Parameters

tuple (int x, int y)

Returns

IntVector2

Remarks

This conversion should be inlined by the JIT compiler.

implicit operator IntVector2(Vector2Int)

Casts from Unity's Vector2Int.

public static implicit operator IntVector2(Vector2Int vector)

Parameters

vector Vector2Int

Returns

IntVector2

operator !=(IntVector2, IntVector2)

Whether the two vectors differ in their x and/or y coords.

public static bool operator !=(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool
See Also

operator <(IntVector2, IntVector2)

Returns true iff < holds for both components.

public static bool operator <(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

operator <=(IntVector2, IntVector2)

Returns true iff <= holds for both components.

public static bool operator <=(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

bool

operator *(IntVector2, IntVector2)

Multiplies the two vectors component-wise.

public static IntVector2 operator *(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2

operator *(IntVector2, int)

Multiplies each component of the vector by scalar.

public static IntVector2 operator *(IntVector2 vector, int scalar)

Parameters

vector IntVector2
scalar int

Returns

IntVector2

operator *(int, IntVector2)

Multiplies each component of the vector by scalar.

public static IntVector2 operator *(int scalar, IntVector2 vector)

Parameters

scalar int
vector IntVector2

Returns

IntVector2

operator -(IntVector2, IntVector2)

Subtracts the two vectors component-wise.

public static IntVector2 operator -(IntVector2 a, IntVector2 b)

Parameters

a IntVector2
b IntVector2

Returns

IntVector2

operator -(IntVector2)

Negates each component of the vector.

public static IntVector2 operator -(IntVector2 a)

Parameters

a IntVector2

Returns

IntVector2