This is a utility module used by Color::TupleEncode.
This module provides the default color encoding scheme.
Therefore,
if you do not explicitly set the encoding method in a Color::TupleEncode object explicitly,
it will be set to Color::TupleEncode::Baran

To change or set the encoding method,
pass the method directly or as an option in new() or set with set_options().
new()

Given the tuple (a,b,c), let the characteristic hues for each tuple be ha,hb,hc. Form the differences

dab = | a - b |
dac = | a - c |
dbc = | b - c |

The hue is calculated along the gradient formed by the two components that form the largest difference. For example, if dac is the largest difference, the final hue lies along the gradient formed by (ha,hc).

The effect of this encoding is to emphasize the component that is the most different.

If two components equal and the third is very different, e.g. (0.1,1,0.1) then the encoded hue will the characteristic hue of the largest component. In this case h = hb = 120.

When the difference in the close values is small (0.1,1,0.15) the encoded hue will be very close to the characterstic hue of the most different component. In this case, the hue will be very close to hb = 120 - the hue is h = 113.

When the values are spread equally (0.3,0.6,0.9) the hue will be half way between the characteristic hues of the components that form the largest difference. In this case, the hue will lie between ha and hc - the hue is h = 300.

would result in saturation varying from its minimum to maximum value from dmin = 0.25 to dmax = 0.75. Depending on the magnitude of the difference in components in your tuples, you will want to adjust the difference range to match.

If the -relative option is used, then a relative correction is applied to d if d > 0 before saturation is calculated. Note that with this correction, d will always be in the range [ 0, 1 ].

drel = d / max( |a|, |b|, |c|, d )
d <- drel

Saturation can be constrained within a range [ min, max ] by setting the min,max parameters. These values must be in the range [0,1].

The Baran et al. publication in which this encoding was introduced suggests to use the product of absolute and relative saturations as the final saturation. This can be done by calculating two values of saturation, one with the -saturation={relative=>0}> option, and one with -saturation={relative=>1}>.

You can combine saturation and value encoding together. See the "Value" section.

The effect will be to adjust saturation when the largest component difference is in the range [0,2] (from s = 0 to s = 1). Thus as the difference grows, the color becomes more saturated.

In the range [ 2, 5 ], s = 1 since the range is beyond dmax set for saturation. However, in this higher range the value will be adjusted from min = 1 to max = 0. Thus, as the difference grows, the color gets darker.

Below is an example of the HSV values for various ( x, y, z) using the options above.