namespace mimas {

template <typename T>
double rgba<T>::getHue(void) const
{
    /**returns a HUE value for the pixel, in the range 0-360.
    *hue is 'supposed' to represent the colour of a pixel, once brightness levels
    *and so on have been removed. Returns -1 for an undefined hue.
    */
    T   min,max,delta;
    double h;

    // calculate the hue
    min = r;
    if (g<r && g<b)     min=g;
    if (b<r && b<g)     min=b;
    max = r;
    if (g>r && g>b)     max=g;
    if (b>r && b>g)     max=b;

    if (min==max)       //undefined hue
    { return (T) -1; }

/* algo 2... */
    delta = max - min;
    if ( r == max )
        h = ((double)( g - b )) / (double) delta;
                                        // between yellow & magenta
    else if( g == max )
        h = 2.0 + ((double)( b - r )) / (double) delta;
                                        // between cyan & yellow
    else
        h = 4.0 + ((double)( r - g )) / (double) delta;
                                        // between magenta & cyan

    h *= 60;                            // degrees
    if( h < 0 )
        h += 360;
        
    return h;
}

template <typename T>
double rgba<T>::getSaturation(void) const
{
    /**returns the saturation value for the pixel.
     *saturation lies between 0-1
     */
    T   min,max,delta;
    double s;

    min = r;
    if (g<r && g<b)     min=g;
    if (b<r && b<g)     min=b;
    max = r;
    if (g>r && g>b)     max=g;
    if (b>r && b>g)     max=b;

    s = ((double)(max - min))/(double)max;

    return s;
}

}