Subject: bug#12559: closed (Re: bug#12559: color-hsl-to-rgb doesn't handle hue range overflow)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 06 Oct 2012 02:23:03 +0000

Your bug report

#12559: color-hsl-to-rgb doesn't handle hue range overflow

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
12559: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12559
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#12559: color-hsl-to-rgb doesn't handle hue range overflow
From: Glenn Morris <[email-masked]>
To: [email-masked]
Date: Fri, 05 Oct 2012 22:21:51 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Version: 24.3

Thanks; applied to trunk.

Subject: color-hsl-to-rgb doesn't handle hue range overflow
From: Julian Scheid <[email-masked]>
To: [email-masked]
Date: Tue, 02 Oct 2012 15:40:54 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

`color-hsl-to-rgb' manipulates hue without dealing with range overflow
or underflow.  This takes small and large hue values outside of the
range expected by `color-hue-to-rgb' and causes incorrect results for
such values:

    (color-rgb-to-hsl 0.65 0.25 0.75)
    ;; -> (0.7999999999999999 0.5 0.5)

    (apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.25 0.75))
    ;; -> (0.25 0.25 0.75)

    (color-rgb-to-hsl 0.65 0.75 0.25)
    ;; -> (0.20000000000000004 0.5 0.5)

    (apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.75 0.25))
    ;; -> (0.6499999999999999 0.75 -0.1499999999999998)

The patch below makes the conversion work as expected:

    (apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.25 0.75))
    ;; -> (0.6499999999999999 0.25 0.75)

    (apply 'color-hsl-to-rgb (color-rgb-to-hsl 0.65 0.75 0.25))
    ;; -> (0.6499999999999999 0.75 0.25)

2012-10-02  Julian Scheid  <[email-masked]>

	* color.el (color-hsl-to-rgb): Fix for incorrect results for
        small and large hue values.

=== modified file 'lisp/color.el'
*** lisp/color.el	2012-08-13 19:10:35 +0000
--- lisp/color.el	2012-10-02 13:16:32 +0000
*************** Return a list (RED, GREEN, BLUE) which e
*** 116,124 ****
  		 (- (+ L S) (* L S))))
  	   (m1 (- (* 2.0 L) m2)))
        (list
!        (color-hue-to-rgb m1 m2 (+ H (/ 1.0 3)))
         (color-hue-to-rgb m1 m2 H)
!        (color-hue-to-rgb m1 m2 (- H (/ 1.0 3)))))))
  
  (defun color-complement-hex (color)
    "Return the color that is the complement of COLOR, in hexadecimal format."
--- 116,124 ----
  		 (- (+ L S) (* L S))))
  	   (m1 (- (* 2.0 L) m2)))
        (list
!        (color-hue-to-rgb m1 m2 (mod (+ H (/ 1.0 3)) 1))
         (color-hue-to-rgb m1 m2 H)
!        (color-hue-to-rgb m1 m2 (mod (- H (/ 1.0 3)) 1))))))
  
  (defun color-complement-hex (color)
    "Return the color that is the complement of COLOR, in hexadecimal format."