Vector
Extends:
The Vector class is used for handling vector quantities and for drawing them onto the world.
Constructor Summary
Public Constructor | ||
public |
constructor(opts: object) |
Member Summary
Public Members | ||
public |
Flag for setting the angle style of the vector. |
|
public |
Color of the components. |
|
public |
Flag for enabling the drawing of the vector's components. Default value is false. |
|
public |
Flag for drawing the components at the starting point of the vector. |
|
public |
Label for the vector. |
|
public |
Sets the -x magnitude of the vector. |
|
public |
Sets the -y magnitude of the vector. |
Method Summary
Public Methods | ||
public |
Add a value to the -x and -y components of the vector. |
|
public |
Get the angle of the vector. |
|
public |
Dot product between two vectors. |
|
public |
Get the magnitude of the vector. |
|
public |
magSquared(): number Get the magnitude squared of the vector. |
|
public |
Multiply the -x and -y components of the vector by a constant value. |
|
public |
Get a readable format of the vector's components. |
|
public |
Set the -x and -y components of the vector. |
|
public |
Set the vector's magnitude and angle. |
|
public |
Gets the standard angle of the vector. |
|
public |
Subtract a value to the -x and -y components of the vector. |
Private Methods | ||
private |
draw() Main draw function for the vector called by the World automatically. |
|
private |
Draws a vector between two points. |
|
private |
Tests if the mouse is over the vector. |
Inherited Summary
From class WorldElement | ||
public |
Sets the color in HEX format of the element. |
|
public |
Sets the cursor style when the mouse is over the element. |
|
public |
Flag for enabling or diabling this element. |
|
public |
Flag set when the element is being dragged around. |
|
public |
Sets the font of the element. |
|
public |
Sets the current height of the element. |
|
public |
Flag for allowing the element to be dragged around. |
|
public |
Sets the move style of the element. |
|
public |
Flag set when the mouse is over the element. |
|
public |
Sets a callback function for when the element is dragged around. |
|
public |
Sets the position of the element. |
|
public |
Sets the renderer used for the element. |
|
public |
Sets the rotation of the element. |
|
public |
A copy of the z-index value is stored here. |
|
public |
Sets the drawing scale of the element. |
|
public |
Flag for determining if the element will be a top-most element when dragged around. |
|
public |
Flag used to determine if an object is a child of WorldElement. |
|
public |
Sets the current width of the element. |
|
public |
Sets the world where this element is found. |
|
public |
Sets the z-index of the element. |
|
public |
addPosition(x: number, y: number) Adds the provided coordinates to the position. |
|
public |
Sets if the element is draggable. |
|
public |
Function called when the mouse moves to check if the pointer is over the element. |
|
public |
Sets the color in HEX format of the element. |
|
public |
setPosition(x: number, y: number) Sets the position of the element. |
|
public |
Sets the scale of the element. |
|
public |
Sets the z-index of the element. |
|
private |
resize() Function called when the canvas gets resized. |
|
private |
Sets the world object where element will be drawn. |
|
private |
Sets the element as a topmost element. |
Public Constructors
public constructor(opts: object) source
Override:
WorldElement#constructorParams:
Name | Type | Attribute | Description |
opts | object |
|
Object that contains valid Vector properties with values. Their values will be assigned at the end of the constructor. If an invalid property is passed then the value will be ignored. |
Public Members
public angleStyle: number source
Flag for setting the angle style of the vector. Default value is ANGLE_STYLE.DEG.
public components: boolean source
Flag for enabling the drawing of the vector's components. Default value is false.
Public Methods
public add(x: number | object, y: number) source
Add a value to the -x and -y components of the vector.
public angle(): number source
Get the angle of the vector. The type of angle depends on the value of Vector.angleStyle.
public mult(x: number | object, y: number) source
Multiply the -x and -y components of the vector by a constant value.
public standardAngle(): number source
Gets the standard angle of the vector. This means that the angle ranges from 0 to 360°. Only works when the angleStyle is in degrees.
public sub(x: number | object, y: number) source
Subtract a value to the -x and -y components of the vector.
Private Methods
private drawLine(x0: number, y0: number, x1: number, y1: number, color: string, dashed: boolean): Array source
Draws a vector between two points. The vector is a line with an equilateral triangle at the tip of the vector.
Params:
Name | Type | Attribute | Description |
x0 | number | Start -x coordinate of the vector in pixels. |
|
y0 | number | Start -y coordinate of the vector in pixels. |
|
x1 | number | End -x coordinate of the vector in pixels. |
|
y1 | number | End -y coordinate of the vector in pixels. |
|
color | string | Color of the vector in HEX format. |
|
dashed | boolean | Flag for drawing the vector with a dashed line. |
private isMouseOver(): boolean source
Tests if the mouse is over the vector.