Krita Source Code Documentation
Loading...
Searching...
No Matches
KisScatterOption.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3 * SPDX-FileCopyrightText: 2011 Silvio Heinrich <plassy@web.de>
4 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8#include "KisScatterOption.h"
9
10#include <QVector2D>
11
15
17namespace kpou = KisPaintOpOptionUtils;
18
19
24
26 : KisCurveOption(data)
27 , m_axisX(data.axisX)
28 , m_axisY(data.axisY)
29{
30}
31
32QPointF KisScatterOption::apply(const KisPaintInformation& info, qreal width, qreal height) const
33{
34 if ((!m_axisX && !m_axisY) || (!isChecked())) {
35 return info.pos();
36 }
37
38 // just use the most significant dimension for calculations
39 qreal diameter = qMax(width, height);
40 qreal sensorValue = computeSizeLikeValue(info);
41
42 qreal jitter = (2.0 * info.randomSource()->generateNormalized() - 1.0) * diameter * sensorValue;
43 QPointF result(0.0, 0.0);
44
45 if (m_axisX && m_axisY) {
46 qreal jitterY = (2.0 * info.randomSource()->generateNormalized() - 1.0) * diameter * sensorValue;
47 result = QPointF(jitter, jitterY);
48 return info.pos() + result;
49 }
50
51 qreal drawingAngle = info.drawingAngle();
52 QVector2D movement(cos(drawingAngle), sin(drawingAngle));
53 if (m_axisX) {
54 movement *= jitter;
55 result = movement.toPointF();
56 }
57 else if (m_axisY) {
58 QVector2D movementNormal(-movement.y(), movement.x());
59 movementNormal *= jitter;
60 result = movementNormal.toPointF();
61 }
62
63 return info.pos() + result;
64}
bool isChecked() const
qreal computeSizeLikeValue(const KisPaintInformation &info, bool useStrengthValue=true) const
KisRandomSourceSP randomSource() const
const QPointF & pos() const
qreal drawingAngle(bool considerLockedAngle=false) const
qreal generateNormalized() const
QPointF apply(const KisPaintInformation &info, qreal width, qreal height) const
KisScatterOption(const KisPropertiesConfiguration *setting)