001    /*
002    *
003    
004    Licensed under the Apache License, Version 2.0 (the "License");
005    you may not use this file except in compliance with the License.
006    You may obtain a copy of the License at
007    
008       http://www.apache.org/licenses/LICENSE-2.0
009    
010    Unless required by applicable law or agreed to in writing, software
011    distributed under the License is distributed on an "AS IS" BASIS,
012    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013    See the License for the specific language governing permissions and
014    limitations under the License.
015    */
016    
017    package railo.runtime.img.math;
018    
019    public class MathFunction1D implements Function1D {
020    
021            public final static int SIN = 1;
022            public final static int COS = 2;
023            public final static int TAN = 3;
024            public final static int SQRT = 4;
025            public final static int ASIN = -1;
026            public final static int ACOS = -2;
027            public final static int ATAN = -3;
028            public final static int SQR = -4;
029    
030            private int operation;
031            
032            public MathFunction1D(int operation) {
033                    this.operation = operation;
034            }
035            
036            public float evaluate(float v) {
037                    switch (operation) {
038                    case SIN:
039                            return (float)Math.sin(v);
040                    case COS:
041                            return (float)Math.cos(v);
042                    case TAN:
043                            return (float)Math.tan(v);
044                    case SQRT:
045                            return (float)Math.sqrt(v);
046                    case ASIN:
047                            return (float)Math.asin(v);
048                    case ACOS:
049                            return (float)Math.acos(v);
050                    case ATAN:
051                            return (float)Math.atan(v);
052                    case SQR:
053                            return v*v;
054                    }
055                    return v;
056            }
057    }
058