BB.Vector2
A vector in 2 dimensional space. A direct copy of Three.js's THREE.Vector2 class.
Index
Methods
- BB.Vector2 constructor
- add
- addScalar
- addVectors
- ceil
- clamp
- clampScalar
- clone
- copy
- distanceTo
- distanceToSquared
- divide
- divideScalar
- dot
- equals
- floor
- fromArray
- getComponent
- length
- lengthSq
- lerp
- lerpVectors
- max
- min
- multiply
- mutliplyScalar
- negate
- normalize
- round
- roundToZero
- set
- setComponent
- setLength
- setX
- setY
- sub
- subScalar
- subVectors
- toArray
Constructor
BB.Vector2
(
-
x
-
y
)
-
x
-
y
Parameters:
-
x
NumberRepresents the x value of the vector
-
y
NumberRepresents the y value of the vector
Methods
add
(
-
v
)
BB.Vector2
chainable
-
v
Adds vector v to this vector.
Parameters:
-
v
BB.Vector2The vector to add to this vector
Returns: BB.Vector2
this vector.
addScalar
(
-
s
)
BB.Vector2
chainable
-
s
Add the scalar value s to this vector's x and y values.
Parameters:
-
s
NumberScalar to add vector with.
Returns: BB.Vector2
this vector.
addVectors
(
-
a
-
b
)
BB.Vector2
chainable
-
a
-
b
Sets this vector to a + b.
Parameters:
-
a
BB.Vector2The first vector.
-
b
BB.Vector2The second vector.
Returns: BB.Vector2
This vector.
ceil
()
BB.Vector2
chainable
The components of the vector are rounded upwards (towards positive infinity) to an integer value.
Returns: BB.Vector2
This vector.
clamp
(
-
min
-
max
)
BB.Vector2
chainable
-
min
-
max
If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value. If this vector's x or y value is less than the min vector's x or y value, it is replace by the corresponding value. Note: This function assumes min < max, if this assumption isn't true it will not operate correctly
Parameters:
-
min
BB.Vector2The vector containing the min x and y values in the desired range.
-
max
BB.Vector2The vector containing the max x and y values in the desired range.
Returns: BB.Vector2
This vector.
clampScalar
(
-
min
-
max
)
BB.Vector2
chainable
-
min
-
max
If this vector's x or y values are greater than the max value, they are replaced by the max value. If this vector's x or y values are less than the min value, they are replace by the min value.
Parameters:
-
min
Numberthe minimum value the components will be clamped to.
-
max
Numberthe minimum value the components will be clamped to.
Returns: BB.Vector2
This vector.
clone
()
BB.Vector2
Clones this vector.
Returns: BB.Vector2
A new vector with this vectors x and y values.
copy
(
-
v
)
BB.Vector2
chainable
-
v
Copies value of v to this vector. Note: Does not return a copy of this vector.
Parameters:
Returns: BB.Vector2
This vector.
distanceTo
(
-
v
)
Number
-
v
Computes distance of this vector to v.
Parameters:
Returns: Number
Distance from this vector to v.
distanceToSquared
(
-
v
)
Number
-
v
Computes squared distance of this vector to v.
Parameters:
Returns: Number
Squared distance from this vector to v.
divide
(
-
v
)
BB.Vector2
chainable
-
v
Divides this vector by v.
Parameters:
-
v
BB.Vector2The vector to subtract from this vector
Returns: BB.Vector2
this vector.
divideScalar
(
-
s
)
BB.Vector2
-
s
Divides this vector by scalar s.
Parameters:
-
s
NumberThe scalar to divide this vector by.
Returns: BB.Vector2
This vector.
dot
(
-
v
)
Number
-
v
Computes dot product of this vector and v.
Parameters:
Returns: Number
The dot product of this vector and v.
equals
(
-
v
)
Boolean
-
v
Checks for strict equality of this vector and v.
Parameters:
-
v
BB.Vector2The vector to check equality against.
Returns: Boolean
floor
()
BB.Vector2
chainable
The components of the vector are rounded downwards (towards negative infinity) to an integer value.
Returns: BB.Vector2
This vector.
fromArray
(
-
array
)
BB.Vector2
chainable
-
array
Sets this vector's x value to be array[0] and y value to be array[1].
Parameters:
-
array
typeArray of length 2.
Returns: BB.Vector2
This vector.
getComponent
(
-
index
)
Number
-
index
Get this vector's x and y values by index (0 and 1 respectively). If index equals 0 method returns vector's x value. If index equals 1 method returns vector's y value.
Parameters:
-
index
type0 or 1
Returns: Number
Vector's x or y dependent on index
length
()
Number
Computes the length of this vector.
Returns: Number
The length of this vector.
lengthSq
()
Number
Computes squared length of this vector.
Returns: Number
The squared length of this vector.
lerp
(
-
v
-
alpha
)
BB.Vector2
chainable
-
v
-
alpha
Linear interpolation between this vector and v, where alpha is the percent along the line.
Parameters:
-
v
BB.Vector2The vector to lerp this vector with.
-
alpha
NumberPercentage along the line (0 - 1).
Returns: BB.Vector2
This vector.
lerpVectors
(
-
v1
-
v2
-
alpha
)
BB.Vector2
chainable
-
v1
-
v2
-
alpha
Sets this vector to be the vector linearly interpolated between v1 and v2 with alpha factor.
Parameters:
-
v1
BB.Vector2The first vector.
-
v2
BB.Vector2The second vector.
-
alpha
NumberPercentage along the line (0 - 1).
Returns: BB.Vector2
This vector.
max
(
-
v
)
BB.Vector2
chainable
-
v
If this vector's x or y value is less than v's x or y value, replace that value with the corresponding min value.
Parameters:
-
v
BB.Vector2The vector to check and assign max values from
Returns: BB.Vector2
This vector.
min
(
-
v
)
BB.Vector2
chainable
-
v
If this vector's x or y value is less than v's x or y value, replace that value with the corresponding min value.
Parameters:
-
v
BB.Vector2The vector to check and assign min values from
Returns: BB.Vector2
This vector.
multiply
(
-
v
)
BB.Vector2
chainable
-
v
Multiplies this vector by v.
Parameters:
-
v
BB.Vector2The vector to subtract from this vector
Returns: BB.Vector2
this vector.
mutliplyScalar
(
-
s
)
BB.Vector2
-
s
Multiplies this vector by scalar s.
Parameters:
-
s
NumberThe scalar to multiply this vector by.
Returns: BB.Vector2
This vector.
negate
()
BB.Vector2
chainable
Inverts this vector.
Returns: BB.Vector2
this vector.
normalize
()
BB.Vector2
chainable
Normalizes this vector.
Returns: BB.Vector2
This vector.
round
()
BB.Vector2
chainable
The components of the vector are rounded towards the nearest integer value.
Returns: BB.Vector2
This vector.
roundToZero
()
BB.Vector2
chainable
The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
Returns: BB.Vector2
This vector.
set
(
-
x
-
y
)
BB.Vector2
chainable
-
x
-
y
Sets value of this vector.
Parameters:
-
x
NumberRepresents the x value of the vector
-
y
NumberRepresents the y value of the vector
Returns: BB.Vector2
this vector.
setComponent
(
-
index
-
value
)
-
index
-
value
Sets this vector's x and y values by index (0 and 1 respectively). If index equals 0 method replaces this.x with value. If index equals 1 method replaces this.y with value.
Parameters:
-
index
Number0 or 1
-
value
NumberValue to be assigned to corresponding index
setLength
(
-
l
)
BB.Vector2
chainable
-
l
Normalizes this vector and multiplies it by l.
Parameters:
-
l
NumberThe new length of the vector.
Returns: BB.Vector2
This vector.
setX
(
-
x
)
BB.Vector2
chainable
-
x
Replace this vector's x value with x.
Parameters:
-
x
NumberRepresents the x value of the vector.
Returns: BB.Vector2
this vector.
setY
(
-
y
)
BB.Vector2
chainable
-
y
Replace this vector's y value with y.
Parameters:
-
y
NumberRepresents the y value of the vector.
Returns: BB.Vector2
this vector.
sub
(
-
v
)
BB.Vector2
chainable
-
v
Subtracts vector v from this vector.
Parameters:
-
v
BB.Vector2The vector to subtract from this vector
Returns: BB.Vector2
this vector.
subScalar
(
-
s
)
BB.Vector2
chainable
-
s
Subtracts the scalar value s from this vector's x and y values.
Parameters:
-
s
NumberScalar to subract vector by.
Returns: BB.Vector2
this vector.
subVectors
(
-
a
-
b
)
BB.Vector2
chainable
-
a
-
b
Sets this vector to a - b.
Parameters:
-
a
BB.Vector2The first vector.
-
b
BB.Vector2The second vector.
Returns: BB.Vector2
This vector.
toArray
(
-
[array]
)
Array
-
[array]
Returns an array [x, y].
Parameters:
-
[array]
Array optionalOptional array that will be filled if provided.
Returns: Array
Array [x, y].