illuminated.Vec2 Class
Vec2 represents a 2d position or a 2d vector. It is used everywhere in Illuminated.js.
Vec2 is based on Box2d’s Vec2 except that in Illuminated.js a Vec2 vector is immutable. It means every method creates a new Vec2 instance and you can safely use a same Vec2 instance everywhere because the immutability guarantees that properties will not be modified.
Constructor
illuminated.Vec2
-
[x=0]
-
[y=0]
Parameters:
-
[x=0]
Number optionalX coordinate for the vector.
-
[y=0]
Number optionalY coordinate for the vector.
Methods
add
-
v
Adds the given vector to this vector.
Parameters:
-
v
illuminated.Vec2A vector to add to this vector.
Returns:
copy
()
illuminated.Vec2
Returns a copy of this vector.
Returns:
dist2
-
v
Calculates the squared distance between this vector and the given vector.
Parameters:
-
v
illuminated.Vec2A vector with which the squared distance is calculated.
Returns:
dot
-
v
Calculates the dot product of this vector and the given vector.
Parameters:
-
v
illuminated.Vec2A vector with which to calculate the dot product.
Returns:
inBound
-
topleft
-
bottomright
Determines if this vector is within the bounds defined by the given vectors.
Parameters:
-
topleft
illuminated.Vec2A vector that is the top-left of the bounds.
-
bottomright
illuminated.Vec2A vector that is the bottom-right of the bounds.
Returns:
inv
()
illuminated.Vec2
Returns the inverse of this vector.
Returns:
length2
()
Number
Calculates the squared length of this vector.
Returns:
mul
-
v
Multiplies the given vector with this vector.
Parameters:
-
v
illuminated.Vec2A vector to multiply with this vector.
Returns:
normalize
()
illuminated.Vec2
Calculates the normalized form of this vector.
Returns:
sub
-
v
Subtracts the given vector from this vector.
Parameters:
-
v
illuminated.Vec2A vector to subtract from this vector.
Returns:
toString
()
String
Returns a string representing this vector.
Returns:
Properties
x
Number
X coordinate for the vector.
Default: 0
y
Number
Y coordinate for the vector.
Default: 0