Krita Source Code Documentation
Loading...
Searching...
No Matches
KisStrokeEfficiencyMeasurer.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QPointF>
10#include <QVector>
11#include <QElapsedTimer>
12
13#include <boost/optional.hpp>
14
15#include "kis_global.h"
16
18{
19 boost::optional<QPointF> lastSamplePos;
20 qreal distance = 0;
21
22 QElapsedTimer strokeTimeSource;
23 bool isEnabled = true;
24
27
30
31 int framesCount = 0;
32
33};
34
36 : m_d(new Private())
37{
38 m_d->strokeTimeSource.start();
39}
40
44
46{
47 m_d->isEnabled = value;
48}
49
51{
52 return m_d->isEnabled;
53}
54
56{
57 if (!m_d->isEnabled) return;
58
59 if (!m_d->lastSamplePos) {
60 m_d->lastSamplePos = pt;
61 } else {
62 m_d->distance += kisDistance(pt, *m_d->lastSamplePos);
63 *m_d->lastSamplePos = pt;
64 }
65}
66
68{
69 if (!m_d->isEnabled) return;
70
71 Q_FOREACH (const QPointF &pt, points) {
72 addSample(pt);
73 }
74}
75
77{
78 m_d->renderingStartTime = m_d->strokeTimeSource.elapsed();
79}
80
82{
83 m_d->renderingTime = m_d->strokeTimeSource.elapsed() - m_d->renderingStartTime;
84}
85
87{
88 m_d->cursorMoveStartTime = m_d->strokeTimeSource.elapsed();
89}
90
92{
93 m_d->cursorMoveTime = m_d->strokeTimeSource.elapsed() - m_d->cursorMoveStartTime;
94}
95
100
102{
103 return m_d->cursorMoveTime ? m_d->distance / m_d->cursorMoveTime : 0.0;
104}
105
107{
108 return m_d->renderingTime ? m_d->distance / m_d->renderingTime : 0.0;
109}
110
112{
113 return m_d->renderingTime ? m_d->framesCount * 1000.0 / m_d->renderingTime : 0.0;
114}
115
116
float value(const T *src, size_t ch)
const QScopedPointer< Private > m_d
void addSamples(const QVector< QPointF > &points)
qreal kisDistance(const QPointF &pt1, const QPointF &pt2)
Definition kis_global.h:190