Class Vector2D

java.lang.Object
com.xebisco.yield.Vector2D
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ImmutableVector2D

public class Vector2D extends Object implements Serializable
Represents a 2D vector, points and sizes.
See Also:
  • Constructor Details

    • Vector2D

      public Vector2D(double x, double y)
      Constructs a new Vector2D instance with the specified x and y coordinates.
      Parameters:
      x - the x coordinate of the vector
      y - the y coordinate of the vector
    • Vector2D

      public Vector2D()
      Constructs a new Vector2D instance.
    • Vector2D

      public Vector2D(Vector2D a)
      Constructs a new Vector2D instance with the specified Vector2D object.
      Parameters:
      a - the Vector2D object to copy
  • Method Details

    • set

      public Vector2D set(double x, double y)
      Sets the x and y coordinates of this Vector2D instance.
      Parameters:
      x - the new x coordinate
      y - the new y coordinate
      Returns:
      this Vector2D instance for method chaining
    • reset

      public Vector2D reset()
      Resets this Vector2D instance to the origin (0, 0).
      Returns:
      this Vector2D instance for method chaining
    • set

      public Vector2D set(Vector2D a)
      Sets the coordinates of this Vector2D instance from a given Vector2D object.
      Parameters:
      a - The Vector2D object
      Returns:
      this Vector2D instance for method chaining
    • sumLocal

      public Vector2D sumLocal(Vector2D a)
      Adds the x and y coordinates of given Vector2D object to this Vector2D instance.
      Parameters:
      a - the Vector2D object to add from
      Returns:
      this Vector2D instance for method chaining
    • sum

      public Vector2D sum(Vector2D a)
      Adds the x and y coordinates of the given Vector2D object to a copy of this Vector2D instance.
      Parameters:
      a - the Vector2D object to add
      Returns:
      a new Vector2D instance representing the result of the addition operation
    • subtractLocal

      public Vector2D subtractLocal(Vector2D a)
      Subtracts the x and y coordinates of given Vector2D object to this Vector2D instance.
      Parameters:
      a - the Vector2D object to add from
      Returns:
      this Vector2D instance for method chaining
    • subtract

      public Vector2D subtract(Vector2D a)
      Subtracts the x and y coordinates of the given Vector2D object from a copy of this Vector2D instance.
      Parameters:
      a - the Vector2D object to subtract
      Returns:
      a new Vector2D instance representing the result of the subtraction operation
    • multiplyLocal

      public Vector2D multiplyLocal(Vector2D a)
      Multiply the x and y values of this object by the x and y values of the given object.
      Parameters:
      a - The Vector2D to multiply this Vector2D by.
    • multiplyLocal

      public Vector2D multiplyLocal(double value)
      This method multiplies the x and y values of a Vector2D object by a given value and returns the object.
      Parameters:
      value - The parameter "value" is a double type variable that represents the value by which the x and y coordinates of the Vector2D object are multiplied.
      Returns:
      The method is returning this instance of the `Vector2D`.
    • multiply

      public Vector2D multiply(Vector2D a)
      This method returns the result of multiplying two instances of the Vector2D class.
      Parameters:
      a - The parameter "a" is a Vector2D object that is being passed as an argument to the "multiply" method.
      Returns:
      A new instance of the `Vector2D` class is being returned. The new instance is created by calling the `multiplyLocal` method on the current instance of `Vector2D` with the argument `a`.
    • multiply

      public Vector2D multiply(double value)
    • divideLocal

      public Vector2D divideLocal(Vector2D a)
      Divide the x and y values of this object by the x and y values of the given object.
      Parameters:
      a - The Vector2D to divide by.
    • divideLocal

      public Vector2D divideLocal(double value)
    • divide

      public Vector2D divide(Vector2D a)
      This Java function returns a new Vector2D object that is the result of dividing the current object by the input object.
      Parameters:
      a - The parameter "a" is a Vector2D object that is being passed as an argument to the "divide" method.
      Returns:
      A new instance of the `Vector2D` class is being returned, which is the result of dividing the current instance by the `a` parameter using the `divideLocal` method.
    • divide

      public Vector2D divide(double value)
    • absoluteLocal

      public Vector2D absoluteLocal()
      The function returns the absolute value of the x and y coordinates of a Vector2D object.
      Returns:
      The method is returning this instance of the `Vector2D` class.
    • absolute

      public Vector2D absolute()
      This method returns a new Vector2D object with absolute values of x and y coordinates.
      Returns:
      A new instance of the `Vector2D` class is being returned, which is created using the `x` and `y` values of the current instance. The `absoluteLocal()` method is then called on the new instance to modify its values, but the modified instance is not returned.
    • invertLocal

      public Vector2D invertLocal()
      This function inverts a Vector2D object locally by multiplying it with -1.
      Returns:
      The method is returning this `Vector2D` object.
    • invert

      public Vector2D invert()
      The function inverts a Vector2D object by multiplying it with a new object with negative values.
      Returns:
      The method is returning a new instance of the `Vector2D` class that is the result of multiplying the current instance with a new instance of `Vector2D` that has the values `-1` for both anchors. This new instance is effectively the inverse of the current instance.
    • x

      public double x()
      This function returns the value of the x variable.
      Returns:
      The value of the x variable.
    • setX

      public Vector2D setX(double x)
      This function sets the value of the x variable to the value of the x parameter.
      Parameters:
      x - The x coordinate of the point.
    • y

      public double y()
      This function returns the y coordinate of the point.
      Returns:
      The y coordinate of the point.
    • setY

      public Vector2D setY(double y)
      This function sets the y coordinate of the point to the value of the parameter y.
      Parameters:
      y - The y coordinate of the point.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • vector2D

      public static Vector2D vector2D(int degrees, double intensity)
      The function returns a 2D vector with a given angle in degrees and intensity.
      Parameters:
      degrees - The angle in degrees that the vector makes with the positive x-axis.
      intensity - The intensity parameter represents the magnitude or length of the vector. It determines how long the vector will be.
      Returns:
      A new instance of the Vector2D class with x and y components calculated based on the input degrees and intensity values.
    • angle

      public double angle()
      This Java function calculates the angle in degrees between the positive x-axis and a point represented by its x and y coordinates using the Math.atan2() and Math.toDegrees() methods.
      Returns:
      The method `calculateDegrees()` returns the angle in degrees between the positive x-axis and the vector represented by the point (x,y) in the Cartesian coordinate system. It uses the `Math.atan2()` method to calculate the angle in radians and then converts it to degrees using the `Math.toDegrees()` method.
    • intensity

      public double intensity()
      This Java function calculates the intensity of a vector using the Pythagorean theorem.
      Returns:
      The method `calculateIntensity` is returning the intensity of a vector, which is calculated as the square root of the sum of the squares of its components (x and y).
    • width

      public double width()
    • height

      public double height()