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
Name | Type |
---|---|
vector | Vector |
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
Name | Type |
---|---|
vector | SerializedVector |
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
Name | Type | Default value | Description |
---|---|---|---|
vector | Vector | undefined | The vector to measure. |
threshold | number | 0.01 | Optional. 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
Name | Type | Description |
---|---|---|
referenceVector | Vector | The vector to compare against. |
vectors | readonly 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
Name | Type | Description |
---|---|---|
seedOrRNG | undefined | RNG | Seed | The 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
Name | Type |
---|---|
object | unknown |
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
Name | Type |
---|---|
object | unknown |
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
Name | Type |
---|---|
vector | Vector |
Returns
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
Name | Type |
---|---|
vector1 | Vector |
vector2 | Vector |
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
Name | Type |
---|---|
vector | Vector |
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
Name | Type | Default value | Description |
---|---|---|---|
vector | Vector | undefined | The vector to convert. |
round | boolean | false | Optional. If true, will round the vector values to the nearest integer. Default is false. |
Returns
string