rhodonite
    Preparing search index...

    Class AnimatedVector2

    An animated 2D vector that can interpolate between animation keyframes over time. This class extends Vector2 and implements both IVector2 and IAnimatedValue interfaces, providing support for animation blending, looping, and time-based value updates.

    Hierarchy (View Summary)

    Implements

    Index
    • Creates a new AnimatedVector2 instance.

      Parameters

      • animationSamplers: AnimationSamplers

        A map of animation track names to their corresponding samplers

      • activeAnimationTrackName: string

        The name of the initial active animation track

      Returns AnimatedVector2

      When the specified animation track is not found in the samplers

    _v: TypedArray = ...

    Internal typed array storage for vector components

    isLoop: boolean = true

    Whether the animation should loop when it reaches the end.

    • get blendingRatio(): number

      Gets the current blending ratio between animation tracks.

      Returns number

      The current blending ratio

    • set blendingRatio(value: number): void

      Sets the blending ratio between the first and second active animation tracks.

      Parameters

      • value: number

        The blending ratio (0.0 = first track only, 1.0 = second track only)

      Returns void

    • get bytesPerComponent(): number

      Gets the number of bytes per component in the underlying typed array.

      Returns number

      The number of bytes per component

    • get className(): string

      Gets the class name.

      Returns string

      The string "Vector2"

    • get glslStrAsFloat(): string

      Converts the vector to a GLSL vec2 string representation with float precision.

      Returns string

      GLSL-compatible vec2 string

    • get glslStrAsInt(): string

      Converts the vector to a GLSL ivec2 string representation with integer precision.

      Returns string

      GLSL-compatible ivec2 string

    • get glslStrAsUint(): string

      Gets the GLSL string representation of the vector as unsigned integer values.

      Returns string

      GLSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • get wgslStrAsFloat(): string

      Converts the vector to a WGSL vec2f string representation with float precision.

      Returns string

      WGSL-compatible vec2f string

    • get wgslStrAsInt(): string

      Converts the vector to a WGSL vec2i string representation with integer precision.

      Returns string

      WGSL-compatible vec2i string

    • get wgslStrAsUint(): string

      Gets the WGSL string representation of the vector as unsigned integer values.

      Returns string

      WGSL-formatted string for unsigned integer values with 'u' suffix

      Error - Must be implemented by subclasses

    • get x(): number

      Gets the x component of the vector, updating the animation if necessary.

      Returns number

      The x component value

    • get y(): number

      Gets the y component of the vector, updating the animation if necessary.

      Returns number

      The y component value

    • get z(): number

      Gets the z component of the vector, updating the animation if necessary. Note: This always returns the z component even though this is a 2D vector.

      Returns number

      The z component value

    • get compositionType(): CompositionTypeClass<"VEC2">

      Gets the composition type of this vector.

      Returns CompositionTypeClass<"VEC2">

      The composition type (Vec2)

    • Gets the component at the specified index.

      Parameters

      • i: number

        The index (0 for x, 1 for y)

      Returns number

      The component value at the specified index

    • Creates a clone of this vector.

      Returns Vector2

      A new Vector2 instance with the same components

    • Removes an animation sampler from the available tracks.

      Parameters

      • trackName: string

        The name of the animation track to remove

      Returns void

    • Calculates the dot product with another vector.

      Parameters

      • vec: IVector2

        The vector to calculate dot product with

      Returns number

      The dot product result

    • Converts the vector to a flat array representation.

      Returns number[]

      Array containing [x, y] components

    • Gets all available animation track names.

      Returns string[]

      An array containing all animation track names

    • Gets the animation sampler for a specific track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns AnimationSampler

      The animation sampler for the specified track

      When the specified animation track is not found

    • Number of actual interpolations performed. Intended for tests and benchmarks.

      Returns number

    • Gets the track name of the sampler that is actually bound as the first animation. This can differ from the requested active track when that track has no sampler.

      Returns string

      The track name of the currently evaluated first sampler

    • Gets the name of the first (primary) active animation track.

      Returns string

      The name of the first active animation track

    • Gets the maximum end time for a specific animation track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns number

      The maximum end time (last input value) of the specified track

      When the specified animation track is not found

    • Gets the minimum start time for a specific animation track.

      Parameters

      • trackName: string

        The name of the animation track

      Returns number

      The minimum start time (first input value) of the specified track

      When the specified animation track is not found

    • Returns the current vector values as a regular JavaScript array.

      Returns number[]

      An array containing the x and y components of the vector

    • Gets the track name of the sampler that is actually bound as the second animation. This can differ from the requested active track when that track has no sampler.

      Returns string | undefined

      The track name of the currently evaluated second sampler, or undefined if none is bound

    • Gets the name of the second (secondary) active animation track.

      Returns string | undefined

      The name of the second active animation track, or undefined if not set

    • Gets the internal value array without allocating a copy. Do not mutate the returned array.

      Returns TypedArray

    • Drops the memoized interpolation result. Call this after mutating sampler data directly.

      Returns void

    • Checks if this vector is a dummy (empty) vector.

      Returns boolean

      True if the vector has no components, false otherwise

    • Checks if this vector is approximately equal to another vector within a tolerance.

      Parameters

      • vec: IVector2

        The vector to compare with

      • delta: number = Number.EPSILON

        The tolerance value (default: Number.EPSILON)

      Returns boolean

      True if vectors are approximately equal, false otherwise

    • Checks if this vector is strictly equal to another vector (exact comparison).

      Parameters

      • vec: IVector2

        The vector to compare with

      Returns boolean

      True if vectors are exactly equal, false otherwise

    • Checks if the internal storage shares the same ArrayBuffer as the provided one. Useful for determining if vectors share underlying memory.

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer to compare against

      Returns boolean

      True if the same ArrayBuffer is used, false otherwise

    • Calculates the length (magnitude) of the vector.

      Returns number

      The length of the vector

    • Calculates the squared length of the vector. This is more efficient than calculating the actual length when only comparison is needed.

      Returns number

      The squared length of the vector

    • Calculates the distance from this vector to another vector.

      Parameters

      Returns number

      The distance between the vectors

    • Adds or updates an animation sampler for a specific track.

      Parameters

      • animationTrackName: string

        The name of the animation track

      • animationSampler: AnimationSampler

        The animation sampler to associate with the track

      Returns void

    • Sets the first (primary) active animation track.

      Parameters

      • animationTrackName: string

        The name of the animation track to set as primary

      Returns void

      When the specified animation track is not found (logged as info instead)

    • Sets the internal Float32Array and triggers an update.

      Parameters

      • array: Float32Array

        The new Float32Array to use for the vector components

      Returns void

    • Sets the second (secondary) active animation track for blending.

      Parameters

      • animationTrackName: string

        The name of the animation track to set as secondary

      Returns void

      When the specified animation track is not found (logged as info instead)

    • Sets a specific time for animation evaluation instead of using global time.

      Parameters

      • time: number

        The time value to use for animation sampling

      Returns void

    • Sets the time and blending ratio and evaluates the value at most once.

      Parameters

      • time: number
      • blendingRatio: number

      Returns void

    • Converts the vector to a string representation.

      Returns string

      String representation in the format "(x, y)"

    • Converts the vector to an approximate string representation with financial precision.

      Returns string

      String representation with reduced decimal places

    • Updates the vector values based on the current time and active animation tracks. Handles looping, blending between tracks, and caching to avoid redundant calculations.

      Returns void

    • Clears the specific time and uses the default time (0) for animation updates. When used with AnimationComponent, the time will be set via setTime() during animation processing.

      Returns void

    • Gets the component value at the specified index. Alias for the at() method for convenience.

      Parameters

      • i: number

        The index of the component to retrieve

      Returns number

      The component value at the given index

    • Adds two vectors component-wise.

      Parameters

      • l_vec: IVector2

        The left vector operand

      • r_vec: IVector2

        The right vector operand

      Returns Vector2

      A new Vector2 instance containing the sum

    • Calculates the angle between two vectors in radians.

      Parameters

      Returns number

      The angle between the vectors in radians

    • Divides a vector by a scalar value.

      Parameters

      • vec: IVector2

        The vector to divide

      • value: number

        The scalar value to divide by

      Returns Vector2

      A new Vector2 instance containing the divided result

    • Divides the left vector by the right vector component-wise.

      Parameters

      • l_vec: IVector2

        The left vector operand (dividend)

      • r_vec: IVector2

        The right vector operand (divisor)

      Returns Vector2

      A new Vector2 instance containing the component-wise division result

    • Calculates the dot product of two vectors (static version).

      Parameters

      • l_vec: IVector2

        The left vector operand

      • r_vec: IVector2

        The right vector operand

      Returns number

      The dot product of the two vectors

    • Creates a dummy vector with no components.

      Returns Vector2

      A new dummy Vector2 instance

    • Creates a vector from individual x and y components.

      Parameters

      • x: number

        The x component

      • y: number

        The y component

      Returns Vector2

      A new Vector2 instance

    • Creates a vector from an array, taking the first 2 elements.

      Parameters

      • array: number[]

        The array containing components

      Returns Vector2

      A new Vector2 instance

    • Creates a vector from a 2-element array.

      Parameters

      • array: Array2<number>

        The array containing [x, y] components

      Returns Vector2

      A new Vector2 instance

    • Creates a vector by copying components from another IVector2.

      Parameters

      Returns Vector2

      A new Vector2 instance

    • Creates a vector by copying the first 2 components from a 4D vector.

      Parameters

      Returns Vector2

      A new Vector2 instance

    • Calculates the distance between two vectors.

      Parameters

      Returns number

      The distance between the vectors

    • Calculates the squared length of a vector (static version). This is more efficient than calculating the actual length when only comparison is needed.

      Parameters

      • vec: IVector2

        The vector to calculate squared length for

      Returns number

      The squared length of the vector

    • Multiplies a vector by a scalar value.

      Parameters

      • vec: IVector2

        The vector to multiply

      • value: number

        The scalar value to multiply by

      Returns Vector2

      A new Vector2 instance containing the scaled result

    • Multiplies two vectors component-wise.

      Parameters

      • l_vec: IVector2

        The left vector operand

      • r_vec: IVector2

        The right vector operand

      Returns Vector2

      A new Vector2 instance containing the component-wise product

    • Normalizes a vector to unit length.

      Parameters

      Returns Vector2

      A new normalized Vector2 instance

    • Creates a one vector (1, 1).

      Returns Vector2

      A new one Vector2 instance

    • Subtracts the right vector from the left vector component-wise.

      Parameters

      • l_vec: IVector2

        The left vector operand

      • r_vec: IVector2

        The right vector operand

      Returns Vector2

      A new Vector2 instance containing the difference

    • Creates a zero vector (0, 0).

      Returns Vector2

      A new zero Vector2 instance