module:Position

module:Position

Pair of value in 2d space

Constructor

# new module:Position(x, y)

Position constructor

Parameters:
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

Parameters:
Name Type Attributes Description
positionDefinition PositionDefinition <optional>

Position definition

Returns:
Type
Position

# add(definition, yopt) → {Position}

Add another position or number

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Another position or a number

y Number <optional>

Value for "y" if "position" is a number

Returns:

Itself

Type
Position

# calc(operation, definition, diffYopt) → {Position}

Apply an operation to this position values

Parameters:
Name Type Attributes Description
operation function

Function to apply on value

definition PositionDefinition | Number

Another position or a number

diffY Number <optional>

Value to apply on "y" if "definition" is a number

Returns:

Itself

Type
Position

# clone() → {Position}

Create a copy of this position

Returns:

New instance

Type
Position

# crossProduct(positionDefinition) → {Number}

Cross product

Parameters:
Name Type Description
positionDefinition PositionDefinition

Another position

Returns:
Type
Number

# distance(positionDefinition) → {Number}

Compute distance with another position

Parameters:
Name Type Description
positionDefinition PositionDefinition

Any position

Returns:
Type
Number

# divide(definition, yopt) → {Position}

Divide by another position or number

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Another position or a number

y Number <optional>

Value for "y" if "position" is a number

Returns:

Itself

Type
Position

# dotProduct(positionDefinition) → {Number}

Dot product

Parameters:
Name Type Description
positionDefinition PositionDefinition

Another position

Returns:
Type
Number

# isOnSameSide(positionDefinition, vector) → {Boolean}

Define if this is on the same side of a vector as another position

Parameters:
Name Type Description
positionDefinition PositionDefinition

Another position

vector Vector

Any vector

Returns:
Type
Boolean

# multiply(definition, yopt) → {Position}

Multiply by another position or number

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Another position or a number

y Number <optional>

Value for "y" if "position" is a number

Returns:

Itself

Type
Position

# power(definition, yopt) → {Position}

Raise to a power

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Another position or a number

y Number <optional>

Value for "y" if "position" is a number

Returns:

Itself

Type
Position

# rotate(angleopt, originDefinitionopt) → {Position}

Rotate the position around the origin clockwise

Parameters:
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))

Returns:

Itself

Type
Position

# set(definition, diffYopt) → {Position}

Define this position value

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Horizontal position or another position

diffY Number <optional>

Vertical position if "definition" is a number

Returns:

Itself

Type
Position

# subtract(definition, yopt) → {Position}

Subtract another position or number

Parameters:
Name Type Attributes Description
definition PositionDefinition | Number

Another position or a number

y Number <optional>

Value for "y" if "position" is a number

Returns:

Itself

Type
Position

# toJSON() → {Array.<Number>}

Return a JSON ready Position definition

Returns:
Type
Array.<Number>

Type Definitions

# AbstractPosition

Type:
  • Object
Properties
Name Type Attributes Default Description
x Number <optional>
0

Vertical position

y Number <optional>
0

Horizontal position

# PositionDefinition

Type:
  • Array.<Number> | AbstractPosition