Compare commits
4 Commits
3ea49697a9
...
7c4f2c9d43
| Author | SHA1 | Date |
|---|---|---|
|
|
7c4f2c9d43 | |
|
|
6c8767b227 | |
|
|
c8302cdec4 | |
|
|
13bdaab5d5 |
|
|
@ -50,7 +50,7 @@ target_include_directories(
|
|||
PUBLIC "./include"
|
||||
PRIVATE "./src")
|
||||
set_target_properties(hyprutils PROPERTIES VERSION ${hyprutils_VERSION}
|
||||
SOVERSION 7)
|
||||
SOVERSION 8)
|
||||
target_link_libraries(hyprutils PkgConfig::deps)
|
||||
|
||||
# tests
|
||||
|
|
|
|||
|
|
@ -1,3 +1,11 @@
|
|||
hyprutils (0.9.0-0.1) unstable; urgency=medium
|
||||
|
||||
* Non-maintainer upload
|
||||
* New upstream release (Closes: #1117181)
|
||||
* Breaking ABI changes: updated soversion to 8
|
||||
|
||||
-- Carl Keinath <carl.keinath@gmail.com> Sat, 04 Oct 2025 10:58:35 +0200
|
||||
|
||||
hyprutils (0.8.4-0.1) unstable; urgency=medium
|
||||
|
||||
* Non-maintainer upload.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Section: libdevel
|
|||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends:
|
||||
libhyprutils7 (= ${binary:Version}),
|
||||
libhyprutils8 (= ${binary:Version}),
|
||||
${misc:Depends},
|
||||
Description: Utilities used across the Hyprland ecosystem (development files)
|
||||
Hyprutils is a small C++ library for utilities used across the Hyprland
|
||||
|
|
@ -25,7 +25,7 @@ Description: Utilities used across the Hyprland ecosystem (development files)
|
|||
.
|
||||
This package contains the development files.
|
||||
|
||||
Package: libhyprutils7
|
||||
Package: libhyprutils8
|
||||
Architecture: any
|
||||
Multi-Arch: same
|
||||
Depends:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ namespace Hyprutils {
|
|||
class CBezierCurve {
|
||||
public:
|
||||
/* Calculates a cubic bezier curve based on 2 control points (EXCLUDES the 0,0 and 1,1 points). */
|
||||
void setup(const std::array<Hyprutils::Math::Vector2D, 2>& points);
|
||||
void setup(const std::array<Hyprutils::Math::Vector2D, 2>& points);
|
||||
/* Calculates a cubic bezier curve based on 4 control points. */
|
||||
void setup4(const std::array<Hyprutils::Math::Vector2D, 4>& points);
|
||||
|
||||
float getYForT(float const& t) const;
|
||||
float getXForT(float const& t) const;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <hyprutils/memory/Casts.hpp>
|
||||
#include <hyprutils/math/Misc.hpp>
|
||||
|
||||
#include <format>
|
||||
|
|
@ -9,82 +10,86 @@ namespace Hyprutils {
|
|||
namespace Math {
|
||||
class Vector2D {
|
||||
public:
|
||||
Vector2D(double, double);
|
||||
Vector2D(int, int);
|
||||
Vector2D();
|
||||
~Vector2D();
|
||||
constexpr Vector2D(double xx, double yy) : x(xx), y(yy) {
|
||||
;
|
||||
}
|
||||
constexpr Vector2D(int xx, int yy) : x(Hyprutils::Memory::sc<double>(xx)), y(Hyprutils::Memory::sc<double>(yy)) {
|
||||
;
|
||||
}
|
||||
constexpr Vector2D() = default;
|
||||
~Vector2D() = default;
|
||||
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
|
||||
// returns the scale
|
||||
double normalize();
|
||||
double normalize();
|
||||
|
||||
Vector2D operator+(const Vector2D& a) const {
|
||||
constexpr Vector2D operator+(const Vector2D& a) const {
|
||||
return Vector2D(this->x + a.x, this->y + a.y);
|
||||
}
|
||||
Vector2D operator-(const Vector2D& a) const {
|
||||
constexpr Vector2D operator-(const Vector2D& a) const {
|
||||
return Vector2D(this->x - a.x, this->y - a.y);
|
||||
}
|
||||
Vector2D operator-() const {
|
||||
constexpr Vector2D operator-() const {
|
||||
return Vector2D(-this->x, -this->y);
|
||||
}
|
||||
Vector2D operator*(const double& a) const {
|
||||
constexpr Vector2D operator*(const double& a) const {
|
||||
return Vector2D(this->x * a, this->y * a);
|
||||
}
|
||||
Vector2D operator/(const double& a) const {
|
||||
constexpr Vector2D operator/(const double& a) const {
|
||||
return Vector2D(this->x / a, this->y / a);
|
||||
}
|
||||
|
||||
bool operator==(const Vector2D& a) const {
|
||||
constexpr bool operator==(const Vector2D& a) const {
|
||||
return a.x == x && a.y == y;
|
||||
}
|
||||
|
||||
bool operator!=(const Vector2D& a) const {
|
||||
constexpr bool operator!=(const Vector2D& a) const {
|
||||
return a.x != x || a.y != y;
|
||||
}
|
||||
|
||||
Vector2D operator*(const Vector2D& a) const {
|
||||
constexpr Vector2D operator*(const Vector2D& a) const {
|
||||
return Vector2D(this->x * a.x, this->y * a.y);
|
||||
}
|
||||
|
||||
Vector2D operator/(const Vector2D& a) const {
|
||||
constexpr Vector2D operator/(const Vector2D& a) const {
|
||||
return Vector2D(this->x / a.x, this->y / a.y);
|
||||
}
|
||||
|
||||
bool operator>(const Vector2D& a) const {
|
||||
constexpr bool operator>(const Vector2D& a) const {
|
||||
return this->x > a.x && this->y > a.y;
|
||||
}
|
||||
|
||||
bool operator<(const Vector2D& a) const {
|
||||
constexpr bool operator<(const Vector2D& a) const {
|
||||
return this->x < a.x && this->y < a.y;
|
||||
}
|
||||
Vector2D& operator+=(const Vector2D& a) {
|
||||
constexpr Vector2D& operator+=(const Vector2D& a) {
|
||||
this->x += a.x;
|
||||
this->y += a.y;
|
||||
return *this;
|
||||
}
|
||||
Vector2D& operator-=(const Vector2D& a) {
|
||||
constexpr Vector2D& operator-=(const Vector2D& a) {
|
||||
this->x -= a.x;
|
||||
this->y -= a.y;
|
||||
return *this;
|
||||
}
|
||||
Vector2D& operator*=(const Vector2D& a) {
|
||||
constexpr Vector2D& operator*=(const Vector2D& a) {
|
||||
this->x *= a.x;
|
||||
this->y *= a.y;
|
||||
return *this;
|
||||
}
|
||||
Vector2D& operator/=(const Vector2D& a) {
|
||||
constexpr Vector2D& operator/=(const Vector2D& a) {
|
||||
this->x /= a.x;
|
||||
this->y /= a.y;
|
||||
return *this;
|
||||
}
|
||||
Vector2D& operator*=(const double& a) {
|
||||
constexpr Vector2D& operator*=(const double& a) {
|
||||
this->x *= a;
|
||||
this->y *= a;
|
||||
return *this;
|
||||
}
|
||||
Vector2D& operator/=(const double& a) {
|
||||
constexpr Vector2D& operator/=(const double& a) {
|
||||
this->x /= a;
|
||||
this->y /= a;
|
||||
return *this;
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ namespace Hyprutils::Memory {
|
|||
template <typename T>
|
||||
class CAtomicSharedPointer {
|
||||
template <typename X>
|
||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
||||
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||
template <typename X>
|
||||
using validHierarchy = typename std::enable_if<std::is_assignable<CAtomicSharedPointer<T>&, X>::value, CAtomicSharedPointer&>::type;
|
||||
using validHierarchy = std::enable_if_t<std::is_assignable_v<CAtomicSharedPointer<T>&, X>, CAtomicSharedPointer&>;
|
||||
|
||||
public:
|
||||
explicit CAtomicSharedPointer(Impl_::impl_base* impl) noexcept : m_ptr(impl) {}
|
||||
|
|
@ -221,9 +221,9 @@ namespace Hyprutils::Memory {
|
|||
class CAtomicWeakPointer {
|
||||
|
||||
template <typename X>
|
||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
||||
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||
template <typename X>
|
||||
using validHierarchy = typename std::enable_if<std::is_assignable<CAtomicWeakPointer<T>&, X>::value, CAtomicWeakPointer&>::type;
|
||||
using validHierarchy = std::enable_if_t<std::is_assignable_v<CAtomicWeakPointer<T>&, X>, CAtomicWeakPointer&>;
|
||||
|
||||
public:
|
||||
CAtomicWeakPointer(const CAtomicWeakPointer<T>& ref) {
|
||||
|
|
|
|||
|
|
@ -27,5 +27,3 @@ namespace Hyprutils::Memory {
|
|||
return std::bit_cast<To>(from);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace Hyprutils {
|
|||
namespace Impl_ {
|
||||
class impl_base {
|
||||
public:
|
||||
virtual ~impl_base() {};
|
||||
virtual ~impl_base() = default;
|
||||
|
||||
virtual void inc() noexcept = 0;
|
||||
virtual void dec() noexcept = 0;
|
||||
|
|
@ -57,13 +57,13 @@ namespace Hyprutils {
|
|||
// this way, weak pointers will still be able to
|
||||
// reference and use, but no longer create shared ones.
|
||||
_destroying = true;
|
||||
__deleter(_data);
|
||||
_deleter(_data);
|
||||
// now, we can reset the data and call it a day.
|
||||
_data = nullptr;
|
||||
_destroying = false;
|
||||
}
|
||||
|
||||
std::default_delete<T> __deleter{};
|
||||
std::default_delete<T> _deleter{};
|
||||
|
||||
//
|
||||
virtual void inc() noexcept {
|
||||
|
|
|
|||
|
|
@ -22,26 +22,23 @@ namespace Hyprutils {
|
|||
class CSharedPointer {
|
||||
public:
|
||||
template <typename X>
|
||||
using validHierarchy = typename std::enable_if<std::is_assignable<CSharedPointer<T>&, X>::value, CSharedPointer&>::type;
|
||||
using validHierarchy = std::enable_if_t<std::is_assignable_v<CSharedPointer<T>&, X>, CSharedPointer&>;
|
||||
template <typename X>
|
||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
||||
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||
|
||||
/* creates a new shared pointer managing a resource
|
||||
avoid calling. Could duplicate ownership. Prefer makeShared */
|
||||
explicit CSharedPointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object);
|
||||
explicit CSharedPointer(T* object) noexcept : impl_(new Impl_::impl<T>(object)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
/* creates a shared pointer from a reference */
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer<U>& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept {
|
||||
impl_ = ref.impl_;
|
||||
CSharedPointer(const CSharedPointer& ref) noexcept : impl_(ref.impl_) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +52,7 @@ namespace Hyprutils {
|
|||
}
|
||||
|
||||
/* allows weakPointer to create from an impl */
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept {
|
||||
impl_ = implementation;
|
||||
CSharedPointer(Impl_::impl_base* implementation) noexcept : impl_(implementation) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +95,7 @@ namespace Hyprutils {
|
|||
return *this;
|
||||
}
|
||||
|
||||
CSharedPointer& operator=(CSharedPointer&& rhs) {
|
||||
CSharedPointer& operator=(CSharedPointer&& rhs) noexcept {
|
||||
std::swap(impl_, rhs.impl_);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,13 @@ namespace Hyprutils {
|
|||
class CUniquePointer {
|
||||
public:
|
||||
template <typename X>
|
||||
using validHierarchy = typename std::enable_if<std::is_assignable<CUniquePointer<T>&, X>::value, CUniquePointer&>::type;
|
||||
using validHierarchy = std::enable_if_t<std::is_assignable_v<CUniquePointer<T>&, X>, CUniquePointer&>;
|
||||
template <typename X>
|
||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
||||
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||
|
||||
/* creates a new unique pointer managing a resource
|
||||
avoid calling. Could duplicate ownership. Prefer makeUnique */
|
||||
explicit CUniquePointer(T* object) noexcept {
|
||||
impl_ = new Impl_::impl<T>(object, false);
|
||||
explicit CUniquePointer(T* object) noexcept : impl_(new Impl_::impl<T>(object, false)) {
|
||||
increment();
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +62,7 @@ namespace Hyprutils {
|
|||
return *this;
|
||||
}
|
||||
|
||||
CUniquePointer& operator=(CUniquePointer&& rhs) {
|
||||
CUniquePointer& operator=(CUniquePointer&& rhs) noexcept {
|
||||
std::swap(impl_, rhs.impl_);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ namespace Hyprutils {
|
|||
class CWeakPointer {
|
||||
public:
|
||||
template <typename X>
|
||||
using validHierarchy = typename std::enable_if<std::is_assignable<CWeakPointer<T>&, X>::value, CWeakPointer&>::type;
|
||||
using validHierarchy = std::enable_if_t<std::is_assignable_v<CWeakPointer<T>&, X>, CWeakPointer&>;
|
||||
template <typename X>
|
||||
using isConstructible = typename std::enable_if<std::is_constructible<T&, X&>::value>::type;
|
||||
using isConstructible = std::enable_if_t<std::is_constructible_v<T&, X&>>;
|
||||
|
||||
/* create a weak ptr from a reference */
|
||||
template <typename U, typename = isConstructible<U>>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using namespace Hyprutils::Animation;
|
|||
using namespace Hyprutils::Memory;
|
||||
|
||||
static const std::string DEFAULTBEZIERNAME = "default";
|
||||
static const std::string DEFAULTSTYLE = "";
|
||||
static const std::string DEFAULTSTYLE = "";
|
||||
|
||||
#define SP CSharedPointer
|
||||
#define WP CWeakPointer
|
||||
|
|
|
|||
|
|
@ -9,12 +9,21 @@ using namespace Hyprutils::Math;
|
|||
using namespace Hyprutils::Memory;
|
||||
|
||||
void CBezierCurve::setup(const std::array<Vector2D, 2>& pVec) {
|
||||
// Avoid reallocations by reserving enough memory upfront
|
||||
m_vPoints.resize(pVec.size() + 2);
|
||||
m_vPoints = {
|
||||
setup4(std::array<Vector2D, 4>{
|
||||
Vector2D(0, 0), // Start point
|
||||
pVec[0], pVec[1], // Control points
|
||||
Vector2D(1, 1) // End point
|
||||
});
|
||||
}
|
||||
|
||||
void CBezierCurve::setup4(const std::array<Vector2D, 4>& pVec) {
|
||||
// Avoid reallocations by reserving enough memory upfront
|
||||
m_vPoints.resize(4);
|
||||
m_vPoints = {
|
||||
pVec[0],
|
||||
pVec[1],
|
||||
pVec[2],
|
||||
pVec[3],
|
||||
};
|
||||
|
||||
if (m_vPoints.size() != 4)
|
||||
|
|
@ -37,14 +46,14 @@ float CBezierCurve::getXForT(float const& t) const {
|
|||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
|
||||
return (3 * t * (1 - t) * (1 - t) * m_vPoints[1].x) + (3 * t2 * (1 - t) * m_vPoints[2].x) + (t3 * m_vPoints[3].x);
|
||||
return ((1 - t) * (1 - t) * (1 - t) * m_vPoints[0].x) + (3 * t * (1 - t) * (1 - t) * m_vPoints[1].x) + (3 * t2 * (1 - t) * m_vPoints[2].x) + (t3 * m_vPoints[3].x);
|
||||
}
|
||||
|
||||
float CBezierCurve::getYForT(float const& t) const {
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
|
||||
return (3 * t * (1 - t) * (1 - t) * m_vPoints[1].y) + (3 * t2 * (1 - t) * m_vPoints[2].y) + (t3 * m_vPoints[3].y);
|
||||
return ((1 - t) * (1 - t) * (1 - t) * m_vPoints[0].y) +(3 * t * (1 - t) * (1 - t) * m_vPoints[1].y) + (3 * t2 * (1 - t) * m_vPoints[2].y) + (t3 * m_vPoints[3].y);
|
||||
}
|
||||
|
||||
// Todo: this probably can be done better and faster
|
||||
|
|
|
|||
|
|
@ -145,16 +145,14 @@ CRegion& Hyprutils::Math::CRegion::scale(const Vector2D& scale) {
|
|||
if (scale == Vector2D{1, 1})
|
||||
return *this;
|
||||
|
||||
auto rects = getRects();
|
||||
int rectsNum = 0;
|
||||
auto RECTSARR = pixman_region32_rectangles(&m_rRegion, &rectsNum);
|
||||
|
||||
clear();
|
||||
|
||||
for (auto& r : rects) {
|
||||
r.x1 = std::floor(r.x1 * scale.x);
|
||||
r.y1 = std::floor(r.y1 * scale.y);
|
||||
r.x2 = std::ceil(r.x2 * scale.x);
|
||||
r.y2 = std::ceil(r.y2 * scale.y);
|
||||
add(&r);
|
||||
for (int i = 0; i < rectsNum; ++i) {
|
||||
RECTSARR[i].x1 = std::floor(RECTSARR[i].x1 * scale.x);
|
||||
RECTSARR[i].x2 = std::ceil(RECTSARR[i].x2 * scale.x);
|
||||
RECTSARR[i].y1 = std::floor(RECTSARR[i].y1 * scale.y);
|
||||
RECTSARR[i].y2 = std::ceil(RECTSARR[i].y2 * scale.y);
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
|
|
|||
|
|
@ -5,21 +5,6 @@
|
|||
#include <cmath>
|
||||
|
||||
using namespace Hyprutils::Math;
|
||||
using namespace Hyprutils::Memory;
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D(double xx, double yy) : x(xx), y(yy) {
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D(int xx, int yy) : x(sc<double>(xx)), y(sc<double>(yy)) {
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::Vector2D() : x(0), y(0) {
|
||||
;
|
||||
}
|
||||
|
||||
Hyprutils::Math::Vector2D::~Vector2D() {}
|
||||
|
||||
double Hyprutils::Math::Vector2D::normalize() {
|
||||
// get max abs
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ CConstVarList::CConstVarList(const std::string& in, const size_t lastArgNo, cons
|
|||
if (in.empty())
|
||||
return;
|
||||
|
||||
size_t idx = 0;
|
||||
size_t pos = 0;
|
||||
size_t idx = 0;
|
||||
size_t pos = 0;
|
||||
std::ranges::replace_if(m_str, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0);
|
||||
|
||||
for (const auto& s : m_str | std::views::split(0)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue