2016-05-01 06:00:02 -07:00
|
|
|
#ifndef VOXEL_VECTOR3I_H
|
|
|
|
#define VOXEL_VECTOR3I_H
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
#include <core/math/vector3.h>
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
struct Vector3i {
|
|
|
|
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int z;
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i() : x(0), y(0), z(0) {}
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i(int px, int py, int pz) : x(px), y(py), z(pz) {}
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i(const Vector3i & other) {
|
2016-05-01 06:00:02 -07:00
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i(const Vector3 & f) {
|
|
|
|
x = Math::floor(f.x);
|
|
|
|
y = Math::floor(f.y);
|
|
|
|
z = Math::floor(f.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Vector3 to_vec3() {
|
|
|
|
return Vector3(x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Vector3i & operator=(const Vector3i & other) {
|
2016-05-01 06:00:02 -07:00
|
|
|
x = other.x;
|
|
|
|
y = other.y;
|
|
|
|
z = other.z;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i operator+(const Vector3i & other) const {
|
2016-05-02 15:09:07 -07:00
|
|
|
return Vector3i(x + other.x, y + other.y, z + other.z);
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i operator-(const Vector3i & other) const {
|
2016-05-02 15:09:07 -07:00
|
|
|
return Vector3i(x - other.x, y - other.y, z - other.z);
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i operator*(int n) const {
|
2016-05-02 15:09:07 -07:00
|
|
|
return Vector3i(x * n, y * n, z * n);
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ Vector3i operator/(int n) const {
|
2016-05-02 15:09:07 -07:00
|
|
|
return Vector3i(x / n, y / n, z / n);
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ bool operator==(const Vector3i & other) const {
|
2016-05-01 06:00:02 -07:00
|
|
|
return x == other.x && y == other.y && z == other.z;
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
_FORCE_INLINE_ bool operator!=(const Vector3i & other) const {
|
2016-05-01 06:00:02 -07:00
|
|
|
return x != other.x && y != other.y && z != other.z;
|
|
|
|
}
|
|
|
|
|
2016-05-05 12:08:52 -07:00
|
|
|
void clamp_to(const Vector3i min, const Vector3i max) {
|
|
|
|
if (x < min.x) x = min.x;
|
|
|
|
if (y < min.y) y = min.y;
|
|
|
|
if (z < min.z) z = min.z;
|
|
|
|
|
|
|
|
if (x >= max.x) x = max.x;
|
|
|
|
if (y >= max.y) y = max.y;
|
|
|
|
if (z >= max.z) z = max.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Vector3iHasher {
|
|
|
|
static _FORCE_INLINE_ uint32_t hash(const Vector3i & v) {
|
|
|
|
uint32_t hash = hash_djb2_one_32(v.x);
|
|
|
|
hash = hash_djb2_one_32(v.y);
|
|
|
|
return hash_djb2_one_32(v.z);
|
|
|
|
}
|
2016-05-01 06:00:02 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VOXEL_VECTOR3I_H
|
|
|
|
|