Skip to main content

Vector

Type Aliases

SerializedVector

Ƭ SerializedVector: LuaMap<string, unknown> & { __serializedVectorBrand: symbol ; __kind: CopyableIsaacAPIClassType.VECTOR }

Defined in

packages/isaacscript-common/src/functions/vector.ts:18

Functions

copyVector

copyVector(vector): Vector

Helper function to copy a Vector Isaac API class.

Parameters

NameType
vectorVector

Returns

Vector

Defined in

packages/isaacscript-common/src/functions/vector.ts:27


deserializeVector

deserializeVector(vector): Vector

Helper function to convert a SerializedVector object to a normal RNG object. (This is used by the save data manager when reading data from the "save#.dat" file.)

Parameters

NameType
vectorSerializedVector

Returns

Vector

Defined in

packages/isaacscript-common/src/functions/vector.ts:41


doesVectorHaveLength

doesVectorHaveLength(vector, threshold?): boolean

Helper function to measure a vector to see if it has a non-zero length using a threshold to ignore extremely small values.

Use this function instead of explicitly checking if the length is 0 because vectors in the game are unlikely to ever be exactly set to 0. Instead, they will always have some miniscule length.

Parameters

NameTypeDefault valueDescription
vectorVectorundefinedThe vector to measure.
thresholdnumber0.01Optional. The threshold from 0 to consider to be a non-zero vector. Default is 0.01.

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/vector.ts:73


getClosestVectorTo

getClosestVectorTo(referenceVector, vectors): Vector | undefined

Given an array of vectors, this helper function returns the closest one to a provided reference vector.

Parameters

NameTypeDescription
referenceVectorVectorThe vector to compare against.
vectorsreadonly Vector[]The array of vectors to look through.

Returns

Vector | undefined

Defined in

packages/isaacscript-common/src/functions/vector.ts:87


getRandomVector

getRandomVector(seedOrRNG): Readonly<Vector>

Helper function to get a random vector between (-1, -1) and (1, 1).

To get random vectors with a bigger length, multiply this with a number.

Use this over the RandomVector function when you need the vector to be seeded.

If you want to generate an unseeded vector, you must explicitly pass undefined to the seedOrRNG parameter.

Parameters

NameTypeDescription
seedOrRNGundefined | RNG | SeedThe Seed or RNG object to use. If an RNG object is provided, the RNG.Next method will be called. If undefined is provided, it will default to a random seed.

Returns

Readonly<Vector>

Defined in

packages/isaacscript-common/src/functions/vector.ts:119


isSerializedVector

isSerializedVector(object): object is SerializedVector

Used to determine is the given table is a serialized Vector object created by the deepCopy function.

Parameters

NameType
objectunknown

Returns

object is SerializedVector

Defined in

packages/isaacscript-common/src/functions/vector.ts:134


isVector

isVector(object): object is Vector

Helper function to check if something is an instantiated Vector object.

Parameters

NameType
objectunknown

Returns

object is Vector

Defined in

packages/isaacscript-common/src/functions/vector.ts:145


serializeVector

serializeVector(vector): SerializedVector

Helper function to convert a Vector object to a SerializedVector object. (This is used by the save data manager when writing data from the "save#.dat" file.)

Parameters

NameType
vectorVector

Returns

SerializedVector

Defined in

packages/isaacscript-common/src/functions/vector.ts:153


vectorEquals

vectorEquals(vector1, vector2): boolean

Helper function to compare two vectors for equality.

This function is useful because vectors are not directly comparable. In other words, Vector(1.2) === Vector(1.2) will be equal to false.

Parameters

NameType
vector1Vector
vector2Vector

Returns

boolean

Defined in

packages/isaacscript-common/src/functions/vector.ts:172


vectorToDirection

vectorToDirection(vector): Direction

Helper function for finding out which way a vector is pointing.

Parameters

NameType
vectorVector

Returns

Direction

Defined in

packages/isaacscript-common/src/functions/vector.ts:177


vectorToString

vectorToString(vector, round?): string

Helper function to convert a vector to a string.

Parameters

NameTypeDefault valueDescription
vectorVectorundefinedThe vector to convert.
roundbooleanfalseOptional. If true, will round the vector values to the nearest integer. Default is false.

Returns

string

Defined in

packages/isaacscript-common/src/functions/vector.ts:189