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
rgbintA 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
valueVector3The red, green, and blue components of the color.
Color3(float)
Initializes a new instance of the Color3 struct.
public Color3(float value)
Parameters
valuefloatThe 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
redfloatThe red component of the color.
greenfloatThe green component of the color.
bluefloatThe blue component of the color.
Color3(float[])
Initializes a new instance of the Color3 struct.
public Color3(float[] values)
Parameters
valuesfloat[]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
valuesisnull.- ArgumentOutOfRangeException
Thrown when
valuescontains more or less than four elements.
Fields
Black
The Black color (0, 0, 0).
public static readonly Color3 Black
Field Value
Blue
The blue component of the color.
public float Blue
Field Value
Green
The green component of the color.
public float Green
Field Value
Red
The red component of the color.
public float Red
Field Value
White
The White color (1, 1, 1, 1).
public static readonly Color3 White
Field Value
Properties
this[int]
Gets or sets the component at the specified index.
public float this[int index] { readonly get; set; }
Parameters
indexintThe 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
indexis out of the range [0, 2].
Methods
Add(Color3, Color3)
Adds two colors.
public static Color3 Add(Color3 left, Color3 right)
Parameters
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
leftColor3The first color to add.
rightColor3The second color to add.
resultColor3When 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
valueColor3The color whose contrast is to be adjusted.
contrastfloatThe 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
valueColor3The color whose contrast is to be adjusted.
contrastfloatThe amount by which to adjust the contrast.
resultColor3When 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
valueColor3The color whose saturation is to be adjusted.
saturationfloatThe 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
valueColor3The color whose saturation is to be adjusted.
saturationfloatThe amount by which to adjust the saturation.
resultColor3When 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
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
valueColor3The value to clamp.
minColor3The minimum value.
maxColor3The maximum value.
resultColor3When 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
Returns
Equals(ref Color3)
Determines whether the specified Color3 is equal to this instance.
public readonly bool Equals(ref Color3 other)
Parameters
Returns
Equals(object?)
Determines whether the specified object is equal to this instance.
public override readonly bool Equals(object? obj)
Parameters
Returns
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
startColor3Start color.
endColor3End color.
amountfloatValue 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
startColor3Start color.
endColor3End color.
amountfloatValue between 0 and 1 indicating the weight of
end.resultColor3When 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
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
leftColor3The first source color.
rightColor3The second source color.
resultColor3When 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
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
leftColor3The first source color.
rightColor3The second source color.
resultColor3When 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
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
leftColor3The first color to modulate.
rightColor3The second color to modulate.
resultColor3When the method completes, contains the modulated color.
Negate(Color3)
Negates a color.
public static Color3 Negate(Color3 value)
Parameters
valueColor3The 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
valueColor3The color to negate.
resultColor3When 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
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
valueColor3The non-premultiplied value.
alphafloatThe color alpha.
resultColor3The premultiplied result.
Scale(Color3, float)
Scales a color.
public static Color3 Scale(Color3 value, float scale)
Parameters
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
valueColor3The color to scale.
scalefloatThe amount by which to scale.
resultColor3When 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
startColor3Start color.
endColor3End color.
amountfloatValue 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
startColor3Start color.
endColor3End color.
amountfloatValue between 0 and 1 indicating the weight of
end.resultColor3When 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
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
leftColor3The first color to subtract.
rightColor3The second color to subtract.
resultColor3WHen 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
ToString(IFormatProvider)
Returns a string that represents this instance.
public readonly string ToString(IFormatProvider formatProvider)
Parameters
formatProviderIFormatProviderThe format provider.
Returns
ToString(string)
Returns a string that represents this instance.
public readonly string ToString(string format)
Parameters
formatstringThe format to apply to each channel element (float)
Returns
ToString(string?, IFormatProvider?)
Returns a string that represents this instance.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format to apply to each channel element (float).
formatProviderIFormatProviderThe format provider.
Returns
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
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
Returns
- bool
trueiflefthas the same value asright; otherwise,false.
explicit operator Color4(Color3)
public static explicit operator Color4(Color3 value)
Parameters
valueColor3The value.
Returns
- Color4
The result of the conversion.
explicit operator Color3(int)
public static explicit operator Color3(int value)
Parameters
valueintThe value.
Returns
- Color3
The result of the conversion.
implicit operator Vector3(Color3)
public static implicit operator Vector3(Color3 value)
Parameters
valueColor3The value.
Returns
- Vector3
The result of the conversion.
implicit operator Color3(Vector3)
public static implicit operator Color3(Vector3 value)
Parameters
valueVector3The 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
Returns
- bool
trueiflefthas a different value thanright; otherwise,false.
operator *(Color3, Color3)
Modulates two colors.
public static Color3 operator *(Color3 left, Color3 right)
Parameters
Returns
- Color3
The modulated color.
operator *(Color3, float)
Scales a color.
public static Color3 operator *(Color3 value, float scale)
Parameters
Returns
- Color3
The scaled color.
operator *(float, Color3)
Scales a color.
public static Color3 operator *(float scale, Color3 value)
Parameters
Returns
- Color3
The scaled color.
operator -(Color3, Color3)
Subtracts two colors.
public static Color3 operator -(Color3 left, Color3 right)
Parameters
Returns
- Color3
The difference of the two colors.
operator -(Color3)
Negates a color.
public static Color3 operator -(Color3 value)
Parameters
valueColor3The color to negate.
Returns
- Color3
A negated color.
operator +(Color3)
Assert a color (return it unchanged).
public static Color3 operator +(Color3 value)
Parameters
valueColor3The color to assert (unchanged).
Returns
- Color3
The asserted (unchanged) color.