Struct RGB
A colour in RGB (red, green, blue) format with no alpha channel.
public readonly struct RGB : IEquatable<RGB>
- Implements
- Inherited Members
- Extension Methods
Remarks
The RGB values are in the inclusive range [0, 1]
.
Constructors
RGB(float, float, float)
Creates an RGB with the given channels without clamping.
public RGB(float r, float g, float b)
Parameters
Fields
Black
The colour (0, 0, 0)
.
public static readonly RGB Black
Field Value
Blue
The colour (0, 0, 1)
.
public static readonly RGB Blue
Field Value
Green
The colour (0, 1, 0)
.
public static readonly RGB Green
Field Value
Red
The colour (1, 0, 0)
.
public static readonly RGB Red
Field Value
White
The colour (1, 1, 1)
.
public static readonly RGB White
Field Value
Properties
b
The blue channel of the colour.
public float b { get; init; }
Property Value
Remarks
This is intended to be in the inclusive range [0, 1]
, but can be outside.
g
The green channel of the colour.
public float g { get; init; }
Property Value
Remarks
This is intended to be in the inclusive range [0, 1]
, but can be outside.
r
The red channel of the colour.
public float r { get; init; }
Property Value
Remarks
This is intended to be in the inclusive range [0, 1]
, but can be outside.
Methods
Clamp01()
Returns the RGB with each component clamped to the inclusive range [0, 1]
.
public RGB Clamp01()
Returns
Equals(RGB)
public bool Equals(RGB other)
Parameters
other
RGB
Returns
Equals(RGB, float)
Returns whether each component of other
differs from the corresponding component of this by <= tolerance
.
public bool Equals(RGB other, float tolerance)
Parameters
Returns
Equals(object)
See Equals(RGB).
public override bool Equals(object obj)
Parameters
obj
object
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
LerpClamped(RGB, RGB, float)
Linearly interpolates component-wise from start
(t
= 0) to end
(t
= 1), clamping t
to
the inclusive range [0, 1]
.
public static RGB LerpClamped(RGB start, RGB end, float t)
Parameters
Returns
- See Also
LerpUnclamped(RGB, RGB, float)
Linearly interpolates component-wise from start
(t
= 0) to end
(t
= 1), without clamping
t
.
public static RGB LerpUnclamped(RGB start, RGB end, float t)
Parameters
Returns
Remarks
Values of t
outside the range [0, 1]
will give outputs beyond start
or end
.
- See Also
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(string)
Applies format
to each component.
public string ToString(string format)
Parameters
format
string
Returns
WithAlpha(float)
Returns a Color with the same RGB values and with the given alpha.
public Color WithAlpha(float alpha)
Parameters
alpha
float
Returns
- Color
Operators
operator +(RGB, RGB)
Adds component-wise, with no clamping.
public static RGB operator +(RGB x, RGB y)
Parameters
Returns
operator /(RGB, RGB)
Divides component-wise, with no clamping.
public static RGB operator /(RGB x, RGB y)
Parameters
Returns
operator /(RGB, float)
Divides each component of rgb
by scalar
with no clamping.
public static RGB operator /(RGB rgb, float scalar)
Parameters
Returns
operator ==(RGB, RGB)
Component-wise equality.
public static bool operator ==(RGB x, RGB y)
Parameters
Returns
explicit operator RGB(Color)
Returns an RGB with the same RGB values as the Color, but discarding the alpha.
public static explicit operator RGB(Color rgba)
Parameters
rgba
Color
Returns
explicit operator HSL(RGB)
public static explicit operator HSL(RGB rgb)
Parameters
rgb
RGB
Returns
Remarks
Does not do any clamping.
This is independent of colour space.
explicit operator HSV(RGB)
public static explicit operator HSV(RGB rgb)
Parameters
rgb
RGB
Returns
Remarks
Does not do any clamping.
This is independent of colour space.
operator !=(RGB, RGB)
public static bool operator !=(RGB x, RGB y)
Parameters
Returns
operator *(RGB, RGB)
Multiplies component-wise, with no clamping.
public static RGB operator *(RGB x, RGB y)
Parameters
Returns
operator *(RGB, float)
Multiplies each component of rgb
by scalar
with no clamping.
public static RGB operator *(RGB rgb, float scalar)
Parameters
Returns
operator *(float, RGB)
Multiplies each component of rgb
by scalar
with no clamping.
public static RGB operator *(float scalar, RGB rgb)
Parameters
Returns
operator -(RGB, RGB)
Subtracts component-wise, with no clamping.
public static RGB operator -(RGB x, RGB y)