FloatMath_Delegate.java revision c2e9651bf386a1f7bf7fc706cf5424950570470c
1f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian/*
2f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Copyright (C) 2007 The Android Open Source Project
3f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
4f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * you may not use this file except in compliance with the License.
6f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * You may obtain a copy of the License at
7f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
8f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
10f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * See the License for the specific language governing permissions and
14f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * limitations under the License.
15f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian */
16f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
17f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianpackage android.util;
18f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
19f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopianimport com.android.layoutlib.bridge.impl.DelegateManager;
20f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
21f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian/**
22f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Delegate implementing the native methods of android.util.FloatMath
23f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
24f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Through the layoutlib_create tool, the original native methods of FloatMath have been replaced
25f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * by calls to methods of the same name in this delegate class.
26f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
27f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * Because it's a stateless class to start with, there's no need to keep a {@link DelegateManager}
28f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian * around to map int to instance of the delegate.
29f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian *
30f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian */
31f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian/*package*/ final class FloatMath_Delegate {
32f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
33f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /** Prevents instantiation. */
34f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    private FloatMath_Delegate() {}
35f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
36f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /**
37f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * Returns the float conversion of the most positive (i.e. closest to
38f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * positive infinity) integer value which is less than the argument.
39f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     *
40f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @param value to be converted
41724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * @return the floor of value
42724d91d778e71c8186399f4955de14b54812b3edAravind Akella     */
43724d91d778e71c8186399f4955de14b54812b3edAravind Akella    /*package*/ static float floor(float value) {
44724d91d778e71c8186399f4955de14b54812b3edAravind Akella        return (float)Math.floor(value);
45724d91d778e71c8186399f4955de14b54812b3edAravind Akella    }
46724d91d778e71c8186399f4955de14b54812b3edAravind Akella
47724d91d778e71c8186399f4955de14b54812b3edAravind Akella    /**
48724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * Returns the float conversion of the most negative (i.e. closest to
49724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * negative infinity) integer value which is greater than the argument.
50724d91d778e71c8186399f4955de14b54812b3edAravind Akella     *
51724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * @param value to be converted
52724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * @return the ceiling of value
53724d91d778e71c8186399f4955de14b54812b3edAravind Akella     */
54724d91d778e71c8186399f4955de14b54812b3edAravind Akella    /*package*/ static float ceil(float value) {
55f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian        return (float)Math.ceil(value);
56f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    }
57ac9a96da65f6eae4513654adaad8a457d1c1575cMathias Agopian
58f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /**
59f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * Returns the closest float approximation of the sine of the argument.
60f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     *
61f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @param angle to compute the cosine of, in radians
62f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @return the sine of angle
63f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     */
64f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /*package*/ static  float sin(float angle) {
65f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian        return (float)Math.sin(angle);
66f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    }
67f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian
68f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /**
69f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * Returns the closest float approximation of the cosine of the argument.
70f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     *
71f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @param angle to compute the cosine of, in radians
72f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @return the cosine of angle
73f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     */
74f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /*package*/ static float cos(float angle) {
75f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian        return (float)Math.cos(angle);
76724d91d778e71c8186399f4955de14b54812b3edAravind Akella    }
77724d91d778e71c8186399f4955de14b54812b3edAravind Akella
78f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /**
79724d91d778e71c8186399f4955de14b54812b3edAravind Akella     * Returns the closest float approximation of the square root of the
80f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * argument.
81f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     *
82ac9a96da65f6eae4513654adaad8a457d1c1575cMathias Agopian     * @param value to compute sqrt of
83f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     * @return the square root of value
84f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian     */
85f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    /*package*/ static float sqrt(float value) {
86f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian        return (float)Math.sqrt(value);
87f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian    }
88f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian}
89f001c92436b4a66eb7687286325ced7f10c9f917Mathias Agopian