001/* [{
002Copyright 2010 Nicolas Carranza <nicarran at gmail.com>
003
004This file is part of jpen.
005
006jpen is free software: you can redistribute it and/or modify
007it under the terms of the GNU Lesser General Public License as published by
008the Free Software Foundation, either version 3 of the License,
009or (at your option) any later version.
010
011jpen is distributed in the hope that it will be useful,
012but WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014GNU Lesser General Public License for more details.
015
016You should have received a copy of the GNU Lesser General Public License
017along with jpen.  If not, see <http://www.gnu.org/licenses/>.
018}] */
019package jpen.internal;
020
021public class Range {
022        public final float min;
023        public final float max;
024        private final float range;
025
026        public Range(float min, float max) {
027                if(min<0 && max>0 && Math.abs(max+min)==1){ // trick to avoid loosing the tool center
028                        if(max>-min)
029                                min=-max;
030                        else
031                                max=-min;
032                }
033                this.min=min;
034                this.max=max;
035                this.range=max-min;
036        }
037        
038        public final float getRangedValue(float value) {
039                return (value-min)/range;
040        }
041
042        @Override
043        public String toString() {
044                return "[PLevel.Range: "+min+", "+max+"]";
045        }
046}