Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
Spring.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
7#include <PhosphorAnimation/phosphoranimation_export.h>
8
9#include <QString>
10#include <QtGlobal>
11
12namespace PhosphorAnimation {
13
18class PHOSPHORANIMATION_EXPORT Spring final : public Curve
19{
20public:
21 Spring() = default;
22 Spring(qreal omega, qreal zeta);
23
24 Spring(const Spring&) = default;
25 Spring& operator=(const Spring&) = default;
26 Spring(Spring&&) = default;
27 Spring& operator=(Spring&&) = default;
28
29 QString typeId() const override;
30 qreal evaluate(qreal t) const override;
31 void step(qreal dt, CurveState& state, qreal target) const override;
32 bool isStateful() const override
33 {
34 return true;
35 }
36 qreal settleTime() const override;
37 QString toString() const override;
38 std::unique_ptr<Curve> clone() const override;
40 bool overshoots() const override;
41 bool equals(const Curve& other) const override;
42
44 static Spring fromString(const QString& str);
45
46 static Spring snappy();
47 static Spring smooth();
48 static Spring bouncy();
49
50 qreal omega = 12.0;
51 qreal zeta = 0.8;
52
53 bool operator==(const Spring& other) const;
54 bool operator!=(const Spring& other) const
55 {
56 return !(*this == other);
57 }
58};
59
60} // namespace PhosphorAnimation
Polymorphic base for all animation curves.
Definition Curve.h:44
Damped harmonic oscillator.
Definition Spring.h:19
bool equals(const Curve &other) const override
Same typeId + same parameters.
std::unique_ptr< Curve > clone() const override
Deep copy with identical parameters.
bool operator==(const Spring &other) const
Spring & operator=(const Spring &)=default
Spring(qreal omega, qreal zeta)
QString typeId() const override
Stable identifier for this curve subclass (e.g. "bezier", "spring").
static Spring snappy()
Responsive, slight overshoot.
static Spring smooth()
Critically damped, no overshoot.
Spring(Spring &&)=default
Spring & operator=(Spring &&)=default
qreal settleTime() const override
Approximate settle time in seconds.
bool operator!=(const Spring &other) const
Definition Spring.h:54
static Spring fromString(const QString &str)
Parse from "spring:omega,zeta" or "omega,zeta". Clamps to valid ranges.
Spring(const Spring &)=default
static Spring bouncy()
Visible bounce.
qreal evaluate(qreal t) const override
Evaluate at normalized time t in [0,1]. May overshoot by design.
void step(qreal dt, CurveState &state, qreal target) const override
Advance state by dt real seconds toward target.
bool isStateful() const override
True if this curve requires persistent CurveState across frames.
Definition Spring.h:32
bool overshoots() const override
True for underdamped (zeta < 1). Critical/overdamped never overshoot.
QString toString() const override
Serialize to "typeId:params" or bare "x1,y1,x2,y2" for cubic-bezier.
Definition AnimatedValue.h:31
Mutable state for stateful curve progression (springs carry position+velocity across frames; stateles...
Definition Curve.h:19