#############################################################################
# Geometry.pm
# Maps the rectangles of the colorMix image.
#############################################################################
package Color::Geometry;

require Exporter;

our @ISA = 'Exporter';

our @EXPORT_OK = qw{
    cMixGeom
};


############
# cMixGeom
#   Creates a map of the rectangles of the colorMix image.
sub cMixGeom {
    my $opt   = shift;
    my $want  = shift;
    my $index = shift;

    my $height = $opt->{'height'};
    my $width  = $opt->{'width'};
    my $x_panel_orig = ( 1 + $height );
    my $y_panel_orig = ( 1 );
    my $x_panel_extn = ( $width - 2 );
    my $y_panel_extn = ( $height - 2 );
    my $x_pclr = ( $x_panel_extn - $x_panel_orig - 1 );
    my $y_pclr = ( $x_pclr );
    my $x_shade_orig = ( $x_panel_orig + 1);
    my $y_shade_orig = ( $y_pclr + $y_panel_orig + 3 );
    my $x_shade_extn = ( $x_pclr + $x_shade_orig - 1 );
    my $y_shade_extn = ( $y_panel_extn - 1 );
    my $x_shade = ( $x_pclr );
    my $y_shades = ( $y_shade_extn - $y_shade_orig );
    my $y_shade = int( $y_shades / 19 );

    if ( q{height} eq $want ) {
        return $height;
    }
    elsif ( q{width} eq $want ) {
        return $width;
    }
    elsif ( q{infobox} eq $want ) {
        if ( wantarray ) {
            return ( $x_panel_orig, $y_panel_orig
                   , $x_panel_extn, $y_panel_extn );
        }
        else {
            # Width
            return ( $x_panel_extn - $x_panel_orig );
        }
    }
    elsif ( q{colorbox} eq $want ) {
        if ( wantarray ) {
            return ( 1 + $x_panel_orig, 1 + $y_panel_orig
                   , $x_pclr + $x_panel_orig
                   , $y_pclr + $y_panel_orig );
        }
        else {
            # Width
            return ( $x_pclr );
        }
    }
    elsif ( ( q{shadebox} eq $want )
            && ( 0 <= $index ) 
            && ( 19 >= $index ) 
          ) {
        if ( wantarray ) {
            return (
                ($x_shade_orig)
              , ( (    $index  * $y_shade) + ( $y_shade_orig ) )
              , ($x_shade_extn)
              , ( ( (1+$index) * $y_shade) + ( $y_shade_orig - 2 ) )
            );
        }
    }
}

1;
# EOF Convert.pm
