ObservableVector2d
class ObservableVector2d extends Vector2d
A Vector2d object that provide notification by executing the given callback when the vector is changed.
Constructor
new ObservableVector2d(x: number, y: number, settings: object) → {}
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number | 0 |
x value of the vector |
|
y | number | 0 |
y value of the vector |
|
settings | object |
additional required parameters |
||
settings.onUpdate | Function |
the callback to be executed when the vector is changed |
||
settings.scope | Function |
<optional> |
the value to use as this when calling onUpdate |
Summary
Methods from ObservableVector2d
Public Properties
Public Methods
abs() → {ObservableVector2d}
Update this vector values to absolute values
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
add(v: ObservableVector2d) → {ObservableVector2d}
Add the passed vector to this vector
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
ceil() → {ObservableVector2d}
Ceil the vector values
Type | Description |
---|---|
ObservableVector2d |
new me.ObservableVector2d |
ceilSelf() → {ObservableVector2d}
Ceil this vector values
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
clamp(low: number, high: number) → {ObservableVector2d}
Clamp the vector value within the specified value range
Name | Type | Description |
---|---|---|
low | number | |
high | number |
Type | Description |
---|---|
ObservableVector2d |
new me.ObservableVector2d |
clampSelf(low: number, high: number) → {ObservableVector2d}
Clamp this vector value within the specified value range
Name | Type | Description |
---|---|---|
low | number | |
high | number |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
clone() → {ObservableVector2d}
return a clone copy of this vector
Type | Description |
---|---|
ObservableVector2d |
new me.ObservableVector2d |
copy(v: ObservableVector2d) → {ObservableVector2d}
Copy the x,y values of the passed vector to this one
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
cross(v: Vector2d | ObservableVector2d) → {number}
return the cross product of this vector and the passed one
Name | Type | Description |
---|---|---|
v | Vector2d | ObservableVector2d |
Type | Description |
---|---|
number |
The cross product. |
distance(v: ObservableVector2d) → {number}
return the distance between this vector and the passed one
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
number |
div(n: number) → {ObservableVector2d}
Divide this vector values by the passed value
Name | Type | Description |
---|---|---|
n | number |
the value to divide the vector by |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
dot(v: Vector2d | ObservableVector2d) → {number}
return the dot product of this vector and the passed one
Name | Type | Description |
---|---|---|
v | Vector2d | ObservableVector2d |
Type | Description |
---|---|
number |
The dot product. |
equals(v: ObservableVector2d) → {boolean}
return true if the two vectors are the same
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
boolean |
floor() → {ObservableVector2d}
Floor the vector values
Type | Description |
---|---|
ObservableVector2d |
new me.ObservableVector2d |
floorSelf() → {ObservableVector2d}
Floor this vector values
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
lerp(v: Vector2d | ObservableVector2d, alpha: number) → {ObservableVector2d}
Linearly interpolate between this vector and the given one.
Name | Type | Description |
---|---|---|
v | Vector2d | ObservableVector2d | |
alpha | number |
distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one). |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
maxV(v: ObservableVector2d) → {ObservableVector2d}
Update this vector with the maximum value between this and the passed vector
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
minV(v: ObservableVector2d) → {ObservableVector2d}
Update this vector with the minimum value between this and the passed vector
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
moveTowards(target: Vector2d | ObservableVector2d, step: number) → {ObservableVector2d}
interpolate the position of this vector towards the given one while nsure that the distance never exceeds the given step.
Name | Type | Description |
---|---|---|
target | Vector2d | ObservableVector2d | |
step | number |
the maximum step per iteration (Negative values will push the vector away from the target) |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
negate() → {ObservableVector2d}
Negate the vector values
Type | Description |
---|---|
ObservableVector2d |
new me.ObservableVector2d |
negateSelf() → {ObservableVector2d}
Negate this vector values
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
perp() → {ObservableVector2d}
change this vector to be perpendicular to what it was before.
(Effectively rotates it 90 degrees in a clockwise direction)
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
rotate(angle: number, v: Vector2d | ObservableVector2d) → {ObservableVector2d}
Rotate this vector (counter-clockwise) by the specified angle (in radians).
Name | Type | Attributes | Description |
---|---|---|---|
angle | number |
The angle to rotate (in radians) |
|
v | Vector2d | ObservableVector2d |
<optional> |
an optional point to rotate around |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
scale(x: number, y: number) → {ObservableVector2d}
Multiply this vector values by the given scalar
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number | |||
y | number |
<optional> |
x |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
scaleV(v: ObservableVector2d) → {ObservableVector2d}
Multiply this vector values by the passed vector
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
setCallback(fn: Function, scope: Function) → {ObservableVector2d}
set the callback to be executed when the vector is changed
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn | Function |
callback |
||
scope | Function |
<optional> |
null |
scope |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
setMuted(x: number, y: number) → {ObservableVector2d}
set the vector value without triggering the callback
Name | Type | Description |
---|---|---|
x | number |
x value of the vector |
y | number |
y value of the vector |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
sub(v: ObservableVector2d) → {ObservableVector2d}
Substract the passed vector to this vector
Name | Type | Description |
---|---|---|
v | ObservableVector2d |
Type | Description |
---|---|
ObservableVector2d |
Reference to this object for method chaining |
toString() → {string}
convert the object to a string representation
Type | Description |
---|---|
string |
toVector2d() → {Vector2d}
return a me.Vector2d
copy of this me.ObservableVector2d
object
Type | Description |
---|---|
Vector2d |
new me.Vector2d |