Hyprland/src/helpers/Vector2D.cpp
Jan Beich f1ad270ff8
vector: restore cmath include after 438d063ec6 (#2394)
src/helpers/Vector2D.cpp:27:26: error: no member named 'floor' in namespace 'std'
    return Vector2D(std::floor(x), std::floor(y));
                    ~~~~~^
src/helpers/Vector2D.cpp:27:41: error: no member named 'floor' in namespace 'std'
    return Vector2D(std::floor(x), std::floor(y));
                                   ~~~~~^
src/helpers/Vector2D.cpp:37:17: error: no member named 'sqrt' in namespace 'std'
    return std::sqrt(dx * dx + dy * dy);
           ~~~~~^
2023-05-29 15:12:00 +02:00

39 lines
834 B
C++

#include "Vector2D.hpp"
#include <algorithm>
#include <cmath>
Vector2D::Vector2D(double xx, double yy) {
x = xx;
y = yy;
}
Vector2D::Vector2D() {
x = 0;
y = 0;
}
Vector2D::~Vector2D() {}
double Vector2D::normalize() {
// get max abs
const auto max = std::abs(x) > std::abs(y) ? std::abs(x) : std::abs(y);
x /= max;
y /= max;
return max;
}
Vector2D Vector2D::floor() {
return Vector2D(std::floor(x), std::floor(y));
}
Vector2D Vector2D::clamp(const Vector2D& min, const Vector2D& max) {
return Vector2D(std::clamp(this->x, min.x, max.x < min.x ? INFINITY : max.x), std::clamp(this->y, min.y, max.y < min.y ? INFINITY : max.y));
}
double Vector2D::distance(const Vector2D& other) {
double dx = x - other.x;
double dy = y - other.y;
return std::sqrt(dx * dx + dy * dy);
}