#ifndef UTILS_H
#define UTILS_H
#include <string>
#include <vector>
#include <map>
#include <stdint.h>
#include "Containers.h"
#include "Namespace.h"
BEGIN_NAMESPACE
#define ARRAY_SIZE(array) \
(sizeof(array)/sizeof(array[0]))
#define STATIC_ASSERT(condition, name) \
typedef char assert_failed_ ## name [ (condition) ? 1 : -1 ];
#define ENUM_AS_FLAGS(enum) \
inline enum operator|(enum a, enum b) { return static_cast<enum>(static_cast<int>(a) | static_cast<int>(b)); } \
inline enum operator|=(enum& a, enum b) { return a = static_cast<enum>(static_cast<int>(a) | static_cast<int>(b)); } \
inline enum operator&=(enum& a, enum b) { return a = static_cast<enum>(static_cast<int>(a) & static_cast<int>(b)); } \
inline enum operator~(enum a) { return static_cast<enum>(~static_cast<int>(a)); }
#define DEBUG_PRINT(fmt, ...) \
fprintf(stderr, "%s(%d): " fmt, __FILE__, __LINE__, __VA_ARGS__)
template<typename T>
static T clamp(T a_val, T a_min, T a_max)
{
return std::min(std::max(a_val, a_min), a_max);
}
template<typename T>
static T lerp(T v0, T v1, T t)
{
return (T(1) - t) * v0 + t * v1; // Less precise alternative: return v0 + t * (v1 - v0);
}
struct Size
{
int m_width;
int m_height;
};
struct Point
{
int m_x;
int m_y;
};
struct Rectangle
{
union {
Point m_position;
struct
{
int m_x;
int m_y;
};
};
union {
Size m_size;
struct
{
int m_width;
int m_height;
};
};
};
END_NAMESPACE
#endif // UTILS_H