object Direction extends Serializable
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._
.
- Alphabetic
- By Inheritance
- Direction
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- val Down: Direction
the “straight downwards” direction with a
dx
of zero, and ady
of +1 - val Left: Direction
the “straight leftwards” direction with a
dx
of -1, and ady
of zero - val NoDirection: Direction { val toString: String }
a “non-direction” whose
dx
anddy
are both zero - val Right: Direction
the “straight rightwards” direction with a
dx
of +1, and ady
of zero - val Up: Direction
the “straight upwards” direction with a
dx
of zero, and ady
of -1 - def fromArrowKey(key: Key): Option[Direction]
Returns the Direction that corresponds to the given arrow key.
- def fromDegrees(angle: Double): Direction
Takes in an angle as degrees and returns the corresponding 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.
- 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.
- 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- returns
the Direction that corresponds to the given deltas. If both are exactly equal to zero, returns NoDirection.
- def fromKey(key: Key): Option[Direction]
Returns the Direction that corresponds to the given arrow key.
- def fromRadians(angle: Double): Direction
Takes in an angle as radians and returns the corresponding 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.
- def fromWASD(key: Key): Option[Direction]
Returns the Direction that corresponds to the given WASD key.
- def random(): Direction
Returns a randomly chosen direction (evenly distributed over 360 degrees).