bezier: add setup4

This commit is contained in:
Vaxry 2025-09-30 13:56:31 +01:00
parent 64446e1a4c
commit a20932e200
Signed by: vaxry
GPG key ID: 665806380871D640
5 changed files with 18 additions and 9 deletions

View file

@ -15,6 +15,8 @@ namespace Hyprutils {
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);
/* 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;

View file

@ -27,5 +27,3 @@ namespace Hyprutils::Memory {
return std::bit_cast<To>(from);
}
}

View file

@ -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)