-#ifndef __DALI_VECTOR_2_H__
-#define __DALI_VECTOR_2_H__
+#ifndef DALI_VECTOR_2_H
+#define DALI_VECTOR_2_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
*/
// EXTERNAL INCLUDES
+#include <cstdint> // uint32_t
#include <iosfwd>
// INTERNAL INCLUDES
namespace Dali
{
+class Uint16Pair;
+
/**
* @addtogroup dali_core_math
* @{
* @brief A two dimensional vector.
* @SINCE_1_0.0
*/
-struct DALI_IMPORT_API Vector2
+struct DALI_CORE_API Vector2
{
-// (x width) and (y height) must be consecutive in memory.
-// No other data must be added before (x width) member.
-// No virtual methods must be added to this struct.
+ // (x width) and (y height) must be consecutive in memory.
+ // No other data must be added before (x width) member.
+ // No virtual methods must be added to this struct.
public:
-
/**
* @brief Constructor.
* @SINCE_1_0.0
* @param[in] x x or width component
* @param[in] y y or height component
*/
- explicit Vector2(float x, float y)
- : x(x), y(y)
+ explicit constexpr Vector2(float x, float y)
+ : x(x),
+ y(y)
{
}
*/
explicit Vector2(const Vector4& vec4);
-// Constants
+ /**
+ * @brief Conversion constructor from a Uint16Pair.
+ *
+ * @SINCE_1_9.21
+ *
+ * @param[in] pair The Uint16Pair to create this vector from
+ */
+ Vector2(const Uint16Pair& pair);
+
+ // Constants
- static const Vector2 ONE; ///< (1.0f,1.0f)
- static const Vector2 XAXIS; ///< Vector representing the X axis
- static const Vector2 YAXIS; ///< Vector representing the Y axis
- static const Vector2 NEGATIVE_XAXIS; ///< Vector representing the negative X axis
- static const Vector2 NEGATIVE_YAXIS; ///< Vector representing the negative Y axis
- static const Vector2 ZERO; ///< (0.0f, 0.0f)
+ static const Vector2 ONE; ///< (1.0f,1.0f)
+ static const Vector2 XAXIS; ///< Vector representing the X axis
+ static const Vector2 YAXIS; ///< Vector representing the Y axis
+ static const Vector2 NEGATIVE_XAXIS; ///< Vector representing the negative X axis
+ static const Vector2 NEGATIVE_YAXIS; ///< Vector representing the negative Y axis
+ static const Vector2 ZERO; ///< (0.0f, 0.0f)
-// API
+ // API
/**
* @brief Assignment operator.
return Vector2(x / rhs, y / rhs);
}
-
/**
* @brief Division assignment operator.
*
* @brief Unary negation operator.
*
* @SINCE_1_0.0
- * @return A vector containg the negation
+ * @return A vector containing the negation
*/
Vector2 operator-() const
{
* @param[in] index Subscript index
* @return The float at the given index
*/
- const float& operator[](const unsigned int index) const
+ const float& operator[](const uint32_t index) const
{
- DALI_ASSERT_ALWAYS( index < 2 && "Vector element index out of bounds" );
+ DALI_ASSERT_ALWAYS(index < 2 && "Vector element index out of bounds");
return AsFloat()[index];
}
* @param[in] index Subscript index
* @return The float at the given index
*/
- float& operator[](const unsigned int index)
+ float& operator[](const uint32_t index)
{
- DALI_ASSERT_ALWAYS( index < 2 && "Vector element index out of bounds" );
+ DALI_ASSERT_ALWAYS(index < 2 && "Vector element index out of bounds");
return AsFloat()[index];
}
* @param[in] min The minimum vector
* @param[in] max The maximum vector
*/
- void Clamp( const Vector2& min, const Vector2& max );
+ void Clamp(const Vector2& min, const Vector2& max);
/**
* @brief Returns the contents of the vector as an array of 2 floats.
* @return The vector contents as an array of 2 floats
* @note inlined for performance reasons (generates less code than a function call)
*/
- const float* AsFloat() const {return &x;}
+ const float* AsFloat() const
+ {
+ return &x;
+ }
/**
* @brief Returns the contents of the vector as an array of 2 floats.
* @return The vector contents as an array of 2 floats
* @note inlined for performance reasons (generates less code than a function call)
*/
- float* AsFloat() {return &x;}
+ float* AsFloat()
+ {
+ return &x;
+ }
-public: // Data
+public:
+ Vector2(const Vector2&) = default; ///< Default copy constructor
+ Vector2(Vector2&&) = default; ///< Default move constructor
+ Vector2& operator=(const Vector2&) = default; ///< Default copy assignment operator
+ Vector2& operator=(Vector2&&) = default; ///< Default move assignment operator
+public: // Data
// NOTE
// (x width) and (y height) must be consecutive in memory.
// No other data must be added before (x width) member.
float y; ///< y component
float height; ///< height
};
-
};
/**
* @brief Size is an alias of Dali::Vector2.
* @SINCE_1_0.0
*/
-typedef Vector2 Size;
+using Size = Vector2;
/**
* @brief Print a Vector2.
* @param[in] vector The vector to print
* @return The output stream operator
*/
-DALI_IMPORT_API std::ostream& operator<< (std::ostream& o, const Vector2& vector);
+DALI_CORE_API std::ostream& operator<<(std::ostream& o, const Vector2& vector);
/**
* @brief Returns a vector with components set to the minimum of the corresponding component in a and b.
* @param[in] b A vector
* @return A vector containing the minimum of each component from a and b
*/
-inline Vector2 Min( const Vector2& a, const Vector2& b )
+inline Vector2 Min(const Vector2& a, const Vector2& b)
{
- return Vector2( a.x < b.x ? a.x : b.x , a.y < b.y ? a.y : b.y );
+ return Vector2(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y);
}
/**
* @param[in] b A vector
* @return A vector containing the maximum of each component from a and b
*/
-inline Vector2 Max( const Vector2& a, const Vector2& b )
+inline Vector2 Max(const Vector2& a, const Vector2& b)
{
- return Vector2( a.x > b.x ? a.x : b.x , a.y > b.y ? a.y : b.y );
+ return Vector2(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y);
}
/**
* @param[in] max The maximum value
* @return A vector containing the clamped components of v
*/
-DALI_IMPORT_API Vector2 Clamp( const Vector2& v, const float& min, const float& max );
+DALI_CORE_API Vector2 Clamp(const Vector2& v, const float& min, const float& max);
// Allow Vector2 to be treated as a POD type
-template <> struct TypeTraits< Vector2 > : public BasicTypes< Vector2 > { enum { IS_TRIVIAL_TYPE = true }; };
+template<>
+struct TypeTraits<Vector2> : public BasicTypes<Vector2>
+{
+ enum
+ {
+ IS_TRIVIAL_TYPE = true
+ };
+};
/**
* @}
*/
} // namespace Dali
-#endif // __DALI_VECTOR_2_H__
+#endif // DALI_VECTOR_2_H