mirror of
https://github.com/Relintai/sfw.git
synced 2024-11-08 07:52:09 +01:00
80 lines
1.9 KiB
C++
80 lines
1.9 KiB
C++
/*************************************************************************/
|
|
/* vector2i.cpp */
|
|
/* From https://github.com/Relintai/pandemonium_engine (MIT) */
|
|
/*************************************************************************/
|
|
|
|
//--STRIP
|
|
#include "core/vector2i.h"
|
|
|
|
#include "core/ustring.h"
|
|
//--STRIP
|
|
|
|
Vector2i Vector2i::clamp(const Vector2i &p_min, const Vector2i &p_max) const {
|
|
return Vector2i(
|
|
CLAMP(x, p_min.x, p_max.x),
|
|
CLAMP(y, p_min.y, p_max.y));
|
|
}
|
|
|
|
int64_t Vector2i::length_squared() const {
|
|
return x * (int64_t)x + y * (int64_t)y;
|
|
}
|
|
|
|
double Vector2i::length() const {
|
|
return Math::sqrt((double)length_squared());
|
|
}
|
|
|
|
Vector2i Vector2i::operator+(const Vector2i &p_v) const {
|
|
return Vector2i(x + p_v.x, y + p_v.y);
|
|
}
|
|
void Vector2i::operator+=(const Vector2i &p_v) {
|
|
x += p_v.x;
|
|
y += p_v.y;
|
|
}
|
|
Vector2i Vector2i::operator-(const Vector2i &p_v) const {
|
|
return Vector2i(x - p_v.x, y - p_v.y);
|
|
}
|
|
void Vector2i::operator-=(const Vector2i &p_v) {
|
|
x -= p_v.x;
|
|
y -= p_v.y;
|
|
}
|
|
|
|
Vector2i Vector2i::operator*(const Vector2i &p_v1) const {
|
|
return Vector2i(x * p_v1.x, y * p_v1.y);
|
|
};
|
|
|
|
Vector2i Vector2i::operator*(const int &rvalue) const {
|
|
return Vector2i(x * rvalue, y * rvalue);
|
|
};
|
|
void Vector2i::operator*=(const int &rvalue) {
|
|
x *= rvalue;
|
|
y *= rvalue;
|
|
};
|
|
|
|
Vector2i Vector2i::operator/(const Vector2i &p_v1) const {
|
|
return Vector2i(x / p_v1.x, y / p_v1.y);
|
|
};
|
|
|
|
Vector2i Vector2i::operator/(const int &rvalue) const {
|
|
return Vector2i(x / rvalue, y / rvalue);
|
|
};
|
|
|
|
void Vector2i::operator/=(const int &rvalue) {
|
|
x /= rvalue;
|
|
y /= rvalue;
|
|
};
|
|
|
|
Vector2i Vector2i::operator-() const {
|
|
return Vector2i(-x, -y);
|
|
}
|
|
|
|
bool Vector2i::operator==(const Vector2i &p_vec2) const {
|
|
return x == p_vec2.x && y == p_vec2.y;
|
|
}
|
|
bool Vector2i::operator!=(const Vector2i &p_vec2) const {
|
|
return x != p_vec2.x || y != p_vec2.y;
|
|
}
|
|
|
|
Vector2i::operator String() const {
|
|
return "(" + itos(x) + ", " + itos(y) + ")";
|
|
}
|