Table of Contents

Struct Color3

Namespace
HelixToolkit.Maths
Assembly
HelixToolkit.Maths.dll

Represents a color in the form of rgb.

public struct Color3 : IEquatable<Color3>, IFormattable
Implements
Inherited Members
Extension Methods

Constructors

Color3(int)

Initializes a new instance of the Color3 struct.

public Color3(int rgb)

Parameters

rgb int

A packed integer containing all three color components in RGB order. The alpha component is ignored.

Color3(Vector3)

Initializes a new instance of the Color3 struct.

public Color3(Vector3 value)

Parameters

value Vector3

The red, green, and blue components of the color.

Color3(float)

Initializes a new instance of the Color3 struct.

public Color3(float value)

Parameters

value float

The value that will be assigned to all components.

Color3(float, float, float)

Initializes a new instance of the Color3 struct.

public Color3(float red, float green, float blue)

Parameters

red float

The red component of the color.

green float

The green component of the color.

blue float

The blue component of the color.

Color3(float[])

Initializes a new instance of the Color3 struct.

public Color3(float[] values)

Parameters

values float[]

The values to assign to the red, green, and blue components of the color. This must be an array with three elements.

Exceptions

ArgumentNullException

Thrown when values is null.

ArgumentOutOfRangeException

Thrown when values contains more or less than four elements.

Fields

Black

The Black color (0, 0, 0).

public static readonly Color3 Black

Field Value

Color3

Blue

The blue component of the color.

public float Blue

Field Value

float

Green

The green component of the color.

public float Green

Field Value

float

Red

The red component of the color.

public float Red

Field Value

float

White

The White color (1, 1, 1, 1).

public static readonly Color3 White

Field Value

Color3

Properties

this[int]

Gets or sets the component at the specified index.

public float this[int index] { readonly get; set; }

Parameters

index int

The index of the component to access. Use 0 for the red component, 1 for the green component, and 2 for the blue component.

Property Value

float

The value of the red, green, or blue component, depending on the index.

Exceptions

ArgumentOutOfRangeException

Thrown when the index is out of the range [0, 2].

Methods

Add(Color3, Color3)

Adds two colors.

public static Color3 Add(Color3 left, Color3 right)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

Returns

Color3

The sum of the two colors.

Add(ref Color3, ref Color3, out Color3)

Adds two colors.

public static void Add(ref Color3 left, ref Color3 right, out Color3 result)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

result Color3

When the method completes, completes the sum of the two colors.

AdjustContrast(Color3, float)

Adjusts the contrast of a color.

public static Color3 AdjustContrast(Color3 value, float contrast)

Parameters

value Color3

The color whose contrast is to be adjusted.

contrast float

The amount by which to adjust the contrast.

Returns

Color3

The adjusted color.

AdjustContrast(ref Color3, float, out Color3)

Adjusts the contrast of a color.

public static void AdjustContrast(ref Color3 value, float contrast, out Color3 result)

Parameters

value Color3

The color whose contrast is to be adjusted.

contrast float

The amount by which to adjust the contrast.

result Color3

When the method completes, contains the adjusted color.

AdjustSaturation(Color3, float)

Adjusts the saturation of a color.

public static Color3 AdjustSaturation(Color3 value, float saturation)

Parameters

value Color3

The color whose saturation is to be adjusted.

saturation float

The amount by which to adjust the saturation.

Returns

Color3

The adjusted color.

AdjustSaturation(ref Color3, float, out Color3)

Adjusts the saturation of a color.

public static void AdjustSaturation(ref Color3 value, float saturation, out Color3 result)

Parameters

value Color3

The color whose saturation is to be adjusted.

saturation float

The amount by which to adjust the saturation.

result Color3

When the method completes, contains the adjusted color.

Clamp(Color3, Color3, Color3)

Restricts a value to be within a specified range.

public static Color3 Clamp(Color3 value, Color3 min, Color3 max)

Parameters

value Color3

The value to clamp.

min Color3

The minimum value.

max Color3

The maximum value.

Returns

Color3

The clamped value.

Clamp(ref Color3, ref Color3, ref Color3, out Color3)

Restricts a value to be within a specified range.

public static void Clamp(ref Color3 value, ref Color3 min, ref Color3 max, out Color3 result)

Parameters

value Color3

The value to clamp.

min Color3

The minimum value.

max Color3

The maximum value.

result Color3

When the method completes, contains the clamped value.

Equals(Color3)

Determines whether the specified Color3 is equal to this instance.

public readonly bool Equals(Color3 other)

Parameters

other Color3

The Color3 to compare with this instance.

Returns

bool

true if the specified Color3 is equal to this instance; otherwise, false.

Equals(ref Color3)

Determines whether the specified Color3 is equal to this instance.

public readonly bool Equals(ref Color3 other)

Parameters

other Color3

The Color3 to compare with this instance.

Returns

bool

true if the specified Color3 is equal to this instance; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to this instance.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetHashCode()

Returns a hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Lerp(Color3, Color3, float)

Performs a linear interpolation between two colors.

public static Color3 Lerp(Color3 start, Color3 end, float amount)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Color3

The linear interpolation of the two colors.

Remarks

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Lerp(ref Color3, ref Color3, float, out Color3)

Performs a linear interpolation between two colors.

public static void Lerp(ref Color3 start, ref Color3 end, float amount, out Color3 result)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color3

When the method completes, contains the linear interpolation of the two colors.

Remarks

Passing amount a value of 0 will cause start to be returned; a value of 1 will cause end to be returned.

Max(Color3, Color3)

Returns a color containing the largest components of the specified colors.

public static Color3 Max(Color3 left, Color3 right)

Parameters

left Color3

The first source color.

right Color3

The second source color.

Returns

Color3

A color containing the largest components of the source colors.

Max(ref Color3, ref Color3, out Color3)

Returns a color containing the smallest components of the specified colors.

public static void Max(ref Color3 left, ref Color3 right, out Color3 result)

Parameters

left Color3

The first source color.

right Color3

The second source color.

result Color3

When the method completes, contains an new color composed of the largest components of the source colors.

Min(Color3, Color3)

Returns a color containing the smallest components of the specified colors.

public static Color3 Min(Color3 left, Color3 right)

Parameters

left Color3

The first source color.

right Color3

The second source color.

Returns

Color3

A color containing the smallest components of the source colors.

Min(ref Color3, ref Color3, out Color3)

Returns a color containing the smallest components of the specified colors.

public static void Min(ref Color3 left, ref Color3 right, out Color3 result)

Parameters

left Color3

The first source color.

right Color3

The second source color.

result Color3

When the method completes, contains an new color composed of the smallest components of the source colors.

Modulate(Color3, Color3)

Modulates two colors.

public static Color3 Modulate(Color3 left, Color3 right)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

Returns

Color3

The modulated color.

Modulate(ref Color3, ref Color3, out Color3)

Modulates two colors.

public static void Modulate(ref Color3 left, ref Color3 right, out Color3 result)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

result Color3

When the method completes, contains the modulated color.

Negate(Color3)

Negates a color.

public static Color3 Negate(Color3 value)

Parameters

value Color3

The color to negate.

Returns

Color3

The negated color.

Negate(ref Color3, out Color3)

Negates a color.

public static void Negate(ref Color3 value, out Color3 result)

Parameters

value Color3

The color to negate.

result Color3

When the method completes, contains the negated color.

Premultiply(Color3, float)

Computes the premultiplied value of the provided color.

public static Color3 Premultiply(Color3 value, float alpha)

Parameters

value Color3

The non-premultiplied value.

alpha float

The color alpha.

Returns

Color3

The premultiplied color.

Premultiply(ref Color3, float, out Color3)

Computes the premultiplied value of the provided color.

public static void Premultiply(ref Color3 value, float alpha, out Color3 result)

Parameters

value Color3

The non-premultiplied value.

alpha float

The color alpha.

result Color3

The premultiplied result.

Scale(Color3, float)

Scales a color.

public static Color3 Scale(Color3 value, float scale)

Parameters

value Color3

The color to scale.

scale float

The amount by which to scale.

Returns

Color3

The scaled color.

Scale(ref Color3, float, out Color3)

Scales a color.

public static void Scale(ref Color3 value, float scale, out Color3 result)

Parameters

value Color3

The color to scale.

scale float

The amount by which to scale.

result Color3

When the method completes, contains the scaled color.

SmoothStep(Color3, Color3, float)

Performs a cubic interpolation between two colors.

public static Color3 SmoothStep(Color3 start, Color3 end, float amount)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

Returns

Color3

The cubic interpolation of the two colors.

SmoothStep(ref Color3, ref Color3, float, out Color3)

Performs a cubic interpolation between two colors.

public static void SmoothStep(ref Color3 start, ref Color3 end, float amount, out Color3 result)

Parameters

start Color3

Start color.

end Color3

End color.

amount float

Value between 0 and 1 indicating the weight of end.

result Color3

When the method completes, contains the cubic interpolation of the two colors.

Subtract(Color3, Color3)

Subtracts two colors.

public static Color3 Subtract(Color3 left, Color3 right)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract

Returns

Color3

The difference of the two colors.

Subtract(ref Color3, ref Color3, out Color3)

Subtracts two colors.

public static void Subtract(ref Color3 left, ref Color3 right, out Color3 result)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract.

result Color3

WHen the method completes, contains the difference of the two colors.

ToArray()

Creates an array containing the elements of the color.

public readonly float[] ToArray()

Returns

float[]

A three-element array containing the components of the color.

ToBgra()

Converts the color into a packed integer.

public readonly int ToBgra()

Returns

int

A packed integer containing all three color components. The alpha channel is set to 255.

ToRgba()

Converts the color into a packed integer.

public readonly int ToRgba()

Returns

int

A packed integer containing all three color components. The alpha channel is set to 255.

ToString()

Returns a string that represents this instance.

public override readonly string ToString()

Returns

string

A string that represents this instance.

ToString(IFormatProvider)

Returns a string that represents this instance.

public readonly string ToString(IFormatProvider formatProvider)

Parameters

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToString(string)

Returns a string that represents this instance.

public readonly string ToString(string format)

Parameters

format string

The format to apply to each channel element (float)

Returns

string

A string that represents this instance.

ToString(string?, IFormatProvider?)

Returns a string that represents this instance.

public readonly string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to apply to each channel element (float).

formatProvider IFormatProvider

The format provider.

Returns

string

A string that represents this instance.

ToVector3()

Converts the color into a three component vector.

public readonly Vector3 ToVector3()

Returns

Vector3

A three component vector containing the red, green, and blue components of the color.

Operators

operator +(Color3, Color3)

Adds two colors.

public static Color3 operator +(Color3 left, Color3 right)

Parameters

left Color3

The first color to add.

right Color3

The second color to add.

Returns

Color3

The sum of the two colors.

operator ==(Color3, Color3)

Tests for equality between two objects.

public static bool operator ==(Color3 left, Color3 right)

Parameters

left Color3

The first value to compare.

right Color3

The second value to compare.

Returns

bool

true if left has the same value as right; otherwise, false.

explicit operator Color4(Color3)

Performs an explicit conversion from Color3 to Color4.

public static explicit operator Color4(Color3 value)

Parameters

value Color3

The value.

Returns

Color4

The result of the conversion.

explicit operator Color3(int)

Performs an explicit conversion from int to Color3.

public static explicit operator Color3(int value)

Parameters

value int

The value.

Returns

Color3

The result of the conversion.

implicit operator Vector3(Color3)

Performs an implicit conversion from Color3 to Vector3.

public static implicit operator Vector3(Color3 value)

Parameters

value Color3

The value.

Returns

Vector3

The result of the conversion.

implicit operator Color3(Vector3)

Performs an implicit conversion from Vector3 to Color3.

public static implicit operator Color3(Vector3 value)

Parameters

value Vector3

The value.

Returns

Color3

The result of the conversion.

operator !=(Color3, Color3)

Tests for inequality between two objects.

public static bool operator !=(Color3 left, Color3 right)

Parameters

left Color3

The first value to compare.

right Color3

The second value to compare.

Returns

bool

true if left has a different value than right; otherwise, false.

operator *(Color3, Color3)

Modulates two colors.

public static Color3 operator *(Color3 left, Color3 right)

Parameters

left Color3

The first color to modulate.

right Color3

The second color to modulate.

Returns

Color3

The modulated color.

operator *(Color3, float)

Scales a color.

public static Color3 operator *(Color3 value, float scale)

Parameters

value Color3

The factor by which to scale the color.

scale float

The color to scale.

Returns

Color3

The scaled color.

operator *(float, Color3)

Scales a color.

public static Color3 operator *(float scale, Color3 value)

Parameters

scale float

The factor by which to scale the color.

value Color3

The color to scale.

Returns

Color3

The scaled color.

operator -(Color3, Color3)

Subtracts two colors.

public static Color3 operator -(Color3 left, Color3 right)

Parameters

left Color3

The first color to subtract.

right Color3

The second color to subtract.

Returns

Color3

The difference of the two colors.

operator -(Color3)

Negates a color.

public static Color3 operator -(Color3 value)

Parameters

value Color3

The color to negate.

Returns

Color3

A negated color.

operator +(Color3)

Assert a color (return it unchanged).

public static Color3 operator +(Color3 value)

Parameters

value Color3

The color to assert (unchanged).

Returns

Color3

The asserted (unchanged) color.