Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.util;
     18 
     19 import com.android.layoutlib.bridge.impl.DelegateManager;
     20 import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
     21 
     22 /**
     23  * Delegate implementing the native methods of android.util.FloatMath
     24  *
     25  * Through the layoutlib_create tool, the original native methods of FloatMath have been replaced
     26  * by calls to methods of the same name in this delegate class.
     27  *
     28  * Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
     29  * around to map int to instance of the delegate.
     30  *
     31  */
     32 /*package*/ final class FloatMath_Delegate {
     33 
     34     /** Prevents instantiation. */
     35     private FloatMath_Delegate() {}
     36 
     37     /**
     38      * Returns the float conversion of the most positive (i.e. closest to
     39      * positive infinity) integer value which is less than the argument.
     40      *
     41      * @param value to be converted
     42      * @return the floor of value
     43      */
     44     @LayoutlibDelegate
     45     /*package*/ static float floor(float value) {
     46         return (float)Math.floor(value);
     47     }
     48 
     49     /**
     50      * Returns the float conversion of the most negative (i.e. closest to
     51      * negative infinity) integer value which is greater than the argument.
     52      *
     53      * @param value to be converted
     54      * @return the ceiling of value
     55      */
     56     @LayoutlibDelegate
     57     /*package*/ static float ceil(float value) {
     58         return (float)Math.ceil(value);
     59     }
     60 
     61     /**
     62      * Returns the closest float approximation of the sine of the argument.
     63      *
     64      * @param angle to compute the cosine of, in radians
     65      * @return the sine of angle
     66      */
     67     @LayoutlibDelegate
     68     /*package*/ static  float sin(float angle) {
     69         return (float)Math.sin(angle);
     70     }
     71 
     72     /**
     73      * Returns the closest float approximation of the cosine of the argument.
     74      *
     75      * @param angle to compute the cosine of, in radians
     76      * @return the cosine of angle
     77      */
     78     @LayoutlibDelegate
     79     /*package*/ static float cos(float angle) {
     80         return (float)Math.cos(angle);
     81     }
     82 
     83     /**
     84      * Returns the closest float approximation of the square root of the
     85      * argument.
     86      *
     87      * @param value to compute sqrt of
     88      * @return the square root of value
     89      */
     90     @LayoutlibDelegate
     91     /*package*/ static float sqrt(float value) {
     92         return (float)Math.sqrt(value);
     93     }
     94 
     95     /**
     96      * Returns the closest float approximation of the raising "e" to the power
     97      * of the argument.
     98      *
     99      * @param value to compute the exponential of
    100      * @return the exponential of value
    101      */
    102     @LayoutlibDelegate
    103     /*package*/ static float exp(float value) {
    104         return (float)Math.exp(value);
    105     }
    106 
    107     /**
    108      * Returns the closest float approximation of the result of raising {@code
    109      * x} to the power of {@code y}.
    110      *
    111      * @param x the base of the operation.
    112      * @param y the exponent of the operation.
    113      * @return {@code x} to the power of {@code y}.
    114      */
    115     @LayoutlibDelegate
    116     /*package*/ static float pow(float x, float y) {
    117         return (float)Math.pow(x, y);
    118     }
    119 
    120     /**
    121      * Returns {@code sqrt(}<i>{@code x}</i><sup>{@code 2}</sup>{@code +} <i>
    122      * {@code y}</i><sup>{@code 2}</sup>{@code )}.
    123      *
    124      * @param x a float number
    125      * @param y a float number
    126      * @return the hypotenuse
    127      */
    128     @LayoutlibDelegate
    129     /*package*/ static float hypot(float x, float y) {
    130         return (float)Math.sqrt(x*x + y*y);
    131     }
    132 }
    133