@@ -2,90 +2,350 @@ package vecmatlib.color
22
33import vecmatlib .Float3
44
5+ /**
6+ * Class that represents a color as a three-dimensional float tuple whose components are in a range from 0.0 to 1.0.
7+ * Values outside the (0.0, 1.0) range are allowed.
8+ *
9+ * @constructor Constructs a color with the three given RGB components
10+ * @param r Red component of the color in a range from 0.0 to 1.0
11+ * @param g Green component of the color in a range from 0.0 to 1.0
12+ * @param b Blue component of the color in a range from 0.0 to 1.0
13+ */
514case class Color3f (r : Float , g : Float , b : Float ) extends Float3 {
6-
15+
16+ /**
17+ * Returns a new color resulting from adding the given color to this one.
18+ *
19+ * @param r Red component of the color to add
20+ * @param g Green component of the color to add
21+ * @param b Blue component of the color to add
22+ * @return A color resulting from adding the given color to this one
23+ */
724 def + (r : Float , g : Float , b : Float ): Color3f = Color3f (this .r + r, this .g + g, this .b + b)
8-
25+
26+ /**
27+ * Returns a new color resulting from adding the given color to this one.
28+ * The resulting alpha value is the same as the given one.
29+ *
30+ * @param r Red component of the color to add
31+ * @param g Green component of the color to add
32+ * @param b Blue component of the color to add
33+ * @param a Alpha component of the color to add
34+ * @return A color resulting from adding the given color to this one
35+ */
936 def + (r : Float , g : Float , b : Float , a : Float ): Color4f = Color4f (this .r + r, this .g + g, this .b + b, a)
10-
37+
38+ /**
39+ * Returns a new color resulting from adding the given color to this one.
40+ *
41+ * @param c The color to add
42+ * @return A color resulting from adding the given color to this one
43+ */
1144 def + (c : Color3f ): Color3f = this + (c.r, c.g, c.b)
12-
45+
46+ /**
47+ * Returns a new color resulting from adding the given color to this one.
48+ * The resulting alpha value is the same as the given one.
49+ *
50+ * @param c The color to add
51+ * @return A color resulting from adding the given color to this one
52+ */
1353 def + (c : Color4f ): Color4f = this + (c.r, c.g, c.b, c.a)
14-
54+
55+ /**
56+ * Returns a new color resulting from adding the given color to this one.
57+ *
58+ * This method can be used in place of the '+' operator for better interoperability with Java.
59+ *
60+ * @param r Red component of the color to add
61+ * @param g Green component of the color to add
62+ * @param b Blue component of the color to add
63+ * @return A color resulting from adding the given color to this one
64+ */
1565 def add (r : Float , g : Float , b : Float ): Color3f = this + (r, g, b)
16-
66+
67+ /**
68+ * Returns a new color resulting from adding the given color to this one.
69+ * The resulting alpha value is the same as the given one.
70+ *
71+ * This method can be used in place of the '+' operator for better interoperability with Java.
72+ *
73+ * @param r Red component of the color to add
74+ * @param g Green component of the color to add
75+ * @param b Blue component of the color to add
76+ * @param a Alpha component of the color to add
77+ * @return A color resulting from adding the given color to this one
78+ */
1779 def add (r : Float , g : Float , b : Float , a : Float ): Color4f = this + (r, g, b, a)
18-
80+
81+ /**
82+ * Returns a new color resulting from adding the given color to this one.
83+ *
84+ * This method can be used in place of the '+' operator for better interoperability with Java.
85+ *
86+ * @param c The color to add
87+ * @return A color resulting from adding the given color to this one
88+ */
1989 def add (c : Color3f ): Color3f = this + c
20-
90+
91+ /**
92+ * Returns a new color resulting from adding the given color to this one.
93+ * The resulting alpha value is the same as the given one.
94+ *
95+ * This method can be used in place of the '+' operator for better interoperability with Java.
96+ *
97+ * @param c The color to add
98+ * @return A color resulting from adding the given color to this one
99+ */
21100 def add (c : Color4f ): Color4f = this + c
22101
102+ /**
103+ * Returns a new color resulting from subtracting the given color from this one.
104+ *
105+ * @param r Red component of the color to subtract
106+ * @param g Green component of the color to subtract
107+ * @param b Blue component of the color to subtract
108+ * @return A color resulting from subtracting the given color from this one
109+ */
23110 def - (r : Float , g : Float , b : Float ): Color3f = Color3f (this .r - r, this .g - g, this .b - b)
24111
112+ /**
113+ * Returns a new color resulting from subtracting the given color from this one.
114+ * The resulting alpha value is 1 minus the given one.
115+ *
116+ * @param r Red component of the color to subtract
117+ * @param g Green component of the color to subtract
118+ * @param b Blue component of the color to subtract
119+ * @param a Alpha component of the color to subtract
120+ * @return A color resulting from subtracting the given color from this one
121+ */
25122 def - (r : Float , g : Float , b : Float , a : Float ): Color4f = Color4f (this .r - r, this .g - g, this .b - b, 1.0f - a)
26123
124+ /**
125+ * Returns a new color resulting from subtracting the given color from this one.
126+ *
127+ * @param c The color to subtract
128+ * @return A color resulting from subtracting the given color from this one
129+ */
27130 def - (c : Color3f ): Color3f = this - (c.r, c.g, c.b)
28131
132+ /**
133+ * Returns a new color resulting from subtracting the given color from this one.
134+ * The resulting alpha value is 1 minus the given one.
135+ *
136+ * @param c The color to subtract
137+ * @return A color resulting from subtracting the given color from this one
138+ */
29139 def - (c : Color4f ): Color4f = this - (c.r, c.g, c.b, c.a)
30140
141+ /**
142+ * Returns a new color resulting from subtracting the given color from this one.
143+ *
144+ * This method can be used in place of the '-' operator for better interoperability with Java.
145+ *
146+ * @param r Red component of the color to subtract
147+ * @param g Green component of the color to subtract
148+ * @param b Blue component of the color to subtract
149+ * @return A color resulting from subtracting the given color from this one
150+ */
31151 def subtract (r : Float , g : Float , b : Float ): Color3f = this - (r, g, b)
32152
153+ /**
154+ * Returns a new color resulting from subtracting the given color from this one.
155+ * The resulting alpha value is 1 minus the given one.
156+ *
157+ * This method can be used in place of the '-' operator for better interoperability with Java.
158+ *
159+ * @param r Red component of the color to subtract
160+ * @param g Green component of the color to subtract
161+ * @param b Blue component of the color to subtract
162+ * @param a Alpha component of the color to subtract
163+ * @return A color resulting from subtracting the given color from this one
164+ */
33165 def subtract (r : Float , g : Float , b : Float , a : Float ): Color4f = this - (r, g, b, a)
34166
167+ /**
168+ * Returns a new color resulting from subtracting the given color from this one.
169+ *
170+ * This method can be used in place of the '-' operator for better interoperability with Java.
171+ *
172+ * @param c The color to subtract
173+ * @return A color resulting from subtracting the given color from this one
174+ */
35175 def subtract (c : Color3f ): Color3f = this - c
36176
177+ /**
178+ * Returns a new color resulting from subtracting the given color from this one.
179+ * The resulting alpha value is 1 minus the given one.
180+ *
181+ * This method can be used in place of the '-' operator for better interoperability with Java.
182+ *
183+ * @param c The color to subtract
184+ * @return A color resulting from subtracting the given color from this one
185+ */
37186 def subtract (c : Color4f ): Color4f = this - c
38-
187+
188+ /**
189+ * Returns a new color resulting from multiplying every component of this color with the given ones.
190+ *
191+ * @param r Red component of the color
192+ * @param g Green component of the color
193+ * @param b Blue component of the color
194+ * @return A color resulting from multiplying every component of this color with the given ones
195+ */
39196 def * (r : Float , g : Float , b : Float ): Color3f = Color3f (this .r * r, this .g * g, this .b * b)
40-
197+
198+ /**
199+ * Returns a new color resulting from multiplying every component of this color with the given ones.
200+ * The resulting alpha value is the same as the given one.
201+ *
202+ * @param r Red component of the color
203+ * @param g Green component of the color
204+ * @param b Blue component of the color
205+ * @param a Alpha component of the color
206+ * @return A color resulting from multiplying every component of this color with the given ones
207+ */
41208 def * (r : Float , g : Float , b : Float , a : Float ): Color4f = Color4f (this .r * r, this .g * g, this .b * b, a)
42-
209+
210+ /**
211+ * Returns a new color resulting from the component-wise multiplication of this color with the given one.
212+ *
213+ * @param c The given color
214+ * @return A color resulting from the component-wise multiplication of this color with the given one
215+ */
43216 def * (c : Color3f ): Color3f = this * (c.r, c.g, c.b)
44-
217+
218+ /**
219+ * Returns a new color resulting from the component-wise multiplication of this color with the given one.
220+ * The resulting alpha value is the same as the given one.
221+ *
222+ * @param c The given color
223+ * @return A color resulting from the component-wise multiplication of this color with the given one
224+ */
45225 def * (c : Color4f ): Color4f = this * (c.r, c.g, c.b, c.a)
46-
226+
227+ /**
228+ * Returns a new color resulting from multiplying every component of this color with the given ones.
229+ *
230+ * This method can be used in place of the '*' operator for better interoperability with Java.
231+ *
232+ * @param r Red component of the color
233+ * @param g Green component of the color
234+ * @param b Blue component of the color
235+ * @return A color resulting from multiplying every component of this color with the given ones
236+ */
47237 def blend (r : Float , g : Float , b : Float ): Color3f = this * (r, g, b)
48-
238+
239+ /**
240+ * Returns a new color resulting from multiplying every component of this color with the given ones.
241+ * The resulting alpha value is the same as the given one.
242+ *
243+ * This method can be used in place of the '*' operator for better interoperability with Java.
244+ *
245+ * @param r Red component of the color
246+ * @param g Green component of the color
247+ * @param b Blue component of the color
248+ * @param a Alpha component of the color
249+ * @return A color resulting from multiplying every component of this color with the given ones
250+ */
49251 def blend (r : Float , g : Float , b : Float , a : Float ): Color4f = this * (r, g, b, a)
50-
252+
253+ /**
254+ * Returns a new color resulting from the component-wise multiplication of this color with the given one.
255+ *
256+ * This method can be used in place of the '*' operator for better interoperability with Java.
257+ *
258+ * @param c The given color
259+ * @return A color resulting from the component-wise multiplication of this color with the given one
260+ */
51261 def blend (c : Color3f ): Color3f = this * c
52-
262+
263+ /**
264+ * Returns a new color resulting from the component-wise multiplication of this color with the given one.
265+ * The resulting alpha value is the same as the given one.
266+ *
267+ * This method can be used in place of the '*' operator for better interoperability with Java.
268+ *
269+ * @param c The given color
270+ * @return A color resulting from the component-wise multiplication of this color with the given one
271+ */
53272 def blend (c : Color4f ): Color4f = this * c
54-
273+
274+ /**
275+ * Returns a new color resulting from multiplying all the components by the given scalar.
276+ *
277+ * @param k The scalar by which this color is multiplied
278+ * @return A new color resulting of multiplying all the components of this color by the given scalar
279+ */
55280 def * (k : Float ): Color3f = this * (k, k, k)
56-
281+
282+ /**
283+ * Returns a new color resulting from multiplying all the components by the given scalar.
284+ *
285+ * This method can be used in place of the '*' operator for better interoperability with Java.
286+ *
287+ * @param k The scalar by which this color is multiplied
288+ * @return A new color resulting of multiplying all the components of this color by the given scalar
289+ */
57290 def multiply (k : Float ): Color3f = this * k
58-
291+
292+ /**
293+ * Returns the inverted color `(1.0 - r, 1.0 - g, 1.0 - b)`.
294+ *
295+ * @return The inverted color.
296+ */
59297 def invert : Color3f = Color3f (1.0f - this .r, 1.0f - this .g, 1.0f - this .b)
60-
298+
299+ /**
300+ * Returns a new color resulting from making this color darker by the specified percentage.
301+ *
302+ * @param k Ratio from 0.0 to 1.0
303+ * @return A color resulting from making this color darker by the specified percentage
304+ */
61305 def darker (k : Float ): Color3f = Color3f (this .r * (1.0f - k), this .g * (1.0f - k), this .b * (1.0f - k))
62-
306+
307+ /**
308+ * Returns a new color resulting from making this color lighter by the specified percentage.
309+ *
310+ * @param k Ratio from 0.0 to 1.0
311+ * @return A color resulting from making this color lighter by the specified percentage
312+ */
63313 def lighter (k : Float ): Color3f = Color3f (this .r + (1.0f - this .r) * k, this .g + (1.0f - this .g) * k, this .b + (1.0f - this .b) * k)
64314
315+ /**
316+ * Returns the linear interpolation with another color.
317+ *
318+ * @param to The color to interpolate to
319+ * @param weight Interpolation factor between 0.0 and 1.0
320+ * @return The linear interpolation between this color and the given one
321+ */
65322 def lerp (to : Color3f , weight : Float ): Color3f = (this * (1.0f - weight)) + (to * weight)
66-
323+
67324 /**
68- * X component .
325+ * Alias for 'r' .
69326 *
70- * @return The X component of this tuple
327+ * @return The red component of this color
71328 */
72329 override def x : Float = this .r
73330
74331 /**
75- * Y component .
332+ * Alias for 'g' .
76333 *
77- * @return The Y component of this tuple
334+ * @return The green component of this color
78335 */
79336 override def y : Float = this .g
80337
81338 /**
82- * Z component .
339+ * Alias for 'b' .
83340 *
84- * @return The Z component of this tuple
341+ * @return The blue component of this color
85342 */
86343 override def z : Float = this .b
87344}
88345
346+ /**
347+ * Color4f companion object.
348+ */
89349object Color3f {
90350
91351 lazy val AliceBlue : Color3f = Color3f (0.941176f , 0.972549f , 1.0f )
0 commit comments