mirror of
https://github.com/hyprwm/hyprutils.git
synced 2024-12-22 11:59:48 +01:00
math: add Edges (#10)
This commit is contained in:
parent
962582a090
commit
a950624669
3 changed files with 121 additions and 1 deletions
|
@ -135,6 +135,12 @@ namespace Hyprutils::Math {
|
||||||
*/
|
*/
|
||||||
Vector2D size() const;
|
Vector2D size() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retrieves the size of the box offset by its position.
|
||||||
|
* @return Vector2D representing the bottom right extent of the box.
|
||||||
|
*/
|
||||||
|
Vector2D extent() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds the closest point within the box to a given vector.
|
* @brief Finds the closest point within the box to a given vector.
|
||||||
* @param vec Vector from which to find the closest point.
|
* @param vec Vector from which to find the closest point.
|
||||||
|
@ -179,4 +185,4 @@ namespace Hyprutils::Math {
|
||||||
private:
|
private:
|
||||||
CBox roundInternal();
|
CBox roundInternal();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
110
include/hyprutils/math/Edges.hpp
Normal file
110
include/hyprutils/math/Edges.hpp
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace Hyprutils::Math {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flag set of box edges
|
||||||
|
*/
|
||||||
|
class CEdges {
|
||||||
|
public:
|
||||||
|
enum eEdges : uint8_t {
|
||||||
|
NONE = 0,
|
||||||
|
TOP = 1,
|
||||||
|
LEFT = 2,
|
||||||
|
BOTTOM = 4,
|
||||||
|
RIGHT = 8,
|
||||||
|
};
|
||||||
|
|
||||||
|
CEdges() = default;
|
||||||
|
CEdges(eEdges edges) : m_edges(edges) {}
|
||||||
|
CEdges(uint8_t edges) : m_edges(static_cast<eEdges>(edges)) {}
|
||||||
|
|
||||||
|
bool operator==(const CEdges& other) {
|
||||||
|
return m_edges == other.m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEdges operator|(const CEdges& other) {
|
||||||
|
return m_edges | other.m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEdges operator&(const CEdges& other) {
|
||||||
|
return m_edges & other.m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEdges operator^(const CEdges& other) {
|
||||||
|
return m_edges ^ other.m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator|=(const CEdges& other) {
|
||||||
|
m_edges = (*this | other).m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator&=(const CEdges& other) {
|
||||||
|
m_edges = (*this & other).m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator^=(const CEdges& other) {
|
||||||
|
m_edges = (*this ^ other).m_edges;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the edge set contains the top edge.
|
||||||
|
*/
|
||||||
|
bool top() {
|
||||||
|
return m_edges & TOP;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the edge set contains the left edge.
|
||||||
|
*/
|
||||||
|
bool left() {
|
||||||
|
return m_edges & LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the edge set contains the bottom edge.
|
||||||
|
*/
|
||||||
|
bool bottom() {
|
||||||
|
return m_edges & BOTTOM;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the edge set contains the right edge.
|
||||||
|
*/
|
||||||
|
bool right() {
|
||||||
|
return m_edges & RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param top The state the top edge should be set to.
|
||||||
|
*/
|
||||||
|
void setTop(bool top) {
|
||||||
|
m_edges = static_cast<eEdges>((m_edges & ~TOP) | (TOP * top));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param left The state the left edge should be set to.
|
||||||
|
*/
|
||||||
|
void setLeft(bool left) {
|
||||||
|
m_edges = static_cast<eEdges>((m_edges & ~LEFT) | (LEFT * left));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bottom The state the bottom edge should be set to.
|
||||||
|
*/
|
||||||
|
void setBottom(bool bottom) {
|
||||||
|
m_edges = static_cast<eEdges>((m_edges & ~BOTTOM) | (BOTTOM * bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param right The state the right edge should be set to.
|
||||||
|
*/
|
||||||
|
void setRight(bool right) {
|
||||||
|
m_edges = static_cast<eEdges>((m_edges & ~RIGHT) | (RIGHT * right));
|
||||||
|
}
|
||||||
|
|
||||||
|
eEdges m_edges = NONE;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -199,6 +199,10 @@ Vector2D Hyprutils::Math::CBox::size() const {
|
||||||
return {w, h};
|
return {w, h};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2D Hyprutils::Math::CBox::extent() const {
|
||||||
|
return pos() + size();
|
||||||
|
}
|
||||||
|
|
||||||
Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
Vector2D Hyprutils::Math::CBox::closestPoint(const Vector2D& vec) const {
|
||||||
if (containsPoint(vec))
|
if (containsPoint(vec))
|
||||||
return vec;
|
return vec;
|
||||||
|
|
Loading…
Reference in a new issue