mirror of
https://github.com/hyprwm/hyprutils.git
synced 2025-12-20 08:10:10 +01:00
bezier: add setup4
This commit is contained in:
parent
64446e1a4c
commit
a20932e200
5 changed files with 18 additions and 9 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -27,5 +27,3 @@ namespace Hyprutils::Memory {
|
|||
return std::bit_cast<To>(from);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Reference in a new issue