direction module

Functions for working with directions.

See also

Usage

local direction = require('__flib__.direction')

Functions

opposite(direction) Returns the opposite direction
next(direction[, eight_way=false]) Returns the next direction.
previous(direction[, eight_way=false]) Returns the previous direction.
to_orientation(direction) Returns an orientation from a direction.
to_vector(direction, distance) Returns a vector from a direction.
to_vector_2d(direction, longitudinal, orthogonal) Returns a two-dimensional vector from a cardinal direction.

Fields

north defines.direction.north
east defines.direction.east
west defines.direction.west
south defines.direction.south
northeast defines.direction.northeast
northwest defines.direction.northwest
southeast defines.direction.southeast
southwest defines.direction.southwest

Functions

# opposite(direction)

Returns the opposite direction

Parameters: Returns:
# next(direction[, eight_way=false])

Returns the next direction.

For entities that only support two directions, see opposite.

Parameters:
  • direction : (defines.direction) the starting direction
  • eight_way : (boolean) true to get the next direction in 8-way (note: not many prototypes support 8-way) (default: false)
Returns:
# previous(direction[, eight_way=false])

Returns the previous direction.

For entities that only support two directions, see opposite.

Parameters:
  • direction : (defines.direction) the starting direction
  • eight_way : (boolean) true to get the previous direction in 8-way (note: not many prototypes support 8-way) (default: false)
Returns:
# to_orientation(direction)

Returns an orientation from a direction.

Parameters: Returns:
# to_vector(direction, distance)

Returns a vector from a direction.

Parameters: Returns:
  • (Position)
# to_vector_2d(direction, longitudinal, orthogonal)

Returns a two-dimensional vector from a cardinal direction.

Only supports cardinal (four-way) directions.

Parameters:
  • direction : (defines.direction)
  • longitudinal : (number) Distance to move in the specified direction.
  • orthogonal : (number) Distance to move perpendicular to the specified direction. A negative distance will move “left” and a positive distance will move “right” from the perspective of the direction.
Returns:

Fields

# north

defines.direction.north

# east

defines.direction.east

# west

defines.direction.west

# south

defines.direction.south

# northeast

defines.direction.northeast

# northwest

defines.direction.northwest

# southeast

defines.direction.southeast

# southwest

defines.direction.southwest