VectorView
Hierarchy
- Vector
- VectorView
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
Parameters
options: VectorViewOptions
Returns VectorView
Properties
publicstaticEQUALS_EPSILON
Get or set the vector equals epsilon, by default 0.001 meaning vectors within that tolerance on x or y will be considered equal.
Accessors
publicmagnitude
The magnitude (length) of the Vector
Returns number
Setting the size mutates the current vector
Parameters
newMagnitude: number
Returns void
publicsize
The size (magnitude) of the Vector
Returns number
Setting the size mutates the current vector
Parameters
newLength: number
Returns void
publicx
Get the x component of the vector
Returns number
Set the x component, THIS MUTATES the current vector. It is usually better to create a new vector.
Parameters
val: number
Returns void
publicy
Get the y component of the vector
Returns number
Set the y component, THIS MUTATES the current vector. It is usually better to create a new vector.
Parameters
val: number
Returns void
publicstaticDown
A unit vector pointing down (0, 1)
Returns Vector
publicstaticHalf
A (0.5, 0.5) vector
Returns Vector
publicstaticLeft
A unit vector pointing left (-1, 0)
Returns Vector
publicstaticOne
A (1, 1) vector
Returns Vector
publicstaticRight
A unit vector pointing right (1, 0)
Returns Vector
publicstaticUp
A unit vector pointing up (0, -1)
Returns Vector
publicstaticZero
A (0, 0) vector
Returns Vector
Methods
publicadd
publicaddEqual
publicangleBetween
Returns the difference in radians between the angle of this vector and given angle, using the given rotation type.
Parameters
angle: number
in radians to which the vector has to be rotated, using rotate
rotationType: RotationType
what RotationType to use for the rotation
Returns number
the angle by which the vector needs to be rotated to match the given angle
publicaverage
publicclampMagnitude
Clamps the current vector's magnitude mutating it
Parameters
magnitude: number
Returns Vector
publicclone
publiccross
Performs a 2D cross product with scalar. 2D cross products with a scalar return a vector.
Parameters
v: number
The scalar to cross
Returns Vector
publicdistance
The distance to another vector. If no other Vector is specified, this will return the magnitude.
Parameters
optionalv: Vector
The other vector. Leave blank to use origin vector.
Returns number
publicdot
Performs a dot product with another vector
Parameters
v: Vector
The vector to dot
Returns number
publicequals
Compares this point against another and tests for equality
Parameters
vector: Vector
The other point to compare to
tolerance: number = Vector.EQUALS_EPSILON
Amount of euclidean distance off we are willing to tolerate
Returns boolean
publicnegate
Negate the current vector
Returns Vector
publicnormal
Returns the normal vector to this one, same as the perpendicular of length 1
Returns Vector
publicnormalize
Normalizes a non-zero vector to have a magnitude of 1. Zero vectors return a new zero vector.
Returns Vector
publicperpendicular
Returns the perpendicular vector to this one
Returns Vector
publicrotate
publicscale
publicscaleEqual
Scales this vector by a factor of size and modifies the original
Parameters
size: number
Returns Vector
setTo
Sets the x and y components at once, THIS MUTATES the current vector. It is usually better to create a new vector.
Parameters
x: number
y: number
Returns void
publicsquareDistance
Parameters
optionalv: Vector
Returns number
publicsub
publicsubEqual
publictoAngle
Returns the angle of this vector, in range [0, 2*PI)
Returns number
publictoString
Returns a string representation of the vector.
Parameters
optionalfixed: number
Returns string
staticcross
publicstaticdistance
publicstaticfromAngle
Returns a vector of unit length in the direction of the specified angle in Radians.
Parameters
angle: number
The angle to generate the vector
Returns Vector
publicstaticisValid
Checks if vector is not null, undefined, or if any of its components are NaN or Infinity.
Parameters
vec: Vector
Returns boolean
A 2D vector on a plane.