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 toplevel package o1, so it’s accessible to students simply via import o1.*
.
Attributes
Members list
Type members
Inherited types
The names of the product elements
The name of the type
Value members
Concrete methods
Returns the Direction that corresponds to the given arrow key. For example, the right arrow corresponds to Right
.
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
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
anddy
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
anddy
of the resulting Direction object
Attributes
 Returns

the Direction that corresponds to the given deltas. If both are exactly equal to zero, returns NoDirection.
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
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
Returns the Direction that corresponds to the given WASD key. For example, the D key corresponds to East
.
Concrete fields
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
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
a “nondirection” whose dx
and dy
are both zero
a “nondirection” whose dx
and dy
are both zero
Attributes
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