Constructor
new module:Position(x, y)
Position constructor
Name | Type | Default | Description |
---|---|---|---|
x | Number | 0 | Vertical component |
y | Number | 0 | Horizontal component |
Members
angle
Get the angle of a position relative to the horizontal axis
length
Get vector length
Methods
(static) from(positionDefinitionopt) → {Position}
Create a Position from a generic definition or do nothing if already a Position
Name | Type | Attributes | Description |
---|---|---|---|
positionDefinition | PositionDefinition | <optional> | Position definition |
- Type:
- Position
add(definition, yopt) → {Position}
Add another position or number
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Another position or a number | |
y | Number | <optional> | Value for "y" if "position" is a number |
Itself
- Type:
- Position
calc(operation, definition, diffYopt) → {Position}
Apply an operation to this position values
Name | Type | Attributes | Description |
---|---|---|---|
operation | function | Function to apply on value | |
definition | PositionDefinition | | Another position or a number | |
diffY | Number | <optional> | Value to apply on "y" if "definition" is a number |
Itself
- Type:
- Position
clone() → {Position}
Create a copy of this position
New instance
- Type:
- Position
crossProduct(positionDefinition) → {Number}
Cross product
Name | Type | Description |
---|---|---|
positionDefinition | PositionDefinition | Another position |
- Type:
- Number
distance(positionDefinition) → {Number}
Compute distance with another position
Name | Type | Description |
---|---|---|
positionDefinition | PositionDefinition | Any position |
- Type:
- Number
divide(definition, yopt) → {Position}
Divide by another position or number
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Another position or a number | |
y | Number | <optional> | Value for "y" if "position" is a number |
Itself
- Type:
- Position
dotProduct(positionDefinition) → {Number}
Dot product
Name | Type | Description |
---|---|---|
positionDefinition | PositionDefinition | Another position |
- Type:
- Number
isOnSameSide(positionDefinition, vector) → {Boolean}
Define if this is on the same side of a vector as another position
Name | Type | Description |
---|---|---|
positionDefinition | PositionDefinition | Another position |
vector | Vector | Any vector |
- Type:
- Boolean
multiply(definition, yopt) → {Position}
Multiply by another position or number
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Another position or a number | |
y | Number | <optional> | Value for "y" if "position" is a number |
Itself
- Type:
- Position
power(definition, yopt) → {Position}
Raise to a power
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Another position or a number | |
y | Number | <optional> | Value for "y" if "position" is a number |
Itself
- Type:
- Position
rotate(angleopt, originDefinitionopt) → {Position}
Rotate the position around the origin clockwise
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
angle | Number | <optional> | 0 | Angle of rotation in ratio of full circle (0 means no rotation, 1 means go full circle back to same position) |
originDefinition | PositionDefinition | <optional> | Point of origin to rotate around (by default (0, 0)) |
Itself
- Type:
- Position
set(definition, diffYopt) → {Position}
Define this position value
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Horizontal position or another position | |
diffY | Number | <optional> | Vertical position if "definition" is a number |
Itself
- Type:
- Position
subtract(definition, yopt) → {Position}
Subtract another position or number
Name | Type | Attributes | Description |
---|---|---|---|
definition | PositionDefinition | | Another position or a number | |
y | Number | <optional> | Value for "y" if "position" is a number |
Itself
- Type:
- Position
toJSON() → {Array.<Number>}
Return a JSON ready Position definition
- Type:
- Array.<Number>
Type Definitions
AbstractPosition
- Object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | Number | <optional> | 0 | Vertical position |
y | Number | <optional> | 0 | Horizontal position |
PositionDefinition
- Array.<Number> |
AbstractPosition