@@ -86,7 +86,8 @@ export class FastColor {
8686
8787 // HSV privates
8888 private _h ?: number ;
89- private _s ?: number ;
89+ private _hsl_s ?: number ;
90+ private _hsv_s ?: number ;
9091 private _l ?: number ;
9192 private _v ?: number ;
9293
@@ -143,7 +144,8 @@ export class FastColor {
143144 this . b = input . b ;
144145 this . a = input . a ;
145146 this . _h = input . _h ;
146- this . _s = input . _s ;
147+ this . _hsl_s = input . _hsl_s ;
148+ this . _hsv_s = input . _hsv_s ;
147149 this . _l = input . _l ;
148150 this . _v = input . _v ;
149151 } else if ( matchFormat ( 'rgb' ) ) {
@@ -235,28 +237,28 @@ export class FastColor {
235237 }
236238
237239 getHSVSaturation ( ) : number {
238- if ( typeof this . _s === 'undefined' ) {
240+ if ( typeof this . _hsv_s === 'undefined' ) {
239241 const delta = this . getMax ( ) - this . getMin ( ) ;
240242 if ( delta === 0 ) {
241- this . _s = 0 ;
243+ this . _hsv_s = 0 ;
242244 } else {
243- this . _s = delta / this . getMax ( ) ;
245+ this . _hsv_s = delta / this . getMax ( ) ;
244246 }
245247 }
246- return this . _s ;
248+ return this . _hsv_s ;
247249 }
248250
249251 getHSLSaturation ( ) : number {
250- if ( typeof this . _s === 'undefined' ) {
252+ if ( typeof this . _hsl_s === 'undefined' ) {
251253 const delta = this . getMax ( ) - this . getMin ( ) ;
252254 if ( delta === 0 ) {
253- this . _s = 0 ;
255+ this . _hsl_s = 0 ;
254256 } else {
255257 const l = this . getLightness ( ) ;
256- this . _s = ( delta / 255 ) / ( 1 - Math . abs ( 2 * l - 1 ) ) ;
258+ this . _hsl_s = ( delta / 255 ) / ( 1 - Math . abs ( 2 * l - 1 ) ) ;
257259 }
258260 }
259- return this . _s ;
261+ return this . _hsl_s ;
260262 }
261263
262264 getLightness ( ) : number {
@@ -502,8 +504,8 @@ export class FastColor {
502504 }
503505
504506 private fromHsl ( { h, s, l, a } : OptionalA < HSL > ) : void {
505- this . _h = h = h % 360 ;
506- this . _s = s ;
507+ this . _h = h = ( ( h % 360 ) + 360 ) % 360 ;
508+ this . _hsl_s = s ;
507509 this . _l = l ;
508510 this . a = typeof a === 'number' ? a : 1 ;
509511
@@ -550,8 +552,8 @@ export class FastColor {
550552 }
551553
552554 private fromHsv ( { h, s, v, a } : OptionalA < HSV > ) : void {
553- this . _h = h % 360 ;
554- this . _s = s ;
555+ this . _h = h = ( ( h % 360 ) + 360 ) % 360 ;
556+ this . _hsv_s = s ;
555557 this . _v = v ;
556558 this . a = typeof a === 'number' ? a : 1 ;
557559
0 commit comments