#ifndef MBGL_UTIL_VEC #define MBGL_UTIL_VEC #include #include #include #include #include namespace mbgl { template struct vec2 { struct null {}; typedef T Type; T x, y; inline vec2() {} template::has_quiet_NaN, int>::type = 0> inline vec2(null) : x(std::numeric_limits::quiet_NaN()), y(std::numeric_limits::quiet_NaN()) {} template::has_quiet_NaN, int>::type = 0> inline vec2(null) : x(std::numeric_limits::min()), y(std::numeric_limits::min()) {} inline vec2(const vec2& o) : x(o.x), y(o.y) {} template inline vec2(const U& u) : x(u.x), y(u.y) {} inline vec2(T x_, T y_) : x(x_), y(y_) {} inline bool operator==(const vec2& rhs) const { return x == rhs.x && y == rhs.y; } template inline typename std::enable_if::value, vec2>::type operator*(O o) const { return {x * o, y * o}; } template inline typename std::enable_if::value, vec2>::type & operator*=(O o) { x *= o; y *= o; } inline vec2 operator *(const std::array& matrix) { return { x * matrix[0] + y * matrix[4] + matrix[12], x * matrix[1] + y * matrix[5] + matrix[13] }; } template inline typename std::enable_if::value, vec2>::type operator-(O o) const { return {x - o, y - o}; } template inline typename std::enable_if::value, vec2>::type operator-(const O &o) const { return vec2(x - o.x, y - o.y); } template inline typename std::enable_if::value, vec2>::type operator+(const O &o) const { return vec2(x + o.x, y + o.y); } template inline vec2 matMul(const M &m) const { return {m[0] * x + m[1] * y, m[2] * x + m[3] * y}; } template::has_quiet_NaN, int>::type = 0> inline operator bool() const { return !std::isnan(x) && !std::isnan(y); } template::has_quiet_NaN, int>::type = 0> inline operator bool() const { return x != std::numeric_limits::min() && y != std::numeric_limits::min(); } }; template struct vec3 { T x, y, z; inline vec3() {} inline vec3(const vec3& o) : x(o.x), y(o.y), z(o.z) {} inline vec3(T x_, T y_, T z_) : x(x_), y(y_), z(z_) {} inline bool operator==(const vec3& rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z; } }; template struct vec4 { T x, y, z, w; inline vec4() {} inline vec4(const vec4& o) : x(o.x), y(o.y), z(o.z), w(o.w) {} inline vec4(T x_, T y_, T z_, T w_) : x(x_), y(y_), z(z_), w(w_) {} inline bool operator==(const vec4& rhs) const { return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; } }; typedef vec2 Coordinate; } #endif