Each instance of this class represents a direction on a two-dimensional plane. A direction consists of two components: dx and dy, each of which is a number between -1.0 and +1.0 (inclusive). dx indicates the degree to which the x coordinate changes when moving in that direction. dy is the same for the y coordinate. The x coordinate increases rightwards and y downwards.
For example, moving straight rightwards can be thought of as moving in a Direction with a dx of +1.0 and a dy of 0.0. The upward direction has a dx of 0.0 and a dy of -1.0. Diagonals have non-zero values for both dx and dy.
The squares of the dx and dy of any Direction always sum to roughly 1.0, except for the special value NoDirection, which represents the lack of a direction and has zero for both components. A Direction differs from a smile.modeling.Velocity, which combines a direction of movement and a speed.
You don’t instantiate Direction directly. You create Directions with the methods on this class’s companion object. Among other things, you can:
- construct a direction from two differences between coordinates, as in
Direction.fromDeltas(-100, 50), or - create a direction that corresponds to a given angle, as in
Direction.fromDegrees(60)andDirection.fromRadians(-scala.math.Pi / 4).
Some of the methods of a Direction object also create and return new Directions, as does the directionOf method on Pos objects. Moreover, this class’s companion object has a few predefined Direction constants: Up, Down, Left, Right, and NoDirection.
Direction objects are immutable.
Attributes
- Companion
- object
- Source
- Direction.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Returns a direction that is removed from this direction counterclockwise by the number of degrees the given direction represents. Calling dir1 + dir2 is equivalent to calling dir1.counterclockwise(dir2.toDegrees).
Returns a direction that is removed from this direction counterclockwise by the number of degrees the given direction represents. Calling dir1 + dir2 is equivalent to calling dir1.counterclockwise(dir2.toDegrees).
Attributes
- Source
- Direction.scala
Returns a direction that is removed from this direction by the given number of degrees clockwise. For instance, clockwise(90) produces a direction at a right angle to the original.
Returns a direction that is removed from this direction by the given number of degrees clockwise. For instance, clockwise(90) produces a direction at a right angle to the original.
Attributes
- Source
- Direction.scala
Returns a direction that is removed from this direction by the given number of degrees counterclockwise. For instance, counterclockwise(90) produces a direction at a right angle to the original.
Returns a direction that is removed from this direction by the given number of degrees counterclockwise. For instance, counterclockwise(90) produces a direction at a right angle to the original.
Attributes
- Source
- Direction.scala
Returns true if this direction is a clearly downward one (with a dy over zero) or at least non-upward (with a dy of exactly zero). Only returns false if dy is less than zero.
Returns true if this direction is a clearly downward one (with a dy over zero) or at least non-upward (with a dy of exactly zero). Only returns false if dy is less than zero.
Attributes
- Source
- Direction.scala
Returns true if this direction is a clearly leftward one (with a dx under zero) or at least non-rightward (with a dx of exactly zero). Only returns false if dx is over zero.
Returns true if this direction is a clearly leftward one (with a dx under zero) or at least non-rightward (with a dx of exactly zero). Only returns false if dx is over zero.
Attributes
- Source
- Direction.scala
Returns true if this direction is a clearly rightward one (with a dx over zero) or at least non-leftward (with a dx of exactly zero). Only returns false if dx is less than zero.
Returns true if this direction is a clearly rightward one (with a dx over zero) or at least non-leftward (with a dx of exactly zero). Only returns false if dx is less than zero.
Attributes
- Source
- Direction.scala
Returns true if this direction is a clearly upward one (with a dy under zero) or at least non-downward (with a dy of exactly zero). Only returns false if dy is over zero.
Returns true if this direction is a clearly upward one (with a dy under zero) or at least non-downward (with a dy of exactly zero). Only returns false if dy is over zero.
Attributes
- Source
- Direction.scala
Returns a direction that has the opposite dx and the opposite dy as this one.
Returns a direction that has the opposite dx and the opposite dy as this one.
Attributes
- Source
- Direction.scala
Returns a String description of the Direction, such as "dx=1.00,dy=0.00". Uses two decimals for each coordinate.
Returns a String description of the Direction, such as "dx=1.00,dy=0.00". Uses two decimals for each coordinate.
Attributes
- Source
- Direction.scala
Determines whether this direction and the given one point towards the same quarter of the unit circle. That is, determines whether the two directions’ dx have same sign as the other and whether their dys also have the same signs. Zero values count as both positive and negative for this purpose.
Determines whether this direction and the given one point towards the same quarter of the unit circle. That is, determines whether the two directions’ dx have same sign as the other and whether their dys also have the same signs. Zero values count as both positive and negative for this purpose.
Attributes
- Source
- Direction.scala
Returns a direction that has the opposite dx as this one and the same dy.
Returns a direction that has the opposite dx as this one and the same dy.
Attributes
- Source
- Direction.scala
Returns a direction that has the opposite dy as this one and the same dx.
Returns a direction that has the opposite dy as this one and the same dx.
Attributes
- Source
- Direction.scala
Returns this direction as degrees. Zero degrees points rightwards, and the angle grows counterclockwise from there, staying below 360.
Returns this direction as degrees. Zero degrees points rightwards, and the angle grows counterclockwise from there, staying below 360.
Attributes
- Source
- Direction.scala
Returns this direction as radians. Zero radians points rightwards, and the angle grows counterclockwise from there, staying below 2π.
Returns this direction as radians. Zero radians points rightwards, and the angle grows counterclockwise from there, staying below 2π.
Attributes
- Source
- Direction.scala
Returns a String description of the Direction. The exact format varies for different direction objects. The companion's constants print their names, such as Direction.Up, and any other direction prints its components, even one equal to a constant.
Returns a String description of the Direction. The exact format varies for different direction objects. The companion's constants print their names, such as Direction.Up, and any other direction prints its components, even one equal to a constant.
Attributes
- See also
- Definition Classes
-
Any
- Source
- Direction.scala
Inherited methods
An iterator over the names of all the elements of this product.
An iterator over the names of all the elements of this product.
Attributes
- Inherited from:
- Product
- Source
- Product.scala
An iterator over all the elements of this product.
An iterator over all the elements of this product.
Attributes
- Returns
-
in the default implementation, an
Iterator[Any] - Inherited from:
- Product
- Source
- Product.scala
