mirror of
https://github.com/hyprwm/hyprutils.git
synced 2026-01-03 22:10:09 +01:00
Added transform method to Vector2D class
This commit is contained in:
parent
4737241eaf
commit
971c3d749c
2 changed files with 28 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
|
|
@ -97,6 +99,8 @@ namespace Hyprutils {
|
|||
Vector2D round() const;
|
||||
|
||||
Vector2D getComponentMax(const Vector2D& other) const;
|
||||
|
||||
Vector2D transform(eTransform transform, Vector2D monitorSize) const;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
|
|
@ -55,3 +56,26 @@ double Hyprutils::Math::Vector2D::size() const {
|
|||
Vector2D Hyprutils::Math::Vector2D::getComponentMax(const Vector2D& other) const {
|
||||
return Vector2D(std::max(this->x, other.x), std::max(this->y, other.y));
|
||||
}
|
||||
|
||||
Vector2D Hyprutils::Math::Vector2D::transform(eTransform transform, Vector2D monitorSize) const {
|
||||
switch (transform) {
|
||||
case HYPRUTILS_TRANSFORM_NORMAL:
|
||||
return *this;
|
||||
case HYPRUTILS_TRANSFORM_90:
|
||||
return Vector2D(this->y, monitorSize.y - this->x);
|
||||
case HYPRUTILS_TRANSFORM_180:
|
||||
return Vector2D(monitorSize.x - this->x, monitorSize.y - this->y);
|
||||
case HYPRUTILS_TRANSFORM_270:
|
||||
return Vector2D(monitorSize.x - this->y, this->x);
|
||||
case HYPRUTILS_TRANSFORM_FLIPPED:
|
||||
return Vector2D(monitorSize.x - this->x, this->y);
|
||||
case HYPRUTILS_TRANSFORM_FLIPPED_90:
|
||||
return Vector2D(this->y, this->x);
|
||||
case HYPRUTILS_TRANSFORM_FLIPPED_180:
|
||||
return Vector2D(this->x, monitorSize.y - this->y);
|
||||
case HYPRUTILS_TRANSFORM_FLIPPED_270:
|
||||
return Vector2D(monitorSize.x - this->y, monitorSize.y - this->x);
|
||||
default:
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue