KWin
Loading...
Searching...
No Matches
springmotion.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QtGlobal>
10
11#include <chrono>
12
13namespace KWin
14{
15
22{
23public:
26
30 void advance(std::chrono::milliseconds delta);
31 bool isMoving() const;
32
36 qreal velocity() const;
37 void setVelocity(qreal velocity);
38
42 qreal position() const;
43 void setPosition(qreal position);
44
48 qreal anchor() const;
49 void setAnchor(qreal anchor);
50
54 qreal springConstant() const;
55
66 qreal dampingRatio() const;
67
72 qreal epsilon() const;
73 void setEpsilon(qreal epsilon);
74
75private:
76 struct State
77 {
78 qreal position;
79 qreal velocity;
80 };
81
82 struct Slope
83 {
84 qreal dp;
85 qreal dv;
86 };
87
88 State integrate(const State &state, qreal dt);
89 Slope evaluate(const State &state, qreal dt, const Slope &slope);
90
91 State m_prev;
92 State m_next;
93 qreal m_t;
94 qreal m_timestep;
95
96 qreal m_anchor;
97 qreal m_springConstant;
98 qreal m_dampingRatio;
99 qreal m_dampingCoefficient;
100 qreal m_epsilon;
101};
102
103} // namespace KWin
qreal springConstant() const
void setEpsilon(qreal epsilon)
void advance(std::chrono::milliseconds delta)
qreal velocity() const
void setPosition(qreal position)
void setAnchor(qreal anchor)
qreal epsilon() const
void setVelocity(qreal velocity)
bool isMoving() const
qreal position() const
qreal anchor() const
qreal dampingRatio() const