5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/constants.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/math/math-utils.h>
29 * @addtogroup dali_core_math
36 * @brief An angle in degrees.
38 * This reduces ambiguity when using methods which accept angles in degrees or radians.
44 * @brief Default constructor, initialises to 0.
53 * @brief Creates an angle in degrees.
56 * @param[in] value The initial value in degrees
58 explicit constexpr Degree(float value)
64 * @brief Creates an angle in degrees from a Radian.
67 * @param[in] value The initial value in Radians
69 DALI_CORE_API Degree(Radian value);
72 Degree(const Degree&) = default; ///< Default copy constructor
73 Degree(Degree&&) noexcept = default; ///< Default move constructor
74 Degree& operator=(const Degree&) = default; ///< Default copy assignment operator
75 Degree& operator=(Degree&&) noexcept = default; ///< Default move assignment operator
79 float degree; ///< The value in degrees
82 // compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
85 * @brief Compares equality between two degrees.
88 * @param[in] lhs Degree to compare
89 * @param[in] rhs Degree to compare to
90 * @return True if the values are identical
92 inline bool operator==(const Degree& lhs, const Degree& rhs)
94 return fabsf(lhs.degree - rhs.degree) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000
98 * @brief Compares inequality between two degrees.
101 * @param[in] lhs Degree to compare
102 * @param[in] rhs Degree to compare to
103 * @return True if the values are not identical
105 inline bool operator!=(const Degree& lhs, const Degree& rhs)
107 return !(operator==(lhs, rhs));
111 * @brief Clamps a radian value.
113 * @param angle to clamp
116 * @return The resulting radian
118 inline Degree Clamp(Degree angle, float min, float max)
120 return Degree(Clamp<float>(angle.degree, min, max));
128 #endif // DALI_DEGREE_H