Class/Object

cwinter.codecraft.util.maths

Vector2

Related Docs: object Vector2 | package maths

Permalink

final case class Vector2(_x: Float, _y: Float) extends Product with Serializable

Immutable 2D Vector.

There are two ways to create vectors: Vector2(x, y) will create a vector with components x and y and Vector2(a) will create a unit vector rotated by an angle of a radians. (In the JavaScript version, create vectors using Game.vector2(x, y).) Addition, subtraction, multiplication and division work as expected:

>> 2 * Vector2(0.5, 0) + Vector2(0, 10) / 10 - Vector2(10, 0)
res0: Vector2 = Vector2(-9, 1)

If you are using Java, you can use the methods plus, times and minus in place of the symbolic operators.

_x

The x coordinate.

_y

The y coordinate.

Annotations
@JSExport()
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Vector2
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Vector2(angle: Double)

    Permalink
  2. new Vector2(_x: Float, _y: Float)

    Permalink

    _x

    The x coordinate.

    _y

    The y coordinate.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def *(rhs: Int): Vector2

    Permalink

    Returns the scalar product of the vector with rhs

    Returns the scalar product of the vector with rhs

    Annotations
    @JSExport()
  4. def *(rhs: Float): Vector2

    Permalink

    Returns the scalar product of the vector with rhs

    Returns the scalar product of the vector with rhs

    Annotations
    @JSExport()
  5. def *(rhs: Double): Vector2

    Permalink

    Returns the scalar product of the vector with rhs

    Returns the scalar product of the vector with rhs

    Annotations
    @JSExport()
  6. def +(rhs: Vector2): Vector2

    Permalink

    Returns the sum of the vector and rhs.

    Returns the sum of the vector and rhs.

    Annotations
    @JSExport()
  7. def -(rhs: Vector2): Vector2

    Permalink

    Returns the difference of the vector and rhs.

    Returns the difference of the vector and rhs.

    Annotations
    @JSExport()
  8. def /(rhs: Double): Vector2

    Permalink

    Returns the vector divided by the scalar rhs

    Returns the vector divided by the scalar rhs

    Annotations
    @JSExport()
  9. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. val _x: Float

    Permalink

    The x coordinate.

  11. val _y: Float

    Permalink

    The y coordinate.

  12. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def dot(rhs: Vector2): Double

    Permalink

    Returns the dot product of the vector with rhs.

    Returns the dot product of the vector with rhs.

    Annotations
    @JSExport()
  15. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  19. def isValid: Boolean

    Permalink

    Returns true if none of the components of the vectors are +-infinity or NaN, otherwise false.

    Returns true if none of the components of the vectors are +-infinity or NaN, otherwise false.

    Annotations
    @JSExport()
  20. def length: Double

    Permalink

    Returns the magnitude of the vector

    Returns the magnitude of the vector

    Annotations
    @JSExport()
  21. def lengthSquared: Float

    Permalink

    Returns the square of the magnitude of the vector

    Returns the square of the magnitude of the vector

    Annotations
    @JSExport()
  22. def minus(rhs: Vector2): Vector2

    Permalink

    Returns the sum of this vector and rhs.

    Returns the sum of this vector and rhs.

    Annotations
    @JSExport()
  23. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. def normalized: Vector2

    Permalink

    Returns a new vector with the same direction and whose magnitude is equal to 1

    Returns a new vector with the same direction and whose magnitude is equal to 1

    Annotations
    @JSExport()
  25. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. def orientation: Float

    Permalink

    Returns the angle in radians of the vector and the x-axis.

    Returns the angle in radians of the vector and the x-axis. This value is always between 0 and 2 * Pi.

    Annotations
    @JSExport()
  28. def plus(rhs: Vector2): Vector2

    Permalink

    Returns the sum of this vector and rhs.

    Returns the sum of this vector and rhs.

    Annotations
    @JSExport()
  29. def rotated(angle: Double): Vector2

    Permalink

    Returns the vector rotated by an angle of angle radians.

    Returns the vector rotated by an angle of angle radians.

    Annotations
    @JSExport()
  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  31. def times(rhs: Double): Vector2

    Permalink

    Returns the scalar product of the vector with rhs

    Returns the scalar product of the vector with rhs

    Annotations
    @JSExport()
  32. def unary_-: Vector2

    Permalink

    Returns the additive inverse of the vector.

    Returns the additive inverse of the vector.

    Annotations
    @JSExport()
  33. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  36. def x: Float

    Permalink

    Returns the x-coordinate

    Returns the x-coordinate

    Annotations
    @JSExport() @inline()
  37. def y: Float

    Permalink

    Returns the y-coordinate

    Returns the y-coordinate

    Annotations
    @JSExport() @inline()

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped