@@ -219,14 +219,20 @@ export class Color {
219
219
220
220
/**
221
221
* Creates a new Color instance.
222
- * @param [r] - The red component [0 .. 255]. Defaults to 0.
223
- * @param [g] - The green component [0 .. 255]. Defaults to 0.
224
- * @param [b] - The blue component [0 .. 255]. Defaults to 0.
225
- * @param [ alpha] - The alpha value [0.0 .. 1.0]. Defaults to 1.
222
+ * @param r - A Color object or the red component [0 .. 255]. Defaults to 0.
223
+ * @param g - The green component [0 .. 255]. Defaults to 0.
224
+ * @param b - The blue component [0 .. 255]. Defaults to 0.
225
+ * @param alpha - The alpha value [0.0 .. 1.0]. Defaults to 1.
226
226
*/
227
- constructor ( r = 0 , g = 0 , b = 0 , alpha = 1.0 ) {
228
- this . glArray = new Float32Array ( [ 0 , 0 , 0 , 1 ] ) ;
229
- this . setColor ( r , g , b , alpha ) ;
227
+ constructor ( r : Color | number = 0 , g = 0 , b = 0 , alpha = 1.0 ) {
228
+ if ( typeof r === "number" ) {
229
+ this . glArray = new Float32Array ( [ 0 , 0 , 0 , 1 ] ) ;
230
+ this . setColor ( r , g , b , alpha ) ;
231
+ } else if ( typeof r === "object" ) {
232
+ this . glArray = r . glArray . slice ( ) ;
233
+ } else {
234
+ throw new Error ( "Color: invalid parameter" ) ;
235
+ }
230
236
}
231
237
232
238
/**
@@ -242,7 +248,7 @@ export class Color {
242
248
* @param value - The red component [0 .. 255].
243
249
*/
244
250
set r ( value ) {
245
- this . glArray [ 0 ] = clamp ( ~ ~ value || 0 , 0 , 255 ) / 255.0 ;
251
+ this . glArray [ 0 ] = clamp ( value , 0 , 255 ) / 255.0 ;
246
252
}
247
253
248
254
/**
@@ -258,7 +264,7 @@ export class Color {
258
264
* @param value - The green component [0 .. 255].
259
265
*/
260
266
set g ( value ) {
261
- this . glArray [ 1 ] = clamp ( ~ ~ value || 0 , 0 , 255 ) / 255.0 ;
267
+ this . glArray [ 1 ] = clamp ( value , 0 , 255 ) / 255.0 ;
262
268
}
263
269
264
270
/**
@@ -274,7 +280,7 @@ export class Color {
274
280
* @param value - The blue component [0 .. 255].
275
281
*/
276
282
set b ( value ) {
277
- this . glArray [ 2 ] = clamp ( ~ ~ value || 0 , 0 , 255 ) / 255.0 ;
283
+ this . glArray [ 2 ] = clamp ( value , 0 , 255 ) / 255.0 ;
278
284
}
279
285
280
286
/**
@@ -290,7 +296,7 @@ export class Color {
290
296
* @param value - The alpha component [0.0 .. 1.0].
291
297
*/
292
298
set alpha ( value ) {
293
- this . glArray [ 3 ] = clamp ( + value , 0 , 1.0 ) ;
299
+ this . glArray [ 3 ] = clamp ( value , 0 , 1.0 ) ;
294
300
}
295
301
296
302
/**
@@ -410,7 +416,7 @@ export class Color {
410
416
* @returns Reference to the newly cloned object.
411
417
*/
412
418
clone ( ) {
413
- return colorPool . get ( ) . copy ( this ) ;
419
+ return colorPool . get ( this as Color ) ;
414
420
}
415
421
416
422
/**
@@ -693,7 +699,7 @@ export class Color {
693
699
export const colorPool = createPool <
694
700
Color ,
695
701
[
696
- r ?: number | undefined ,
702
+ r ?: number | Color | undefined ,
697
703
g ?: number | undefined ,
698
704
b ?: number | undefined ,
699
705
alpha ?: number | undefined ,
@@ -703,7 +709,7 @@ export const colorPool = createPool<
703
709
return {
704
710
instance : color ,
705
711
reset ( r = 0 , g = 0 , b = 0 , alpha = 1 ) {
706
- color . setColor ( r , g , b , alpha ) ;
712
+ color . setColor ( r as number , g , b , alpha ) ;
707
713
} ,
708
714
} ;
709
715
} ) ;
0 commit comments