001/*
002 *                  BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on Aug 3, 2007
021 */
022package org.biojava.nbio.structure.gui.util.color;
023
024/**
025 * Performs a sqrt transform on input before passing the values off to another
026 * colorMapper.
027 *
028 * For instance, to map [0^2, 10^2] to a rainbow gradient, use
029 *
030 * new LogColorMapper(GradientMapper.getGradientMapper(GradientMapper.RAINBOW_GRADIENT, 0, 10))
031 *
032 * @author Spencer Bliven
033 *
034 */
035public class SqrtColorMapper extends ContinuousColorMapperTransform {
036
037        /**
038         * Creates a new SqrtColorMapper.
039         * @param sqrtspaceMapper
040         */
041        public SqrtColorMapper(ContinuousColorMapper sqrtspaceMapper) {
042                super(sqrtspaceMapper);
043        }
044
045        /**
046         * Return sqrt(value).
047         * If value is negative, return the color corresponding to negative infinity.
048         *
049         * @param value Value to be mapped
050         * @return sqrt(value), or NEGATIVE_INFINITY
051         * @see org.biojava.nbio.structure.gui.util.color.ContinuousColorMapper#getColor(double)
052         */
053        @Override
054        public double transform(double value) {
055                double sqrtValue = Double.NEGATIVE_INFINITY;
056                if(value >= 0)
057                        sqrtValue = Math.sqrt(value);
058
059                return sqrtValue;
060        }
061
062}