1 #ifndef DONUT_COLOR_HPP
2 #define DONUT_COLOR_HPP
166 constexpr
Color() noexcept = default;
177 constexpr
Color(
float r,
float g,
float b,
float a = 1.0f) noexcept
178 : rgba(r, g, b, a) {}
189 constexpr
Color(
double r,
double g,
double b,
double a = 1.0) noexcept
190 : rgba(static_cast<
float>(r), static_cast<
float>(g), static_cast<
float>(b), static_cast<
float>(a)) {}
202 constexpr
Color(u8 r, u8 g, u8 b, u8 a = 255) noexcept
203 :
Color(static_cast<
float>(r) / 255.0f, static_cast<
float>(g) / 255.0f, static_cast<
float>(b) / 255.0f, static_cast<
float>(a) / 255.0f) {}
215 constexpr
Color(
int r,
int g,
int b,
int a = 255) noexcept
216 :
Color(static_cast<
float>(r) / 255.0f, static_cast<
float>(g) / 255.0f, static_cast<
float>(b) / 255.0f, static_cast<
float>(a) / 255.0f) {}
228 : rgba(rgb.x, rgb.y, rgb.z, 1.0f) {}
238 : rgba(rgba.x, rgba.y, rgba.z, rgba.w) {}
250 constexpr
Color(u8vec3 rgb) noexcept
251 : rgba(rgb.x, rgb.y, rgb.z, 255) {}
261 constexpr
Color(u8vec4 rgba) noexcept
262 : rgba(rgba.x, rgba.y, rgba.z, rgba.w) {}
270 constexpr
operator vec3() const noexcept {
280 constexpr
operator vec4() const noexcept {
290 constexpr
operator dvec3() const noexcept {
292 static_cast<double>(rgba.x),
293 static_cast<double>(rgba.y),
294 static_cast<double>(rgba.z),
304 constexpr
operator dvec4() const noexcept {
306 static_cast<double>(rgba.x),
307 static_cast<double>(rgba.y),
308 static_cast<double>(rgba.z),
309 static_cast<double>(rgba.w),
320 constexpr
operator u8vec3() const noexcept {
322 static_cast<u8
>(clamp(rgba.x, 0.0f, 1.0f) * 255.0f),
323 static_cast<u8
>(clamp(rgba.y, 0.0f, 1.0f) * 255.0f),
324 static_cast<u8
>(clamp(rgba.z, 0.0f, 1.0f) * 255.0f),
335 constexpr
operator u8vec4() const noexcept {
337 static_cast<u8
>(clamp(rgba.x, 0.0f, 1.0f) * 255.0f),
338 static_cast<u8
>(clamp(rgba.y, 0.0f, 1.0f) * 255.0f),
339 static_cast<u8
>(clamp(rgba.z, 0.0f, 1.0f) * 255.0f),
340 static_cast<u8
>(clamp(rgba.w, 0.0f, 1.0f) * 255.0f),
428 return Color{+a.rgba};
439 return Color{-a.rgba};
451 return Color{a.rgba + b.rgba};
463 return Color{a.rgba - b.rgba};
475 return Color{a.rgba * b.rgba};
487 return Color{a.rgba / b.rgba};
500 return Color{a.rgba * b};
513 return Color{a * b.rgba};
526 return Color{a.rgba / b};
539 return Color{a / b.rgba};
615 vec4 rgba{0.0f, 0.0f, 0.0f, 0.0f};
622 inline constexpr Color
Color::AQUA { 0, 255, 255, 255};
624 inline constexpr Color
Color::AZURE {240, 255, 255, 255};
625 inline constexpr Color
Color::BEIGE {245, 245, 220, 255};
629 inline constexpr Color
Color::BLUE { 0, 0, 255, 255};
636 inline constexpr Color
Color::CORAL {255, 127, 80, 255};
640 inline constexpr Color
Color::CYAN { 0, 255, 255, 255};
671 inline constexpr Color
Color::GOLD {255, 215, 0, 255};
673 inline constexpr Color
Color::GRAY {128, 128, 128, 255};
674 inline constexpr Color
Color::GREY {128, 128, 128, 255};
681 inline constexpr Color
Color::IVORY {255, 255, 240, 255};
682 inline constexpr Color
Color::KHAKI {240, 230, 140, 255};
702 inline constexpr Color
Color::LIME { 0, 255, 0, 255};
704 inline constexpr Color
Color::LINEN {250, 240, 230, 255};
721 inline constexpr Color
Color::NAVY { 0, 0, 128, 255};
734 inline constexpr Color
Color::PERU {205, 133, 63, 255};
735 inline constexpr Color
Color::PINK {255, 192, 203, 255};
736 inline constexpr Color
Color::PLUM {221, 160, 221, 255};
740 inline constexpr Color
Color::RED {255, 0, 0, 255};
754 inline constexpr Color
Color::SNOW {255, 250, 250, 255};
757 inline constexpr Color
Color::TAN {210, 180, 140, 255};
758 inline constexpr Color
Color::TEAL { 0, 128, 128, 255};
763 inline constexpr Color
Color::WHEAT {245, 222, 179, 255};
764 inline constexpr Color
Color::WHITE {255, 255, 255, 255};
Normalized floating-point RGBA color type with 32 bits per component.
Definition: Color.hpp:11
static const Color LIGHT_SALMON
Definition: Color.hpp:89
static const Color PEACH_PUFF
Definition: Color.hpp:127
static const Color BEIGE
Definition: Color.hpp:19
static const Color HONEY_DEW
Definition: Color.hpp:71
static const Color AQUAMARINE
Definition: Color.hpp:17
static const Color WHEAT
Definition: Color.hpp:157
constexpr Color(u8 r, u8 g, u8 b, u8 a=255) noexcept
Construct a color with given integer values for each component in the range 0-255,...
Definition: Color.hpp:202
static const Color MEDIUM_VIOLET_RED
Definition: Color.hpp:109
friend Color operator-(const Color &a, const Color &b)
Get the result of component-wise subtraction between two colors.
Definition: Color.hpp:462
static const Color DEEP_PINK
Definition: Color.hpp:54
static const Color LIGHT_PINK
Definition: Color.hpp:88
static const Color GOLD
Definition: Color.hpp:65
static const Color DARK_OLIVE_GREEN
Definition: Color.hpp:43
static const Color SALMON
Definition: Color.hpp:138
static const Color DARK_GRAY
Definition: Color.hpp:38
static const Color IVORY
Definition: Color.hpp:75
static const Color LIGHT_CORAL
Definition: Color.hpp:82
static const Color STEEL_BLUE
Definition: Color.hpp:150
static const Color BLUE_VIOLET
Definition: Color.hpp:24
static const Color DARK_ORCHID
Definition: Color.hpp:45
static const Color LINEN
Definition: Color.hpp:98
static const Color MEDIUM_TURQUOISE
Definition: Color.hpp:108
constexpr Color(vec3 rgb) noexcept
Construct a color from a vector with 3 components, XYZ, that map to the color components RGB,...
Definition: Color.hpp:227
static const Color MEDIUM_AQUA_MARINE
Definition: Color.hpp:101
static const Color DODGER_BLUE
Definition: Color.hpp:58
static const Color RED
Definition: Color.hpp:134
static const Color AQUA
Definition: Color.hpp:16
static const Color THISTLE
Definition: Color.hpp:153
static const Color FIRE_BRICK
Definition: Color.hpp:59
constexpr Color() noexcept=default
Construct a transparent color with a value of 0 in all components.
static const Color GOLDEN_ROD
Definition: Color.hpp:66
static const Color CADET_BLUE
Definition: Color.hpp:27
static const Color SEA_SHELL
Definition: Color.hpp:141
static const Color DARK_ORANGE
Definition: Color.hpp:44
static const Color ROSY_BROWN
Definition: Color.hpp:135
static const Color LIGHT_GOLDEN_ROD_YELLOW
Definition: Color.hpp:84
friend Color operator*(const Color &a, float b)
Get the result of multiplication between a color and a scalar.
Definition: Color.hpp:499
static const Color PLUM
Definition: Color.hpp:130
static const Color SANDY_BROWN
Definition: Color.hpp:139
constexpr void setAlphaComponent(float newValue) noexcept
Set the value of the alpha component of this color.
Definition: Color.hpp:574
static const Color WHITE_SMOKE
Definition: Color.hpp:159
static const Color ORANGE_RED
Definition: Color.hpp:120
static const Color PALE_VIOLET_RED
Definition: Color.hpp:125
static const Color NAVAJO_WHITE
Definition: Color.hpp:114
static const Color MEDIUM_SLATE_BLUE
Definition: Color.hpp:106
friend Color operator*(float a, const Color &b)
Get the result of multiplication between a scalar and a color.
Definition: Color.hpp:512
static const Color SLATE_GRAY
Definition: Color.hpp:146
constexpr Color & operator+=(const Color &other) noexcept
Add the component values of another color to the respective component values of this color.
Definition: Color.hpp:352
static const Color NAVY
Definition: Color.hpp:115
static const Color LIGHT_SEA_GREEN
Definition: Color.hpp:90
constexpr Color & operator*=(float scalar) noexcept
Multiply each of the component values of this color by a scalar value.
Definition: Color.hpp:403
constexpr float getGreenComponent() const noexcept
Get the value of the green component of this color.
Definition: Color.hpp:592
static const Color LIGHT_GREEN
Definition: Color.hpp:87
static const Color GHOST_WHITE
Definition: Color.hpp:64
constexpr Color(u8vec4 rgba) noexcept
Construct a color from a vector with 4 integer components in the range 0-255, XYZW,...
Definition: Color.hpp:261
static const Color SIENNA
Definition: Color.hpp:142
static const Color DARK_MAGENTA
Definition: Color.hpp:42
static const Color INDIAN_RED
Definition: Color.hpp:73
static const Color INVISIBLE
Definition: Color.hpp:13
static const Color DARK_VIOLET
Definition: Color.hpp:53
static const Color GAINSBORO
Definition: Color.hpp:63
constexpr Color & operator/=(float scalar) noexcept
Divide each of the component values of this color by a scalar value.
Definition: Color.hpp:415
static const Color LAVENDER_BLUSH
Definition: Color.hpp:78
static const Color BISQUE
Definition: Color.hpp:20
constexpr float getBlueComponent() const noexcept
Get the value of the blue component of this color.
Definition: Color.hpp:601
constexpr void setGreenComponent(float newValue) noexcept
Set the value of the green component of this color.
Definition: Color.hpp:556
static const Color DIM_GREY
Definition: Color.hpp:57
static const Color LIGHT_SKY_BLUE
Definition: Color.hpp:91
static const Color SADDLE_BROWN
Definition: Color.hpp:137
static const Color SILVER
Definition: Color.hpp:143
static const Color LAWN_GREEN
Definition: Color.hpp:79
static const Color PURPLE
Definition: Color.hpp:132
static const Color PAPAYA_WHIP
Definition: Color.hpp:126
static const Color BURLY_WOOD
Definition: Color.hpp:26
static const Color ALICE_BLUE
Definition: Color.hpp:14
static const Color DARK_GREEN
Definition: Color.hpp:40
friend Color operator+(const Color &a)
Get the component-wise additive identity of a color.
Definition: Color.hpp:427
static const Color LAVENDER
Definition: Color.hpp:77
static const Color MEDIUM_SEA_GREEN
Definition: Color.hpp:105
friend Color operator*(const Color &a, const Color &b)
Get the result of component-wise multiplication between two colors.
Definition: Color.hpp:474
static const Color SKY_BLUE
Definition: Color.hpp:144
constexpr float getRedComponent() const noexcept
Get the value of the red component of this color.
Definition: Color.hpp:583
static const Color LIME
Definition: Color.hpp:96
static const Color DIM_GRAY
Definition: Color.hpp:56
static const Color POWDER_BLUE
Definition: Color.hpp:131
static const Color TAN
Definition: Color.hpp:151
static const Color LIGHT_SLATE_GREY
Definition: Color.hpp:93
static const Color OLIVE_DRAB
Definition: Color.hpp:118
static const Color MEDIUM_PURPLE
Definition: Color.hpp:104
static const Color DARK_SALMON
Definition: Color.hpp:47
static const Color PERU
Definition: Color.hpp:128
static const Color ANTIQUE_WHITE
Definition: Color.hpp:15
static const Color YELLOW
Definition: Color.hpp:160
static const Color DARK_RED
Definition: Color.hpp:46
static const Color DARK_SEA_GREEN
Definition: Color.hpp:48
static const Color PALE_TURQUOISE
Definition: Color.hpp:124
static const Color LIGHT_SLATE_GRAY
Definition: Color.hpp:92
static const Color CYAN
Definition: Color.hpp:34
static const Color ORANGE
Definition: Color.hpp:119
static const Color DARK_TURQUOISE
Definition: Color.hpp:52
static const Color DARK_BLUE
Definition: Color.hpp:35
static const Color MEDIUM_SPRING_GREEN
Definition: Color.hpp:107
static const Color LIGHT_STEEL_BLUE
Definition: Color.hpp:94
static const Color DARK_KHAKI
Definition: Color.hpp:41
static const Color GREY
Definition: Color.hpp:68
static const Color DARK_GREY
Definition: Color.hpp:39
static const Color DARK_CYAN
Definition: Color.hpp:36
static const Color OLD_LACE
Definition: Color.hpp:116
static const Color AZURE
Definition: Color.hpp:18
static const Color MEDIUM_ORCHID
Definition: Color.hpp:103
static const Color LIGHT_GREY
Definition: Color.hpp:86
static const Color CRIMSON
Definition: Color.hpp:33
static const Color SEA_GREEN
Definition: Color.hpp:140
static const Color PALE_GOLDEN_ROD
Definition: Color.hpp:122
static const Color DARK_SLATE_GRAY
Definition: Color.hpp:50
constexpr Color(u8vec3 rgb) noexcept
Construct a color from a vector with 3 integer components in the range 0-255, XYZ,...
Definition: Color.hpp:250
static const Color GRAY
Definition: Color.hpp:67
static const Color CHOCOLATE
Definition: Color.hpp:29
static const Color CORNFLOWER_BLUE
Definition: Color.hpp:31
static const Color INDIGO
Definition: Color.hpp:74
static const Color FUCHSIA
Definition: Color.hpp:62
static const Color FLORAL_WHITE
Definition: Color.hpp:60
static const Color LIME_GREEN
Definition: Color.hpp:97
static const Color MEDIUM_BLUE
Definition: Color.hpp:102
constexpr Color(vec4 rgba) noexcept
Construct a color from a vector with 4 components, XYZW, that map to the color components RGBA,...
Definition: Color.hpp:237
static const Color HOT_PINK
Definition: Color.hpp:72
static const Color GREEN_YELLOW
Definition: Color.hpp:70
static const Color MISTY_ROSE
Definition: Color.hpp:112
static const Color VIOLET
Definition: Color.hpp:156
constexpr Color & operator-=(const Color &other) noexcept
Subtract the component values of another color from the respective component values of this color.
Definition: Color.hpp:365
static const Color ORCHID
Definition: Color.hpp:121
static const Color MINT_CREAM
Definition: Color.hpp:111
static const Color BROWN
Definition: Color.hpp:25
static const Color DEEP_SKY_BLUE
Definition: Color.hpp:55
static const Color LIGHT_YELLOW
Definition: Color.hpp:95
constexpr Color(double r, double g, double b, double a=1.0) noexcept
Construct a color with given values for each component.
Definition: Color.hpp:189
constexpr Color & operator/=(const Color &other) noexcept
Divide the component values of this color with the respective component values of another color.
Definition: Color.hpp:391
static const Color LIGHT_BLUE
Definition: Color.hpp:81
static const Color CORNSILK
Definition: Color.hpp:32
static const Color YELLOW_GREEN
Definition: Color.hpp:161
static const Color REBECCA_PURPLE
Definition: Color.hpp:133
static const Color SNOW
Definition: Color.hpp:148
constexpr void setRedComponent(float newValue) noexcept
Set the value of the red component of this color.
Definition: Color.hpp:547
static const Color BLUE
Definition: Color.hpp:23
friend Color operator/(const Color &a, float b)
Get the result of division between a color and a scalar.
Definition: Color.hpp:525
static const Color LEMON_CHIFFON
Definition: Color.hpp:80
static const Color GREEN
Definition: Color.hpp:69
static const Color SPRING_GREEN
Definition: Color.hpp:149
constexpr Color(int r, int g, int b, int a=255) noexcept
Construct a color with given integer values for each component in the range 0-255,...
Definition: Color.hpp:215
static const Color PINK
Definition: Color.hpp:129
constexpr void setBlueComponent(float newValue) noexcept
Set the value of the blue component of this color.
Definition: Color.hpp:565
static const Color BLANCHED_ALMOND
Definition: Color.hpp:22
static const Color MOCCASIN
Definition: Color.hpp:113
static const Color TURQUOISE
Definition: Color.hpp:155
static const Color DARK_SLATE_GREY
Definition: Color.hpp:51
static const Color FOREST_GREEN
Definition: Color.hpp:61
static const Color CORAL
Definition: Color.hpp:30
friend Color operator/(float a, const Color &b)
Get the result of division between a scalar and a color.
Definition: Color.hpp:538
static const Color WHITE
Definition: Color.hpp:158
static const Color OLIVE
Definition: Color.hpp:117
static const Color MIDNIGHT_BLUE
Definition: Color.hpp:110
static const Color CHARTREUSE
Definition: Color.hpp:28
static const Color SLATE_BLUE
Definition: Color.hpp:145
static const Color DARK_GOLDEN_ROD
Definition: Color.hpp:37
static const Color LIGHT_GRAY
Definition: Color.hpp:85
static const Color SLATE_GREY
Definition: Color.hpp:147
friend Color operator+(const Color &a, const Color &b)
Get the result of component-wise addition between two colors.
Definition: Color.hpp:450
constexpr Color & operator*=(const Color &other) noexcept
Multiply the component values of this color with the respective component values of another color.
Definition: Color.hpp:378
static const Color TEAL
Definition: Color.hpp:152
static const Color ROYAL_BLUE
Definition: Color.hpp:136
constexpr float getAlphaComponent() const noexcept
Get the value of the alpha component of this color.
Definition: Color.hpp:610
static const Color LIGHT_CYAN
Definition: Color.hpp:83
friend Color operator/(const Color &a, const Color &b)
Get the result of component-wise division between two colors.
Definition: Color.hpp:486
static const Color MAGENTA
Definition: Color.hpp:99
static const Color PALE_GREEN
Definition: Color.hpp:123
static const Color KHAKI
Definition: Color.hpp:76
friend Color operator-(const Color &a)
Get the component-wise additive inverse of a color.
Definition: Color.hpp:438
static const Color BLACK
Definition: Color.hpp:21
static const Color TOMATO
Definition: Color.hpp:154
static const Color DARK_SLATE_BLUE
Definition: Color.hpp:49
static const Color MAROON
Definition: Color.hpp:100
Definition: Application.hpp:9