Record Class Vector2Dd

java.lang.Object
java.lang.Record
nl.pim16aap2.animatedarchitecture.core.util.vector.Vector2Dd

public record Vector2Dd(double x, double y) extends Record
Represents a double x/y pair.

This class is thread-safe, as all modifications return a new instance.

  • Constructor Details

    • Vector2Dd

      public Vector2Dd(double x, double y)
      Creates an instance of a Vector2Dd record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
  • Method Details

    • toInteger

      @CheckReturnValue @Contract(pure=true) public Vector2Di toInteger()
      Creates a new integer-based 2d vector from this double-based 2d vector.

      The values of the double-based vector will be rounded to obtain the integer values.

      Returns:
      A new integer-based vector.
    • add

      @CheckReturnValue @Contract(pure=true) public Vector2Dd add(double x, double y)
      Adds values to the current values.
      Parameters:
      x - The x value to add to the current x value.
      y - The y value to add to the current y value.
      Returns:
      A new Vector2Dd with the added values.
    • add

      @CheckReturnValue @Contract(pure=true) public Vector2Dd add(Vector2Dd other)
      Adds another Vector2Dd to the current values.
      Parameters:
      other - The other Vector2Dd to add to the current one.
      Returns:
      A new Vector2Dd with the added values.
    • add

      @CheckReturnValue @Contract(pure=true) public Vector2Dd add(Vector2Di other)
      Adds another Vector2Di to the current values.
      Parameters:
      other - The other Vector2Di to add to the current one.
      Returns:
      A new Vector2Dd with the added values.
    • add

      @CheckReturnValue @Contract(pure=true) public Vector2Dd add(double val)
      Adds a value to both the x and the y values of the current Vector2Dd.
      Parameters:
      val - The value to add to both the x and the y values.
      Returns:
      A new Vector2Dd with the value added to the values.
    • subtract

      @CheckReturnValue @Contract(pure=true) public Vector2Dd subtract(double x, double y)
      Subtracts values from the current values.
      Parameters:
      x - The x value to subtract from the current x value.
      y - The y value to subtract from the current y value.
      Returns:
      A new Vector2Dd with the subtracted values.
    • subtract

      @CheckReturnValue @Contract(pure=true) public Vector2Dd subtract(Vector2Dd other)
      Subtracts another Vector2Dd from both the x and the y values of the current Vector2Dd.
      Parameters:
      other - The other Vector2Dd to subtract from the x and the y values.
      Returns:
      The new Vector2Dd with the value subtracted from the values.
    • subtract

      @CheckReturnValue @Contract(pure=true) public Vector2Dd subtract(Vector2Di other)
      Subtracts another Vector2Di from both the x and the y values of the current Vector2Dd.
      Parameters:
      other - The other Vector2Di to subtract from the x and the y values.
      Returns:
      The new Vector2Dd with the value subtracted from the values.
    • subtract

      @CheckReturnValue @Contract(pure=true) public Vector2Dd subtract(double val)
      Subtracts a value from both the x and the y values of the current Vector2Dd.
      Parameters:
      val - The value to subtract from both the x and the y values.
      Returns:
      A new Vector2Dd with the value subtracted from the values.
    • multiply

      @CheckReturnValue @Contract(pure=true) public Vector2Dd multiply(double x, double y)
      Multiplies values with the current values.
      Parameters:
      x - The x value to multiply with the current x value.
      y - The y value to multiply with the current y value.
      Returns:
      A new Vector2Dd with the multiplied values.
    • multiply

      @CheckReturnValue @Contract(pure=true) public Vector2Dd multiply(Vector2Dd other)
      Multiplies another Vector2Dd from with the x and the y values of the current Vector2Dd.
      Parameters:
      other - The other Vector2Dd to multiply with the x and the y values.
      Returns:
      The new Vector2Dd with the value multiplied with the values.
    • multiply

      @CheckReturnValue @Contract(pure=true) public Vector2Dd multiply(Vector2Di other)
      Multiplies another Vector2Di from with the x and the y values of the current Vector2Dd.
      Parameters:
      other - The other Vector2Di to multiply with the x and the y values.
      Returns:
      The new Vector2Dd with the value multiplied with the values.
    • multiply

      @CheckReturnValue @Contract(pure=true) public Vector2Dd multiply(double val)
      Multiplies a value with both the x and the y values of the current Vector2Dd.
      Parameters:
      val - The value to multiply from both the x and the y values.
      Returns:
      A new Vector2Dd with the value multiplied with the values.
    • divide

      @CheckReturnValue @Contract(pure=true) public Vector2Dd divide(double x, double y)
      Divides the current values with values.
      Parameters:
      x - The x value to use as divisor for the current x value.
      y - The y value to use as divisor for the current y value.
      Returns:
      A new Vector2Dd with the divided values.
    • divide

      @CheckReturnValue @Contract(pure=true) public Vector2Dd divide(Vector2Dd other)
      Divides the x and y values of the current Vector2Dd with the x and the y values of the provided Vector2Dd.
      Parameters:
      other - The other Vector2Dd to use as divisor for the current x and the y values.
      Returns:
      A new Vector2Dd with the divided values.
    • divide

      @CheckReturnValue @Contract(pure=true) public Vector2Dd divide(Vector2Di other)
      Divides the x and y values of the current Vector2Dd with the x and the y values of the provided Vector2Di.
      Parameters:
      other - The other Vector2Di to use as divisor for the current x and the y values.
      Returns:
      A new Vector2Dd with the divided values.
    • divide

      @CheckReturnValue @Contract(pure=true) public Vector2Dd divide(double val)
      Divides both the x and the y values of the current Vector2Dd with a provided value.
      Parameters:
      val - The value to use as divisor for both the x and the y values.
      Returns:
      A new Vector2Dd with the divided values.
    • normalized

      @CheckReturnValue @Contract(pure=true) public Vector2Dd normalized()
      Normalizes this Vector2Dd.
      Returns:
      A new Vector2Dd with normalized
    • toString

      @CheckReturnValue @Contract(pure=true) public String toString(int decimals)
      Returns a String representation of this 2d vector. The output will be the same as toString() with the only difference being that the x/y coordinate values will be formatted to a specific number of decimal places.
      Parameters:
      decimals - The number of decimals to print for each value.
      Returns:
      A String representation of this vector.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • x

      public double x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public double y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component