new Vector2( [x] [, y])
Creates a 2 dimensional vector.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
x |
olympe.df.PONumber | number | olympe.df.Node |
<optional> |
The value for the 'x' coordinate. |
y |
olympe.df.PONumber | number | olympe.df.Node |
<optional> |
The value for the 'y' coordinate. |
Methods
-
addScalar(scalar)
-
Adds a scalar to both coordinates (x,y) of the vector and returns the resulting
Vector2
.Parameters:
Name Type Description scalar
olympe.df.PONumber | number | olympe.df.Node the scalar to add
Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
addScalars(scalarX, scalarY)
-
Adds two scalars to coordinates x and y of the vector and returns the resulting
Vector2
.Parameters:
Name Type Description scalarX
olympe.df.PONumber | number | olympe.df.Node the scalar to add to X
scalarY
olympe.df.PONumber | number | olympe.df.Node the scalar to add to Y
Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
ceil()
-
Constructs a
Vector2
by applying ceil() to the coordinates of this vector.Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
divideScalar(scalar)
-
Divides this
Vector2
by a scalar and returns the resultingVector2
.Parameters:
Name Type Description scalar
olympe.df.PONumber | number | olympe.df.Node the scalar to divide the
Vector2
byReturns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
dot(otherVect)
-
Returns the dot product of this vector with another vector.
Parameters:
Name Type Description otherVect
olympe.df.PVector2 | olympe.df.Node Returns:
The dot product
- Type
- olympe.df.PONumber
-
equals(obj)
-
Checks whether this Vector2 is the same as another Object.
Parameters:
Name Type Description obj
* Object to be compared.
Returns:
true
if this Vector2 andobj
are the same.- Type
- boolean
-
floor()
-
Constructs a
Vector2
by applying floor() to the coordinates of this vector.Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
getSmallestAmongXY()
-
Gets the smallest of the two coordinates for that vector.
Returns:
the smallest value between 'x' and 'y'
- Type
- olympe.df.PONumber
-
getX()
-
Gets the
x
coordinate of this vector.Returns:
The
x
coordinate.- Type
- olympe.df.PONumber
-
getY()
-
Gets the
y
coordinate of this vector.Returns:
The
y
coordinate.- Type
- olympe.df.ONumber | olympe.df.Proxy
-
length()
-
Calculates the length of this vector, which is sqrt(x^2 + y^2).
Returns:
the length of this vector
- Type
- olympe.df.PONumber
-
minus(otherVect)
-
Returns the result of the subtraction of another vector from this vector.
Parameters:
Name Type Description otherVect
olympe.df.PVector2 | olympe.df.Node the vector to subtract from this vector
Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
multiplyScalar(scalar)
-
Multiplies this
Vector2
by a scalar and returns the resultingVector2
.Parameters:
Name Type Description scalar
olympe.df.PONumber | number | olympe.df.Node the scalar to multiply the
Vector2
byReturns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
negate()
-
Returns the inverse of this vector, i.e. (-x, -y).
Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
normalize()
-
Constructs a normalized instance of this vector.
Returns:
the normalized
Vector2
- Type
- olympe.df.PVector2
-
plus(otherVect)
-
Returns the result of this addition of this Vector with another vector.
Parameters:
Name Type Description otherVect
olympe.df.PVector2 | olympe.df.Node the
Vector2
to add to this vectorReturns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
round()
-
Constructs a
Vector2
by applying round() to the coordinates of this vector.Returns:
the resulting
Vector2
- Type
- olympe.df.PVector2
-
setX(x)
-
Sets the 'x' coordinate of this vector.
Parameters:
Name Type Description x
olympe.df.PONumber | number | olympe.df.Node The value to apply to the
x
coordinate. -
setY(y)
-
Sets the
y
coordinate of this vector.Parameters:
Name Type Description y
olympe.df.PONumber | number | olympe.df.Node the value to apply to the
y
coordinate. -
toJSON()
-
Converts this
Vector2
into a JSON string.Returns:
- Type
- string
-
toOString()
-
Construct a string representation of this
Vector2
and returns it as an OString. Will be in the form "Vector2[x, y]".Returns:
the string representation.
- Type
- olympe.df.POString
-
toString()
-
Construct a string representation of this
Vector2
and returns it as s string. Will be in the form "Vector2[x, y]".Returns:
the string representation
- Type
- string
-
<static> fromJSON(json)
-
Deserializes an
Vector2
from a JSON object or string.Parameters:
Name Type Description json
string | Object Returns:
- Type
- olympe.df.Vector2