-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlphaColor.h
130 lines (128 loc) · 9.17 KB
/
AlphaColor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// AlphaColor.h
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Copyright (c) 2019-2024 Adrian Maurer. All rights reserved.
// Distributed under the MIT software license (http://www.opensource.org/licenses/mit-license.php).
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef AMA_ALPHA_COLOR_H
#define AMA_ALPHA_COLOR_H
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "Color.h"
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
namespace ama {
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// AlphaColor<T, A, C>
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A = T, class C = ama::Color<T>>
class AlphaColor
{
// ELEMENT DATA
public:
A alpha;
C color;
// CONSTRUCTION / DESTRUCTION / ASSIGNMENT
public:
constexpr AlphaColor() noexcept : alpha(), color() {}
constexpr AlphaColor(const A& a, const C& c) noexcept : alpha(a), color(c) {}
// ELEMENT FUNCTIONS
public:
constexpr AlphaColor& operator+=(const AlphaColor<T, A, C>& ac) noexcept {alpha += ac.alpha, color += ac.color; return *this;}
constexpr AlphaColor& operator-=(const AlphaColor<T, A, C>& ac) noexcept {alpha -= ac.alpha, color -= ac.color; return *this;}
constexpr AlphaColor& operator*=(const AlphaColor<T, A, C>& ac) noexcept {alpha *= ac.alpha, color *= ac.color; return *this;}
constexpr AlphaColor& operator/=(const AlphaColor<T, A, C>& ac) noexcept {alpha /= ac.alpha, color /= ac.color; return *this;}
constexpr AlphaColor& operator+=(const T v) noexcept {alpha += v, color += v; return *this;}
constexpr AlphaColor& operator-=(const T v) noexcept {alpha -= v, color -= v; return *this;}
constexpr AlphaColor& operator*=(const T v) noexcept {alpha *= v, color *= v; return *this;}
constexpr AlphaColor& operator/=(const T v) noexcept {alpha /= v, color /= v; return *this;}
};
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// AlphaColor<T, A, C> - GOBAL FUNCTIONS
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator+(AlphaColor<T, A, C> ac) noexcept
{
return ac;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator-(AlphaColor<T, A, C> ac) noexcept
{
return {-ac.alpha, -ac.color};
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator+(AlphaColor<T, A, C> ac1, const AlphaColor<T, A, C>& ac2) noexcept
{
return ac1 += ac2;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator-(AlphaColor<T, A, C> ac1, const AlphaColor<T, A, C>& ac2) noexcept
{
return ac1 -= ac2;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator*(AlphaColor<T, A, C> ac1, const AlphaColor<T, A, C>& ac2) noexcept
{
return ac1 *= ac2;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator/(AlphaColor<T, A, C> ac1, const AlphaColor<T, A, C>& ac2) noexcept
{
return ac1 /= ac2;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator+(AlphaColor<T, A, C> ac, const T& v) noexcept
{
return ac += v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator+(const T& v, AlphaColor<T, A, C> ac) noexcept
{
return ac += v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator-(AlphaColor<T, A, C> ac, const T& v) noexcept
{
return ac -= v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator-(const T& v, AlphaColor<T, A, C> ac) noexcept
{
return {v - ac.alpha, v - ac.color};
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator*(AlphaColor<T, A, C> ac, const T& v) noexcept
{
return ac *= v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator*(const T& v, AlphaColor<T, A, C> ac) noexcept
{
return ac *= v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator/(AlphaColor<T, A, C> ac, const T& v) noexcept
{
return ac /= v;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T, class A, class C>
constexpr AlphaColor<T, A, C> operator/(const T& v, AlphaColor<T, A, C> ac) noexcept
{
return {v / ac.alpha, v / ac.color};
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
} //namespace ama
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#endif // AMA_ALPHA_COLOR_H
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------