Table of Contents

Struct RGB

Namespace
PAC.Colour

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

r float

See r.

g float

See g.

b float

See b.

Fields

Black

The colour (0, 0, 0).

public static readonly RGB Black

Field Value

RGB

Blue

The colour (0, 0, 1).

public static readonly RGB Blue

Field Value

RGB

Green

The colour (0, 1, 0).

public static readonly RGB Green

Field Value

RGB

Red

The colour (1, 0, 0).

public static readonly RGB Red

Field Value

RGB

White

The colour (1, 1, 1).

public static readonly RGB White

Field Value

RGB

Properties

b

The blue channel of the colour.

public float b { get; init; }

Property Value

float

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

float

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

float

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

RGB

Equals(RGB)

public bool Equals(RGB other)

Parameters

other RGB

Returns

bool

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

other RGB
tolerance float

Returns

bool

Equals(object)

public override bool Equals(object obj)

Parameters

obj object

Returns

bool

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

start RGB
end RGB
t float

Returns

RGB
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

start RGB
end RGB
t float

Returns

RGB

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

string

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

x RGB
y RGB

Returns

RGB

operator /(RGB, RGB)

Divides component-wise, with no clamping.

public static RGB operator /(RGB x, RGB y)

Parameters

x RGB
y RGB

Returns

RGB

operator /(RGB, float)

Divides each component of rgb by scalar with no clamping.

public static RGB operator /(RGB rgb, float scalar)

Parameters

rgb RGB
scalar float

Returns

RGB

operator ==(RGB, RGB)

Component-wise equality.

public static bool operator ==(RGB x, RGB y)

Parameters

x RGB
y RGB

Returns

bool

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

RGB

explicit operator HSL(RGB)

Converts from RGB to HSL.

public static explicit operator HSL(RGB rgb)

Parameters

rgb RGB

Returns

HSL

Remarks

Does not do any clamping.

This is independent of colour space.

explicit operator HSV(RGB)

Converts from RGB to HSV.

public static explicit operator HSV(RGB rgb)

Parameters

rgb RGB

Returns

HSV

Remarks

Does not do any clamping.

This is independent of colour space.

operator !=(RGB, RGB)

public static bool operator !=(RGB x, RGB y)

Parameters

x RGB
y RGB

Returns

bool

operator *(RGB, RGB)

Multiplies component-wise, with no clamping.

public static RGB operator *(RGB x, RGB y)

Parameters

x RGB
y RGB

Returns

RGB

operator *(RGB, float)

Multiplies each component of rgb by scalar with no clamping.

public static RGB operator *(RGB rgb, float scalar)

Parameters

rgb RGB
scalar float

Returns

RGB

operator *(float, RGB)

Multiplies each component of rgb by scalar with no clamping.

public static RGB operator *(float scalar, RGB rgb)

Parameters

scalar float
rgb RGB

Returns

RGB

operator -(RGB, RGB)

Subtracts component-wise, with no clamping.

public static RGB operator -(RGB x, RGB y)

Parameters

x RGB
y RGB

Returns

RGB