O1Library Docs
Fall 2023
Docs API

# Direction

o1.world.Direction$
See the Direction companion class
object Direction

This companion object of class `Direction` provides some constants of type `Direction` and methods for creating new `Direction` instances.

The object has an alias in the top-level package o1, so it’s accessible to students simply via `import o1.*`.

## Attributes

Companion
  class
Graph
Supertypes
  trait Product
  trait Mirror
  class Object
  trait Matchable
  class Any
Self type
  Direction.type

## Members list

### Type members

#### Inherited types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

## Attributes

Inherited from:
  Mirror

type MirroredLabel <: String

The name of the type

The name of the type

## Attributes

Inherited from:
  Mirror

### Value members

#### Concrete methods

def fromArrowKey(key: Value): Option[Direction]

Returns the Direction that corresponds to the given arrow key. For example, the right arrow corresponds to `Right`.

Returns the Direction that corresponds to the given arrow key. For example, the right arrow corresponds to `Right`.

## Parameters

key

  any key on the keyboard

## Attributes

Returns

  one of Up, Down, Left, Right; `None` if the given key was not one of the four arrow keys

See also

  fromWASD, fromKey

def fromDegrees(angle: Double): Direction

Takes in an angle as degrees and returns the corresponding Direction. Zero degrees points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Takes in an angle as degrees and returns the corresponding Direction. Zero degrees points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

## Attributes

def fromDeltas(dx: Double, dy: Double): Direction

Takes in a difference between x coordinates and a difference between y coordinates and constructs a Direction from them.

Takes in a difference between x coordinates and a difference between y coordinates and constructs a Direction from them.

## Parameters

dx

  a difference between two x coordinates; it is not necessary that this is normalized between -1.0 and +1.0 like the `dx` and `dy` of the resulting Direction object

dy

  a difference between two x coordinates; it is not necessary that this is normalized between -1.0 and +1.0 like the `dx` and `dy` of the resulting Direction object

## Attributes

Returns

  the Direction that corresponds to the given deltas. If both are exactly equal to zero, returns NoDirection.

def fromKey(key: Value): Option[Direction]

Returns the Direction that corresponds to the given arrow key. For example, the right arrow or the D key corresponds to `East`.

Returns the Direction that corresponds to the given arrow key. For example, the right arrow or the D key corresponds to `East`.

## Parameters

key

  any key on the keyboard

## Attributes

Returns

  one of Up, Down, Left, Right; `None` if the given key was not one of the four arrow keys or one of the four WASD keys

See also

  fromArrowKey, fromWASD

def fromRadians(angle: Double): Direction

Takes in an angle as radians and returns the corresponding Direction. Zero radians points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

Takes in an angle as radians and returns the corresponding Direction. Zero radians points rightwards; positive angles are counterclockwise from there, negative ones clockwise.

## Attributes

def fromWASD(key: Value): Option[Direction]

Returns the Direction that corresponds to the given WASD key. For example, the D key corresponds to `East`.

Returns the Direction that corresponds to the given WASD key. For example, the D key corresponds to `East`.

## Parameters

key

  any key on the keyboard

## Attributes

Returns

  one of Up, Down, Left, Right; `None` if the given key was not one of the four WASD keys

See also

  fromArrowKey, fromKey

def random(): Direction

Returns a randomly chosen direction (evenly distributed over 360 degrees).

Returns a randomly chosen direction (evenly distributed over 360 degrees).

## Attributes

#### Concrete fields

val Down: Direction

the “straight downwards” direction with a `dx` of zero, and a `dy` of +1

the “straight downwards” direction with a `dx` of zero, and a `dy` of +1

## Attributes

val Left: Direction

the “straight leftwards” direction with a `dx` of -1, and a `dy` of zero

the “straight leftwards” direction with a `dx` of -1, and a `dy` of zero

## Attributes

val NoDirection: Direction

a “non-direction” whose `dx` and `dy` are both zero

a “non-direction” whose `dx` and `dy` are both zero

## Attributes

val Right: Direction

the “straight rightwards” direction with a `dx` of +1, and a `dy` of zero

the “straight rightwards” direction with a `dx` of +1, and a `dy` of zero

## Attributes

val Up: Direction

the “straight upwards” direction with a `dx` of zero, and a `dy` of -1

the “straight upwards” direction with a `dx` of zero, and a `dy` of -1

## Attributes

### Givens

given derived$CanEqual: CanEqual[Direction, Direction]