Class Vector2

java.lang.Object
io.github.espressoengine.Vector2

public class Vector2 extends Object
Represents a 2D vector.
Version:
$Id: $Id
Author:
pastthepixels
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    double
     
    double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for Vector2.
    Vector2(double x, double y)
    Constructor for Vector2.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double amplitude, double direction)
    Returns a new vector with the current vector's position but moved toward a direction (in radians) by an amplitude.
    add(Vector2 vector)
    Returns a new vector with its position added from both the current vector and parameter vector.
    clamp(double min, double max)
    Returns a new vector with Utils.clamp used on both the x and y values for the vector.
    clamp(Vector2 min, Vector2 max)
    Returns a new vector with Utils.clamp used on both the x and y values for the vector.
    boolean
    equals(Vector2 vector)
    Returns true if two vectors have the same position.
    mult(double factor)
    Returns a new vector whose position is the current vector's multiplied by a factor.
    mult(Vector2 vector)
    Returns a new vector whose position is the current vector's multiplied by parameter vector's position.
    void
    set(double x, double y)
    Sets the position of the vector from two numbers.
    void
    set(Vector2 vector)
    Sets the position of the vector to that of another vector.
    sub(Vector2 vector)
    Returns a new vector with its position being the current vector's subtracted by parameter vector.
    toString.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
    • y

      public double y
  • Constructor Details

    • Vector2

      public Vector2(double x, double y)

      Constructor for Vector2.

      Parameters:
      x - a double
      y - a double
    • Vector2

      public Vector2()

      Constructor for Vector2.

  • Method Details

    • set

      public void set(double x, double y)
      Sets the position of the vector from two numbers.
      Parameters:
      x - a double
      y - a double
    • set

      public void set(Vector2 vector)
      Sets the position of the vector to that of another vector.
      Parameters:
      vector - a Vector2 object
    • add

      public Vector2 add(Vector2 vector)
      Returns a new vector with its position added from both the current vector and parameter vector.
      Parameters:
      vector - a Vector2 object
      Returns:
      a Vector2 object
    • add

      public Vector2 add(double amplitude, double direction)
      Returns a new vector with the current vector's position but moved toward a direction (in radians) by an amplitude. NOTE: Direction is measured in RADIANS. You can just use an object's rotation -- its reference point is the same.
      Parameters:
      amplitude - a double
      direction - a double
      Returns:
      a Vector2 object
    • sub

      public Vector2 sub(Vector2 vector)
      Returns a new vector with its position being the current vector's subtracted by parameter vector.
      Parameters:
      vector - a Vector2 object
      Returns:
      a Vector2 object
    • mult

      public Vector2 mult(Vector2 vector)
      Returns a new vector whose position is the current vector's multiplied by parameter vector's position.
      Parameters:
      vector - a Vector2 object
      Returns:
      a Vector2 object
    • mult

      public Vector2 mult(double factor)
      Returns a new vector whose position is the current vector's multiplied by a factor.
      Parameters:
      factor - a double
      Returns:
      a Vector2 object
    • equals

      public boolean equals(Vector2 vector)
      Returns true if two vectors have the same position.
      Parameters:
      vector - a Vector2 object
      Returns:
      a boolean
    • clamp

      public Vector2 clamp(Vector2 min, Vector2 max)

      Returns a new vector with Utils.clamp used on both the x and y values for the vector.

      Parameters:
      min - a Vector2 object
      max - a Vector2 object
      Returns:
      a Vector2 object
    • clamp

      public Vector2 clamp(double min, double max)

      Returns a new vector with Utils.clamp used on both the x and y values for the vector.

      Parameters:
      min - a double
      max - a double
      Returns:
      a Vector2 object
    • toString

      public String toString()

      toString.

      Overrides:
      toString in class Object
      Returns:
      a String object