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
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -27,5 +27,3 @@ namespace Hyprutils::Memory {
|
|||
return std::bit_cast<To>(from);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue