data-structure-typed

Author

Tyler Zeng

Copyright

Copyright (c) 2022 Tyler Zeng zrwusa@gmail.com

License

MIT License

Hierarchy

  • Vector2D

Constructors

Properties

w: number = 1
x: number = 0
y: number = 0

Accessors

  • get isZero(): boolean
  • The function checks if the x and y values of a point are both zero.

    Returns boolean

    A boolean value indicating whether both the x and y properties of the object are equal to 0.

  • get length(): number
  • The above function calculates the length of a vector using the Pythagorean theorem.

    Returns number

    The length of a vector, calculated using the Pythagorean theorem.

  • get lengthSq(): number
  • The function calculates the square of the length of a vector.

    Returns number

    The method is returning the sum of the squares of the x and y values.

  • get rounded(): Vector2D
  • The "rounded" function returns a new Vector2D object with the x and y values rounded to the nearest whole number.

    Returns Vector2D

    The method is returning a new instance of the Vector2D class with the x and y values rounded to the nearest whole number.

Methods

  • The function takes a Vector2D object as input and returns a new Vector2D object with the absolute values of its x and y components.

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

    Returns Vector2D

    The method is returning a new Vector2D object with the absolute values of the x and y components of the input vector.

  • The function "add" takes two Vector2D objects as parameters and returns a new Vector2D object with the sum of their x and y components.

    Parameters

    • vector1: Vector2D

      The parameter vector1 is an instance of the Vector2D class. It represents a 2-dimensional vector with an x and y component.

    • vector2: Vector2D

      The parameter "vector2" is of type Vector2D. It represents a 2-dimensional vector with an x and y component.

    Returns Vector2D

    The method is returning a new instance of the Vector2D class with the x and y components of the two input vectors added together.

  • The function calculates the angle between a given vector and the negative y-axis.

    Parameters

    • vector: Vector2D

      The "vector" parameter is an instance of the Vector2D class, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

    Returns number

    the angle between the given vector and the vector (0, -1) in radians.Returns the angle between origin and the given vector in radians

  • The function calculates the distance between two points in a two-dimensional space.

    Parameters

    • vector1: Vector2D

      The parameter vector1 represents the first vector in 2D space, while vector2 represents the second vector. Each vector has an x and y component, which represent their respective coordinates in the 2D space.

    • vector2: Vector2D

      The vector2 parameter represents the second vector in the calculation of distance. It is an instance of the Vector2D class, which typically has properties x and y representing the coordinates of the vector in a 2D space.

    Returns number

    The distance between vector1 and vector2.

  • The function calculates the squared distance between two 2D vectors.

    Parameters

    • vector1: Vector2D

      The parameter vector1 represents the first vector, which is an instance of the Vector2D class. It contains the x and y coordinates of the vector.

    • vector2: Vector2D

      The vector2 parameter represents the second vector in a two-dimensional space. It has properties x and y which represent the coordinates of the vector.

    Returns number

    the square of the distance between the two input vectors.

  • The function divides the x and y components of a Vector2D by a given value and returns a new Vector2D.

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

    • value: number

      The value parameter is a number that will be used to divide the x and y components of the vector.

    Returns Vector2D

    A new instance of the Vector2D class with the x and y values divided by the given value.

  • The dot function calculates the dot product of two 2D vectors.The dot product of v1 and v2

    Parameters

    • vector1: Vector2D

      The parameter vector1 represents a 2D vector with its x and y components.

    • vector2: Vector2D

      The "vector2" parameter is a Vector2D object. It represents a two-dimensional vector with an x and y component.

    Returns number

    The dot product of the two input vectors.

  • The function checks if two Vector2D objects are equal by comparing their x and y values.

    Parameters

    • vector1: Vector2D

      The parameter vector1 is of type Vector2D, which represents a 2-dimensional vector. It has two properties: x and y, which represent the x and y components of the vector, respectively.

    • vector2: Vector2D

      The parameter "vector2" is of type Vector2D.

    Returns boolean

    a boolean value, which indicates whether the two input vectors are equal or not.

  • The function checks if two Vector2D objects are equal within a specified rounding factor.

    Parameters

    • vector1: Vector2D

      The first vector to compare.

    • vector2: Vector2D

      The parameter "vector2" is a Vector2D object, which represents a 2-dimensional vector. It is used as one of the inputs for the "equalsRounded" function.

    • Optional roundingFactor: number = 12

      The roundingFactor parameter is used to determine the threshold for considering two vectors as equal. If the absolute difference in the x and y components of the vectors is less than the roundingFactor, the vectors are considered equal.

    Returns boolean

    a boolean value.

  • The function multiplies a Vector2D object by a given value.

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

    • value: number

      The "value" parameter is a number that represents the value by which the x and y components of the vector will be multiplied.

    Returns Vector2D

    A new Vector2D object with the x and y values multiplied by the given value.

  • The normalize function takes a vector as input and returns a normalized version of the vector.Normalizes the vector if it matches a certain condition

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D.

    Returns Vector2D

    the normalized vector if its length is greater than a very small value (epsilon), otherwise it returns the original vector.

  • The function returns a new Vector2D object that is perpendicular to the input vector.The vector that is perpendicular to this one

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D.

    Returns Vector2D

    A new Vector2D object is being returned.

  • The function "random" generates a random Vector2D object with x and y values within the specified range.

    Parameters

    • maxX: number

      The maxX parameter represents the maximum value for the x-coordinate of the random vector.

    • maxY: number

      The maxY parameter represents the maximum value for the y-coordinate of the generated random vector.

    Returns Vector2D

    a new instance of the Vector2D class with random x and y values.

  • The reverse function takes a Vector2D object and returns a new Vector2D object with the negated x and y values.

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector. It has two properties: "x" and "y", which represent the x and y components of the vector, respectively.

    Returns Vector2D

    A new Vector2D object with the negated x and y values of the input vector. Returns the vector that is the reverse of this vector

  • The sign function determines the sign of the cross product between two 2D vectors. (assuming the Y axis is pointing down, X axis to right like a Window app)

    Parameters

    • vector1: Vector2D

      The parameter vector1 is of type Vector2D, which represents a 2-dimensional vector. It likely has properties x and y representing the x and y components of the vector, respectively.

    • vector2: Vector2D

      The above code defines a function called "sign" that takes two parameters: vector1 and vector2. Both vector1 and vector2 are of type Vector2D.

    Returns number

    either -1 or 1. Returns positive if v2 is clockwise of this vector, negative if counterclockwise

  • The subtract function takes two Vector2D objects as parameters and returns a new Vector2D object with the x and y components subtracted.

    Parameters

    • vector1: Vector2D

      The parameter vector1 is an instance of the Vector2D class, representing a 2-dimensional vector. It has properties x and y which represent the x and y components of the vector respectively.

    • vector2: Vector2D

      The parameter "vector2" is a Vector2D object. It represents the second vector that you want to subtract from the first vector.

    Returns Vector2D

    The method is returning a new Vector2D object with the x and y components subtracted from vector1 and vector2.

  • The function subtracts a given value from the x and y components of a Vector2D object and returns a new Vector2D object.

    Parameters

    • vector: Vector2D

      The parameter "vector" is of type Vector2D, which represents a 2-dimensional vector with x and y components.

    • value: number

      The "value" parameter is a number that will be subtracted from both the x and y components of the "vector" parameter.

    Returns Vector2D

    A new Vector2D object with the x and y values subtracted by the given value.

  • The function truncates a vector to a maximum length if it exceeds that length.Adjusts x and y so that the length of the vector does not exceed max

    Parameters

    • vector: Vector2D

      A 2D vector represented by the Vector2D class.

    • max: number

      The max parameter is a number that represents the maximum length that the vector should have.

    Returns Vector2D

    either the original vector or a truncated version of the vector, depending on whether the length of the vector is greater than the maximum value specified.

Generated using TypeDoc