noexcept move for BaseHandle/InstrusivePtr/Math
[platform/core/uifw/dali-core.git] / dali / public-api / math / degree.h
index 4a9f1b8..f87888a 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_DEGREE_H__
-#define __DALI_DEGREE_H__
+#ifndef DALI_DEGREE_H
+#define DALI_DEGREE_H
 
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
+#include <dali/public-api/common/constants.h>
 #include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/math/math-utils.h>
 
 namespace Dali
 {
+/**
+ * @addtogroup dali_core_math
+ * @{
+ */
 
 struct Radian;
 
@@ -30,83 +36,93 @@ struct Radian;
  * @brief An angle in degrees.
  *
  * This reduces ambiguity when using methods which accept angles in degrees or radians.
+ * @SINCE_1_0.0
  */
-struct DALI_IMPORT_API Degree
+struct Degree
 {
   /**
-   * @brief Create an angle in degrees.
-   *
-   * @param[in] value The initial value in degrees.
-   */
-  explicit Degree( float value );
-
-  /**
-   * @brief Create an angle in degrees from an angle in radians.
-   *
-   * @param[in] value The initial value in radians.
-   */
-  Degree( const Radian& value );
-
-  /**
-   * @brief Compare equality between two degrees.
-   *
-   * @param[in] rhs Degree to compare to
-   * @return true if the value is identical
+   * @brief Default constructor, initialises to 0.
+   * @SINCE_1_0.0
    */
-  bool operator==( const Degree& rhs ) const;
+  Degree()
+  : degree(0.f)
+  {
+  }
 
   /**
-   * @brief Compare inequality between two degrees.
+   * @brief Creates an angle in degrees.
    *
-   * @param[in] rhs Degree to compare to
-   * @return true if the value is not identical
+   * @SINCE_1_0.0
+   * @param[in] value The initial value in degrees
    */
-  bool operator!=( const Degree& rhs ) const;
+  explicit constexpr Degree(float value)
+  : degree(value)
+  {
+  }
 
   /**
-   * @brief Compare two degrees.
+   * @brief Creates an angle in degrees from a Radian.
    *
-   * @param[in] rhs Degree to compare to
-   * @return true if this is less than the value
+   * @SINCE_1_0.0
+   * @param[in] value The initial value in Radians
    */
-  bool operator<( const Degree& rhs ) const;
+  DALI_CORE_API Degree(Radian value);
 
-  /**
-   * @brief Assign an angle from a float value.
-   *
-   * @param[in] value Float value in degrees
-   * @return a reference to this
-   */
-  Degree& operator=( const float value );
+public:
+  Degree(const Degree&)     = default;            ///< Default copy constructor
+  Degree(Degree&&) noexcept = default;            ///< Default move constructor
+  Degree& operator=(const Degree&) = default;     ///< Default copy assignment operator
+  Degree& operator=(Degree&&) noexcept = default; ///< Default move assignment operator
 
-  /**
-   * @brief Assign an angle in radians to a Degree.
-   *
-   * @param[in] rhs Radian to get the value from
-   * @return a reference to this
-   */
-  Degree& operator=( const Radian& rhs );
+public:
+  // member data
+  float degree; ///< The value in degrees
+};
 
-  /**
-   * @brief Cast operator to const float reference
-   */
-  operator const float&() const;
+// compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
 
-  /**
-   * @brief Cast operator to float reference.
-   */
-  operator float&();
+/**
+ * @brief Compares equality between two degrees.
+ *
+ * @SINCE_1_0.0
+ * @param[in] lhs Degree to compare
+ * @param[in] rhs Degree to compare to
+ * @return True if the values are identical
+ */
+inline bool operator==(const Degree& lhs, const Degree& rhs)
+{
+  return fabsf(lhs.degree - rhs.degree) < Math::MACHINE_EPSILON_1000; // expect degree angles to be between 0 and 1000
+}
 
-private:
-  // member data
-  float mValue; ///< The value in degrees
+/**
+ * @brief Compares inequality between two degrees.
+ *
+ * @SINCE_1_0.0
+ * @param[in] lhs Degree to compare
+ * @param[in] rhs Degree to compare to
+ * @return True if the values are not identical
+ */
+inline bool operator!=(const Degree& lhs, const Degree& rhs)
+{
+  return !(operator==(lhs, rhs));
+}
 
-  /**
-   * @brief Disable the default constructor.
-   */
-  Degree();
-};
+/**
+ * @brief Clamps a radian value.
+ * @SINCE_1_0.0
+ * @param angle to clamp
+ * @param min value
+ * @param max value
+ * @return The resulting radian
+ */
+inline Degree Clamp(Degree angle, float min, float max)
+{
+  return Degree(Clamp<float>(angle.degree, min, max));
+}
 
+/**
+ * @}
+ */
 } // namespace Dali
 
-#endif // __DALI_DEGREE_H__
+#endif // DALI_DEGREE_H