Color
Defined in: src/lib/math.ts:565
Extends
BaseVector<Color>
Constructors
Constructor
protected new Color(_array: Float32Array): Color;
Defined in: src/lib/math.ts:46
Parameters
| Parameter | Type |
|---|---|
_array | Float32Array |
Returns
Color
Inherited from
BaseVector\<Color\>.constructor
Properties
| Property | Modifier | Type | Default value | Description | Inherited from | Defined in |
|---|---|---|---|---|---|---|
_array | protected | Float32Array | undefined | - | BaseVector._array | src/lib/math.ts:46 |
_immutable | protected | boolean | false | - | BaseVector._immutable | src/lib/math.ts:44 |
ONE | readonly | Readonly<Color> | undefined | A color with all components set to 1. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying. | - | src/lib/math.ts:578 |
ZERO | readonly | Readonly<Color> | undefined | A color with all components set to 0. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying. | - | src/lib/math.ts:571 |
Accessors
a
Get Signature
get a(): number;
Defined in: src/lib/math.ts:639
The alpha component.
Returns
number
Set Signature
set a(value: number): void;
Defined in: src/lib/math.ts:645
Throws
if this color is immutable.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
b
Get Signature
get b(): number;
Defined in: src/lib/math.ts:625
The blue component.
Returns
number
Set Signature
set b(value: number): void;
Defined in: src/lib/math.ts:631
Throws
if this color is immutable.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
g
Get Signature
get g(): number;
Defined in: src/lib/math.ts:611
The green component.
Returns
number
Set Signature
set g(value: number): void;
Defined in: src/lib/math.ts:617
Throws
if this color is immutable.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
immutable
Get Signature
get immutable(): boolean;
Defined in: src/lib/math.ts:51
Whether this vector is immutable.
Returns
boolean
Inherited from
BaseVector.immutable
int
Get Signature
get int(): number;
Defined in: src/lib/math.ts:655
Convert the color to a 32-bit integer.
Returns
number
A 32-bit integer representing the color.
length
Get Signature
get length(): number;
Defined in: src/lib/math.ts:82
Returns
number
Inherited from
BaseVector.length
r
Get Signature
get r(): number;
Defined in: src/lib/math.ts:597
The red component.
Returns
number
Set Signature
set r(value: number): void;
Defined in: src/lib/math.ts:603
Throws
if this color is immutable.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
void
Methods
_createInstance()
protected _createInstance(array: Float32Array\<ArrayBufferLike\> | number[]): Color;
Defined in: src/lib/math.ts:712
Parameters
| Parameter | Type |
|---|---|
array | Float32Array<ArrayBufferLike> | number[] |
Returns
Color
Inherit Doc
Overrides
BaseVector._createInstance
_throwIfImmutable()
protected _throwIfImmutable(operation: string): void;
Defined in: src/lib/math.ts:62
Throws an error if this vector is immutable.
Parameters
| Parameter | Type | Description |
|---|---|---|
operation | string | Description of the attempted operation for the error message. |
Returns
void
Throws
if this vector is immutable.
Inherited from
BaseVector._throwIfImmutable
[iterator]()
iterator: Generator<number, void, unknown>;
Defined in: src/lib/math.ts:350
Make this vector iterable for destructuring.
Returns
Generator<number, void, unknown>
Inherited from
BaseVector.[iterator]
add()
add(other: Color): Color;
Defined in: src/lib/math.ts:132
Add another vector to this vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to add to this vector. |
Returns
Color
A new vector with the result of the addition.
Throws
if the index is out of bounds.
Inherited from
BaseVector.add
at()
at(index: number): number;
Defined in: src/lib/math.ts:94
Get the value at the given index.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | The index to get the value at. |
Returns
number
The value at the given index.
Throws
if the index is out of bounds.
Inherited from
BaseVector.at
clone()
clone(): Color;
Defined in: src/lib/math.ts:313
Clone this vector.
Returns
Color
A new vector with the same values.
Inherited from
BaseVector.clone
distance()
distance(other: Color): number;
Defined in: src/lib/math.ts:304
Calculate the distance between this vector and another vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to calculate the distance to. |
Returns
number
The distance between this vector and the other vector.
Throws
if the index is out of bounds.
Inherited from
BaseVector.distance
div()
div(other: Color): Color;
Defined in: src/lib/math.ts:199
Divide this vector by another vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to divide this vector by. |
Returns
Color
A new vector with the result of the division.
Throws
if the index is out of bounds.
Throws
if the divisor is zero.
Inherited from
BaseVector.div
dot()
dot(other: Color): number;
Defined in: src/lib/math.ts:226
Calculate the dot product of this vector and another vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to calculate the dot product with. |
Returns
number
The dot product of this vector and the other vector.
Throws
if the index is out of bounds.
Inherited from
BaseVector.dot
equals()
equals(other: Color, epsilon: number): boolean;
Defined in: src/lib/math.ts:325
Check if this vector is equal to another vector. (Approximately)
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
other | Color | undefined | The vector to check equality with. |
epsilon | number | 1e-6 | The epsilon to use for the comparison. |
Returns
boolean
True if the vectors are equal, false otherwise.
Inherited from
BaseVector.equals
freeze()
freeze(): Readonly\<T\>;
Defined in: src/lib/math.ts:77
Mark this vector as immutable. Once frozen, any attempt to modify the vector will throw an ImmutableVectorException.
Note: The underlying Float32Array is not itself frozen; only this wrapper instance is. All mutation methods check the immutable flag and will throw.
Returns
Readonly<T>
This vector, frozen and typed as Readonly<T>.
Inherited from
BaseVector.freeze
magnitude()
magnitude(): number;
Defined in: src/lib/math.ts:246
Calculate the magnitude of this vector.
Returns
number
The magnitude of this vector.
Throws
if the index is out of bounds.
Inherited from
BaseVector.magnitude
mul()
mul(other: Color): Color;
Defined in: src/lib/math.ts:176
Multiply this vector by another vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to multiply this vector by. |
Returns
Color
A new vector with the result of the multiplication.
Throws
if the index is out of bounds.
Inherited from
BaseVector.mul
normalize()
normalize(): Color;
Defined in: src/lib/math.ts:265
Normalize this vector.
Returns
Color
A new vector with the result of the normalization.
Throws
if the index is out of bounds.
Inherited from
BaseVector.normalize
scale()
scale(scalar: number): Color;
Defined in: src/lib/math.ts:283
Scale this vector by a scalar.
Parameters
| Parameter | Type | Description |
|---|---|---|
scalar | number | The scalar to scale this vector by. |
Returns
Color
A new vector with the result of the scaling.
Throws
if the index is out of bounds.
Inherited from
BaseVector.scale
setAt()
setAt(index: number, value: number): void;
Defined in: src/lib/math.ts:112
Set the value at the given index.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | The index to set the value at. |
value | number | The value to set at the given index. |
Returns
void
Throws
if the index is out of bounds.
Throws
if this vector is immutable.
Inherited from
BaseVector.setAt
sub()
sub(other: Color): Color;
Defined in: src/lib/math.ts:154
Subtract another vector from this vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | Color | The vector to subtract from this vector. |
Returns
Color
A new vector with the result of the subtraction.
Throws
if the index is out of bounds.
Inherited from
BaseVector.sub
toHex()
toHex(): string;
Defined in: src/lib/math.ts:669
Convert the color to a hex string.
Returns
string
A hex string representing the color.
create()
static create(
r: number,
g: number,
b: number,
a: number): Color;
Defined in: src/lib/math.ts:590
Create a color from individual components.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
r | number | undefined | The red component (0-1). |
g | number | undefined | The green component (0-1). |
b | number | undefined | The blue component (0-1). |
a | number | 1 | The alpha component (0-1, default 1). |
Returns
Color
A new color.
fromHex()
static fromHex(hex: string): Color;
Defined in: src/lib/math.ts:695
Create a color from a hex string.
Parameters
| Parameter | Type | Description |
|---|---|---|
hex | string | The hex string to create the color from (e.g., "#ff0000" or "ff0000"). Supports 6 or 8 character hex strings (with optional alpha). |
Returns
Color
A new color.
Throws
if the hex string is invalid.