Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Curve.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorAnimation/phosphoranimation_export.h>
7
8#include <QString>
9#include <QtGlobal>
10
11#include <memory>
12
13namespace PhosphorAnimation {
14
18struct PHOSPHORANIMATION_EXPORT CurveState
19{
20 qreal value = 0.0;
21 qreal velocity = 0.0;
22 qreal time = 0.0;
26 qreal startValue = 0.0;
28 qreal duration = 1.0;
29};
30
43class PHOSPHORANIMATION_EXPORT Curve
44{
45public:
46 virtual ~Curve() = default;
47
49 virtual QString typeId() const = 0;
50
52 virtual qreal evaluate(qreal t) const = 0;
53
58 virtual void step(qreal dt, CurveState& state, qreal target) const;
59
61 virtual bool isStateful() const
62 {
63 return false;
64 }
65
67 virtual bool overshoots() const
68 {
69 return false;
70 }
71
74 virtual qreal settleTime() const
75 {
76 return 1.0;
77 }
78
81 virtual QString toString() const = 0;
82
84 virtual std::unique_ptr<Curve> clone() const = 0;
85
88 virtual bool equals(const Curve& other) const;
89
90protected:
91 // Protected copy/move prevents slicing outside the hierarchy while
92 // allowing subclasses to default their own copy/move for value semantics.
93 Curve() = default;
94 Curve(const Curve&) = default;
95 Curve& operator=(const Curve&) = default;
96 Curve(Curve&&) = default;
97 Curve& operator=(Curve&&) = default;
98};
99
100} // namespace PhosphorAnimation
Polymorphic base for all animation curves.
Definition Curve.h:44
virtual void step(qreal dt, CurveState &state, qreal target) const
Advance state by dt real seconds toward target.
virtual QString toString() const =0
Serialize to "typeId:params" or bare "x1,y1,x2,y2" for cubic-bezier.
virtual qreal settleTime() const
Approximate settle time in seconds.
Definition Curve.h:74
Curve(Curve &&)=default
Curve(const Curve &)=default
virtual std::unique_ptr< Curve > clone() const =0
Deep copy with identical parameters.
Curve & operator=(Curve &&)=default
virtual ~Curve()=default
virtual bool overshoots() const
True if this curve may evaluate outside [0,1] during progression.
Definition Curve.h:67
Curve & operator=(const Curve &)=default
virtual QString typeId() const =0
Stable identifier for this curve subclass (e.g. "bezier", "spring").
virtual qreal evaluate(qreal t) const =0
Evaluate at normalized time t in [0,1]. May overshoot by design.
virtual bool equals(const Curve &other) const
Same typeId + same parameters.
virtual bool isStateful() const
True if this curve requires persistent CurveState across frames.
Definition Curve.h:61
Definition AnimatedValue.h:31
Mutable state for stateful curve progression (springs carry position+velocity across frames; stateles...
Definition Curve.h:19