Record Class Vector3Dd

java.lang.Object
java.lang.Record
nl.pim16aap2.animatedarchitecture.core.util.vector.Vector3Dd
All Implemented Interfaces:
IVector3D

public record Vector3Dd(double x, double y, double z) extends Record implements IVector3D
Represents a double x/y/z set.

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

  • Constructor Details

    • Vector3Dd

      public Vector3Dd(IVector3D other)
    • Vector3Dd

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

    • of

      public static Vector3Dd of(IVector3D other)
      Creates a Vector3Dd from a IVector3D.

      If the provided IVector3D is already a Vector3Dd, the same instance is returned, otherwise a new instance is created.

      Parameters:
      other - A IVector3D to retrieve as Vector3Dd
      Returns:
      A Vector3Dd representing the provided IVector3D. If the provided IVector3D was already of this type, the same instance is returned.
    • toInteger

      @CheckReturnValue @Contract(pure=true) public Vector3Di toInteger()
      Description copied from interface: IVector3D
      Creates a new integer-based 3d vector from this 3d vector.

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

      Specified by:
      toInteger in interface IVector3D
      Returns:
      A new integer-based vector.
    • toDouble

      @CheckReturnValue @Contract(pure=true) public Vector3Dd toDouble()
      Description copied from interface: IVector3D
      Creates a new double-based 3d vector from this integer-based 3d vector.
      Specified by:
      toDouble in interface IVector3D
      Returns:
      A new double-based vector.
    • add

      @CheckReturnValue @Contract(pure=true) public Vector3Dd add(double x, double y, double z)
      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.
      z - The z value to add to the current z value.
      Returns:
      A new Vector3Dd with the added values.
    • add

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

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

      @CheckReturnValue @Contract(pure=true) public Vector3Dd subtract(double x, double y, double z)
      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.
      z - The z value to subtract from the current z value.
      Returns:
      A new Vector3Dd with the subtracted values.
    • subtract

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

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

      @CheckReturnValue @Contract(pure=true) public Vector3Dd multiply(double x, double y, double z)
      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.
      z - The z value to multiply with the current z value.
      Returns:
      A new Vector3Dd with the multiplied values.
    • multiply

      @CheckReturnValue @Contract(pure=true) public Vector3Dd multiply(IVector3D other)
      Multiplies another 3D vector with the x, y, and z values of the current Vector3Dd.
      Parameters:
      other - The other 3D vector.
      Returns:
      The new Vector3Dd with the value multiplied with the values.
    • multiply

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

      @CheckReturnValue @Contract(pure=true) public Vector3Dd divide(double x, double y, double z)
      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.
      z - The z value to use as divisor for the current z value.
      Returns:
      A new Vector3Dd with the divided values.
    • divide

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

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

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

      @CheckReturnValue @Contract(pure=true) public String toString(int decimals)
      Returns a String representation of this 3d vector. The output will be the same as toString() with the only difference being that the x/y/z 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.
    • rotateAroundXAxis

      @CheckReturnValue @Contract(pure=true) public Vector3Dd rotateAroundXAxis(IVector3D pivotPoint, double radians)
      Rotates this point around another point along the x axis.
      Parameters:
      pivotPoint - The point around which to rotate this point.
      radians - How far to rotate this point (in radians).
      Returns:
      A new Vector3Dd rotated around the pivot point.
    • rotateAroundYAxis

      @CheckReturnValue @Contract(pure=true) public Vector3Dd rotateAroundYAxis(IVector3D pivotPoint, double radians)
      Rotates this point around another point along the y axis.
      Parameters:
      pivotPoint - The point around which to rotate this point.
      radians - How far to rotate this point (in radians).
      Returns:
      A new Vector3Dd rotated around the pivot point.
    • rotateAroundZAxis

      @CheckReturnValue @Contract(pure=true) public Vector3Dd rotateAroundZAxis(IVector3D pivotPoint, double radians)
      Rotates this point around another point along the z axis.
      Parameters:
      pivotPoint - The point around which to rotate this point.
      radians - How far to rotate this point (in radians).
      Returns:
      A new Vector3Dd rotated around the pivot point.
    • max

      @CheckReturnValue @Contract(pure=true) public double max()
      Returns the highest value in this vector.
      Returns:
      The highest value in this vector.
    • min

      @CheckReturnValue @Contract(pure=true) public double min()
      Returns the lowest value in this vector.
      Returns:
      The lowest value in this vector.
    • xD

      public double xD()
      Description copied from interface: IVector3D
      Returns the x value as double.
      Specified by:
      xD in interface IVector3D
      Returns:
      The x value as double.
    • yD

      public double yD()
      Description copied from interface: IVector3D
      Returns the y value as double.
      Specified by:
      yD in interface IVector3D
      Returns:
      The y value as double.
    • zD

      public double zD()
      Description copied from interface: IVector3D
      Returns the z value as double.
      Specified by:
      zD in interface IVector3D
      Returns:
      The z value as double.
    • floor

      public Vector3Dd floor()
      Description copied from interface: IVector3D
      Returns a new vector with Math.floor(double) applied to the current values.
      Specified by:
      floor in interface IVector3D
      Returns:
      A new vector with Math.floor(double) applied to the current values.
    • round

      public Vector3Dd round()
      Description copied from interface: IVector3D
      Returns a new vector with Math.round(double) applied to the current values.
      Specified by:
      round in interface IVector3D
      Returns:
      A new vector with Math.round(double) applied to the current values.
    • ceil

      public Vector3Dd ceil()
      Description copied from interface: IVector3D
      Returns a new vector with Math.ceil(double) applied to the current values.
      Specified by:
      ceil in interface IVector3D
      Returns:
      A new vector with Math.ceil(double) applied to the current values.
    • clamp

      public Vector3Dd clamp(Cuboid cuboid)
      Clamps the vector using a cuboid to provide the upper and lower limits.
      Parameters:
      cuboid - A cuboid describing the upper and lower limits of the vector.
      Returns:
      A new vector.
    • clamp

      public Vector3Dd clamp(IVector3D min, IVector3D max)
      Clamps the vector to the provided upper and lower limits.
      Parameters:
      min - A 3d vector describing the lower limits of the vector.
      max - A 3d vector describing the upper limits of the vector.
      Returns:
      A new 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
    • z

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