rhodonite
    Preparing search index...

    Class ColorRgb

    Represents an RGB color with red, green, and blue components. Extends Vector3 to provide mathematical operations on color values. Each component is stored as a floating-point value, typically in the range [0, 1].

    const red = new ColorRgb(new Float32Array([1, 0, 0]));
    const green = ColorRgb.add(red, new ColorRgb(new Float32Array([0, 1, 0])));

    Hierarchy (View Summary)

    Implements

    Index
    _v: TypedArray = ...

    Internal typed array storage for vector components

    • get a(): number

      Gets the alpha component of the color (always 1 for RGB colors).

      Returns number

      Always returns 1

    • get b(): number

      Gets the blue component of the color.

      Returns number

      The blue component value

    • get bytesPerComponent(): number

      Gets the number of bytes per component.

      Returns number

      The number of bytes per component (4 for Float32Array, 8 for Float64Array)

    • get className(): string

      Gets the class name.

      Returns string

      The class name "Vector3"

    • get g(): number

      Gets the green component of the color.

      Returns number

      The green component value

    • get glslStrAsFloat(): string

      Gets the GLSL representation of this vector as a float vec3.

      Returns string

      A string representation suitable for GLSL shaders

    • get glslStrAsInt(): string

      Gets the GLSL representation of this vector as an integer ivec3.

      Returns string

      A string representation suitable for GLSL shaders with integer components

    • 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 r(): number

      Gets the red component of the color.

      Returns number

      The red component value

    • get w(): number

      Gets the W component of the color (always 1 for RGB colors).

      Returns number

      Always returns 1

    • get wgslStrAsFloat(): string

      Gets the WGSL representation of this vector as a float vec3f.

      Returns string

      A string representation suitable for WGSL shaders

    • get wgslStrAsInt(): string

      Gets the WGSL representation of this vector as an integer vec3i.

      Returns string

      A string representation suitable for WGSL shaders with integer components

    • 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 color (equivalent to red component).

      Returns number

      The X/red component value

    • get y(): number

      Gets the Y component of the color (equivalent to green component).

      Returns number

      The Y/green component value

    • get z(): number

      Gets the Z component of the color (equivalent to blue component).

      Returns number

      The Z/blue component value

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

      Gets the composition type for this vector class.

      Returns CompositionTypeClass<"VEC3">

      The composition type (Vec3)

    • Gets the component at the specified index.

      Parameters

      • i: number

        The index (0 for x, 1 for y, 2 for z)

      Returns number

      The component value at the specified index

    • Creates a deep copy of this ColorRgb instance.

      Returns ColorRgb

      A new ColorRgb instance with the same values

    • Calculates the dot product of this vector with another vector.

      Parameters

      • vec: IVector3

        The vector to calculate dot product with

      Returns number

      The dot product result

    • Converts the vector to a flat array.

      Returns number[]

      An array containing the x, y, and z components

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

      Returns boolean

      True if the vector is dummy (has no components), false otherwise

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

      Parameters

      • vec: IVector3

        The vector to compare with

      • delta: number = Number.EPSILON

        The tolerance for comparison (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: IVector3

        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

    • Converts the vector to a string representation.

      Returns string

      A string representation of the vector in the format "(x, y, z)"

    • Converts the vector to an approximate string representation with limited decimal places.

      Returns string

      A string representation with financial formatting

    • 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 color vectors component-wise.

      Parameters

      • l_vec: IVector3

        The left operand color vector

      • r_vec: IVector3

        The right operand color vector

      Returns ColorRgb

      A new ColorRgb instance representing the sum

    • Calculates the angle between two vectors in radians.

      Parameters

      Returns number

      The angle between the vectors in radians

      Error if either vector has zero length

    • Computes the cross product of two color vectors. Note: Cross product for colors is rarely used but available for completeness.

      Parameters

      • l_vec: IVector3

        The left operand color vector

      • r_vec: IVector3

        The right operand color vector

      Returns ColorRgb

      A new ColorRgb instance representing the cross product

    • Divides a color vector by a scalar value.

      Parameters

      • vec: IVector3

        The color vector to divide

      • value: number

        The scalar value to divide by

      Returns ColorRgb

      A new ColorRgb instance representing the scaled color

    • Divides a vector by a scalar and stores the result in the output vector.

      Parameters

      • vec: IVector3

        The vector to divide

      • value: number

        The scalar value to divide by

      • out: IMutableVector3

        The output vector to store the result

      Returns IMutableVector3

      The output vector containing the divided result

      If division by zero occurs, the result is set to 0 and an error is logged

    • Divides one color vector by another component-wise.

      Parameters

      • l_vec: IVector3

        The dividend color vector

      • r_vec: IVector3

        The divisor color vector

      Returns ColorRgb

      A new ColorRgb instance representing the component-wise quotient

    • Divides two vectors component-wise and stores the result in the output vector.

      Parameters

      Returns IMutableVector3

      The output vector containing the component-wise division result

      If division by zero occurs, the result is set to 0 and an error is logged

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

      Parameters

      Returns number

      The dot product of the two vectors

    • Creates a dummy ColorRgb instance for testing or placeholder purposes.

      Returns ColorRgb

      A new ColorRgb instance with dummy values

    • Creates a vector from an ArrayBuffer.

      Parameters

      • arrayBuffer: ArrayBuffer

        The ArrayBuffer containing the vector data

      Returns Vector3

      A new Vector3 instance

    • Creates a vector with all components set to the same value.

      Parameters

      • val: number

        The value to set for all components

      Returns Vector3

      A new Vector3 instance

    • Creates a vector from individual x, y, z components.

      Parameters

      • x: number

        The x component

      • y: number

        The y component

      • z: number

        The z component

      Returns Vector3

      A new Vector3 instance

    • Creates a vector from an array (takes first 3 elements).

      Parameters

      • array: number[]

        The array containing the components

      Returns Vector3

      A new Vector3 instance

    • Creates a vector from a 3-element array.

      Parameters

      • array: Array3<number>

        Array containing [x, y, z] components

      Returns Vector3

      A new Vector3 instance

    • Creates a vector by copying data from a Float32Array.

      Parameters

      • float32Array: Float32Array

        The Float32Array to copy from

      Returns Vector3

      A new Vector3 instance

    • Creates a vector by copying from another Vector3.

      Parameters

      • vec3: IVector3

        The source vector to copy from

      Returns Vector3

      A new Vector3 instance

    • Creates a Vector3 from a Vector4 (drops the w component).

      Parameters

      • vec4: IVector4

        The source Vector4 to copy from

      Returns Vector3

      A new Vector3 instance

    • Creates a vector from a Float32Array.

      Parameters

      • float32Array: Float32Array

        The Float32Array containing the vector data

      Returns Vector3

      A new Vector3 instance

    • Calculates the distance between two vectors.

      Parameters

      Returns number

      The distance between the two 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: IVector3

        The vector to calculate squared length for

      Returns number

      The squared length of the vector

    • Performs linear interpolation between two vectors.

      Parameters

      • lhs: IVector3

        The start vector

      • rhs: IVector3

        The end vector

      • ratio: number

        The interpolation ratio (0.0 to 1.0)

      Returns Vector3

      A new Vector3 instance containing the interpolated result

    • Multiplies a color vector by a scalar value.

      Parameters

      • vec: IVector3

        The color vector to multiply

      • value: number

        The scalar value to multiply by

      Returns ColorRgb

      A new ColorRgb instance representing the scaled color

    • Multiplies two color vectors component-wise.

      Parameters

      • l_vec: IVector3

        The left operand color vector

      • r_vec: IVector3

        The right operand color vector

      Returns ColorRgb

      A new ColorRgb instance representing the component-wise product

    • Normalizes a color vector to unit length.

      Parameters

      • vec: IVector3

        The color vector to normalize

      Returns ColorRgb

      A new normalized ColorRgb instance

    • Creates a ColorRgb with all components set to one (white).

      Returns ColorRgb

      A new ColorRgb instance with values [1, 1, 1]

    • Subtracts one color vector from another component-wise.

      Parameters

      • l_vec: IVector3

        The minuend color vector

      • r_vec: IVector3

        The subtrahend color vector

      Returns ColorRgb

      A new ColorRgb instance representing the difference

    • Creates a ColorRgb with all components set to zero (black).

      Returns ColorRgb

      A new ColorRgb instance with values [0, 0, 0]