-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
852 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#pragma once | ||
|
||
#include "./Vector2D.hpp" | ||
#include "./Misc.hpp" | ||
|
||
namespace Hyprutils { | ||
namespace Math { | ||
struct SBoxExtents { | ||
Vector2D topLeft; | ||
Vector2D bottomRight; | ||
|
||
// | ||
SBoxExtents operator*(const double& scale) const { | ||
return SBoxExtents{topLeft * scale, bottomRight * scale}; | ||
} | ||
|
||
SBoxExtents round() { | ||
return {topLeft.round(), bottomRight.round()}; | ||
} | ||
|
||
bool operator==(const SBoxExtents& other) const { | ||
return topLeft == other.topLeft && bottomRight == other.bottomRight; | ||
} | ||
|
||
void addExtents(const SBoxExtents& other) { | ||
topLeft = topLeft.getComponentMax(other.topLeft); | ||
bottomRight = bottomRight.getComponentMax(other.bottomRight); | ||
} | ||
}; | ||
|
||
class CBox { | ||
public: | ||
CBox(double x_, double y_, double w_, double h_) { | ||
x = x_; | ||
y = y_; | ||
w = w_; | ||
h = h_; | ||
} | ||
|
||
CBox() { | ||
w = 0; | ||
h = 0; | ||
} | ||
|
||
CBox(const double d) { | ||
x = d; | ||
y = d; | ||
w = d; | ||
h = d; | ||
} | ||
|
||
CBox(const Vector2D& pos, const Vector2D& size) { | ||
x = pos.x; | ||
y = pos.y; | ||
w = size.x; | ||
h = size.y; | ||
} | ||
|
||
CBox& applyFromWlr(); | ||
CBox& scale(double scale); | ||
CBox& scaleFromCenter(double scale); | ||
CBox& scale(const Vector2D& scale); | ||
CBox& translate(const Vector2D& vec); | ||
CBox& round(); | ||
CBox& transform(const eTransform t, double w, double h); | ||
CBox& addExtents(const SBoxExtents& e); | ||
CBox& expand(const double& value); | ||
CBox& noNegativeSize(); | ||
|
||
CBox copy() const; | ||
CBox intersection(const CBox& other) const; | ||
bool overlaps(const CBox& other) const; | ||
bool inside(const CBox& bound) const; | ||
|
||
SBoxExtents extentsFrom(const CBox&); // this is the big box | ||
|
||
Vector2D middle() const; | ||
Vector2D pos() const; | ||
Vector2D size() const; | ||
Vector2D closestPoint(const Vector2D& vec) const; | ||
|
||
bool containsPoint(const Vector2D& vec) const; | ||
bool empty() const; | ||
|
||
double x = 0, y = 0; | ||
union { | ||
double w; | ||
double width; | ||
}; | ||
union { | ||
double h; | ||
double height; | ||
}; | ||
|
||
double rot = 0; /* rad, ccw */ | ||
|
||
// | ||
bool operator==(const CBox& rhs) const { | ||
return x == rhs.x && y == rhs.y && w == rhs.w && h == rhs.h; | ||
} | ||
|
||
private: | ||
CBox roundInternal(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
namespace Hyprutils { | ||
namespace Math { | ||
enum eTransform { | ||
HYPRUTILS_TRANSFORM_NORMAL = 0, | ||
HYPRUTILS_TRANSFORM_90 = 1, | ||
HYPRUTILS_TRANSFORM_180 = 2, | ||
HYPRUTILS_TRANSFORM_270 = 3, | ||
HYPRUTILS_TRANSFORM_FLIPPED = 4, | ||
HYPRUTILS_TRANSFORM_FLIPPED_90 = 5, | ||
HYPRUTILS_TRANSFORM_FLIPPED_180 = 6, | ||
HYPRUTILS_TRANSFORM_FLIPPED_270 = 7, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <pixman.h> | ||
#include <vector> | ||
#include "Vector2D.hpp" | ||
#include "Box.hpp" | ||
|
||
namespace Hyprutils { | ||
namespace Math { | ||
class CRegion { | ||
public: | ||
/* Create an empty region */ | ||
CRegion(); | ||
/* Create from a reference. Copies, does not own. */ | ||
CRegion(const pixman_region32_t* const ref); | ||
/* Create from a box */ | ||
CRegion(double x, double y, double w, double h); | ||
/* Create from a CBox */ | ||
CRegion(const CBox& box); | ||
/* Create from a pixman_box32_t */ | ||
CRegion(pixman_box32_t* box); | ||
|
||
CRegion(const CRegion&); | ||
CRegion(CRegion&&); | ||
|
||
~CRegion(); | ||
|
||
CRegion& operator=(CRegion&& other) { | ||
pixman_region32_copy(&m_rRegion, other.pixman()); | ||
return *this; | ||
} | ||
|
||
CRegion& operator=(CRegion& other) { | ||
pixman_region32_copy(&m_rRegion, other.pixman()); | ||
return *this; | ||
} | ||
|
||
CRegion& clear(); | ||
CRegion& set(const CRegion& other); | ||
CRegion& add(const CRegion& other); | ||
CRegion& add(double x, double y, double w, double h); | ||
CRegion& add(const CBox& other); | ||
CRegion& subtract(const CRegion& other); | ||
CRegion& intersect(const CRegion& other); | ||
CRegion& intersect(double x, double y, double w, double h); | ||
CRegion& translate(const Vector2D& vec); | ||
CRegion& transform(const eTransform t, double w, double h); | ||
CRegion& invert(pixman_box32_t* box); | ||
CRegion& invert(const CBox& box); | ||
CRegion& scale(float scale); | ||
CRegion& scale(const Vector2D& scale); | ||
CRegion& rationalize(); | ||
CBox getExtents(); | ||
bool containsPoint(const Vector2D& vec) const; | ||
bool empty() const; | ||
Vector2D closestPoint(const Vector2D& vec) const; | ||
CRegion copy() const; | ||
|
||
std::vector<pixman_box32_t> getRects() const; | ||
|
||
// | ||
pixman_region32_t* pixman() { | ||
return &m_rRegion; | ||
} | ||
|
||
private: | ||
pixman_region32_t m_rRegion; | ||
}; | ||
} | ||
} |
Oops, something went wrong.