Struct Color4<T>
To provide type-safety between different color spaces and allow extension by users to include additional and future color spaces, colors are marked with a special phantom type parameter that indicates their color space.
Typically these are four-letter abbreviations that indicate the components of the colors, such as Rgba or Hsva.
In any of these cases, letters in the color space correspond to the order of the components in the color vector. For example, color Rgba maps as follows:
X -> R
Y -> G
Z -> B
W -> A.
Implements
Inherited Members
Namespace: OpenTK.Mathematics
Assembly: OpenTK.Mathematics.dll
Syntax
public struct Color4<T> : IEquatable<Color4<T>> where T : IColorSpace4
Type Parameters
Name | Description |
---|---|
T | The color space of the given color. |
Constructors
Color4(float, float, float, float)
Initializes a new instance of the Color4<T> struct.
Declaration
public Color4(float x, float y, float z, float w)
Parameters
Type | Name | Description |
---|---|---|
float | x | The first element of the color. |
float | y | The second element of the color. |
float | z | The third element of the color. |
float | w | The fourth element of the color. |
Fields
W
The fourth element of this color. This corresponds to the second letter of the colour type.
Declaration
public float W
Field Value
Type | Description |
---|---|
float |
X
The first element of this color. This corresponds to the first letter of the color type.
Declaration
public float X
Field Value
Type | Description |
---|---|
float |
Y
The second element of this colour. This corresponds to the second letter of the colour type.
Declaration
public float Y
Field Value
Type | Description |
---|---|
float |
Z
The third element of this color. This corresponds to the second letter of the colour type.
Declaration
public float Z
Field Value
Type | Description |
---|---|
float |
Properties
this[int]
Gets or sets the nth element of this color.
Declaration
public float this[int n] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
int | n | The nth element to get. |
Property Value
Type | Description |
---|---|
float |
Methods
Deconstruct(out float, out float, out float, out float)
Deconstructs this color4 and turns it into a tuple containing 4 floats.
Declaration
[Pure]
public void Deconstruct(out float x, out float y, out float z, out float w)
Parameters
Type | Name | Description |
---|---|---|
float | x | The x component of this color, defined by the color space. |
float | y | The y component of this color, defined by the color space. |
float | z | The z component of this color, defined by the color space. |
float | w | The w component of this color, defined by the color space. |
Equals(Color4<T>)
Compares whether this Color4 structure is equal to the specified Color4.
Declaration
[Pure]
public bool Equals(Color4<T> other)
Parameters
Type | Name | Description |
---|---|---|
Color4<T> | other | The Color4 structure to compare to. |
Returns
Type | Description |
---|---|
bool | True if both Color4 structures contain the same components; false otherwise. |
Equals(object)
Compares whether this Color4 structure is equal to the specified object.
Declaration
[Pure]
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | An object to compare to. |
Returns
Type | Description |
---|---|
bool | True obj is a Color4 structure with the same components as this Color4; false otherwise. |
Overrides
GetHashCode()
Calculates the hash code for this Color4 structure.
Declaration
[Pure]
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A System.Int32 containing the hashcode of this Color4 structure. |
Overrides
ToString()
Creates a string that describes this Color4 structure.
Declaration
[Pure]
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that describes this Color4 structure. |
Overrides
Operators
operator ==(in Color4<T>, in Color4<T>)
Compares the specified Color4 structures for equality.
Declaration
[Pure]
public static bool operator ==(in Color4<T> left, in Color4<T> right)
Parameters
Type | Name | Description |
---|---|---|
Color4<T> | left | The left-hand side of the comparison. |
Color4<T> | right | The right-hand side of the comparison. |
Returns
Type | Description |
---|---|
bool | True if left is equal to right; false otherwise. |
explicit operator Vector4(in Color4<T>)
Declaration
[Pure]
public static explicit operator Vector4(in Color4<T> col)
Parameters
Type | Name | Description |
---|---|---|
Color4<T> | col | The color which the instantiated vector will use the X,Y,Z and W from, in that order. |
Returns
Type | Description |
---|---|
Vector4 | The vector that was instantiated. |
explicit operator Color4<T>(in Vector4)
Declaration
[Pure]
public static explicit operator Color4<T>(in Vector4 vec)
Parameters
Type | Name | Description |
---|---|---|
Vector4 | vec | The vector which the instantiated color will use the X,Y,Z and W from, in that order. |
Returns
Type | Description |
---|---|
Color4<T> | The color that was instantiated. |
operator !=(in Color4<T>, in Color4<T>)
Compares the specified Color4 structures for inequality.
Declaration
[Pure]
public static bool operator !=(in Color4<T> left, in Color4<T> right)
Parameters
Type | Name | Description |
---|---|---|
Color4<T> | left | The left-hand side of the comparison. |
Color4<T> | right | The right-hand side of the comparison. |
Returns
Type | Description |
---|---|
bool | True if left is not equal to right; false otherwise. |