Warning, file /graphics/washipad/src/pressureequation.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // This file is part of Washi Pad
0002 // SPDX-FileCopyrightText: 2018 Kevin Ottens <ervin@kde.org>
0003 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #include "pressureequation.h"
0006 
0007 #include <cmath>
0008 #include <QDebug>
0009 
0010 namespace {
0011     float sigmoid(float x)
0012     {
0013         const auto lambda = 5.0f;
0014         return 1.0f / (1.0f + std::exp(-lambda * x));
0015     }
0016 
0017     float computeWidth(float minWidth, float maxWidth, float pressure)
0018     {
0019         const auto alpha = sigmoid(2.0f * pressure - 1.0f);
0020         return (1.0f - alpha) * minWidth + alpha * maxWidth;
0021     }
0022 }
0023 
0024 float PressureEquation::minWidth() const
0025 {
0026     return m_minWidth;
0027 }
0028 
0029 float PressureEquation::maxWidth() const
0030 {
0031     return m_maxWidth;
0032 }
0033 
0034 float PressureEquation::pressure() const
0035 {
0036     return m_pressure;
0037 }
0038 
0039 float PressureEquation::width() const
0040 {
0041     return m_width;
0042 }
0043 
0044 void PressureEquation::setMinWidth(float minWidth)
0045 {
0046     if (qFuzzyCompare(m_minWidth, minWidth))
0047         return;
0048 
0049     m_minWidth = minWidth;
0050     emit minWidthChanged(minWidth);
0051     updateWidth();
0052 }
0053 
0054 void PressureEquation::setMaxWidth(float maxWidth)
0055 {
0056     if (qFuzzyCompare(m_maxWidth, maxWidth))
0057         return;
0058 
0059     m_maxWidth = maxWidth;
0060     emit maxWidthChanged(maxWidth);
0061     updateWidth();
0062 }
0063 
0064 void PressureEquation::setPressure(float pressure)
0065 {
0066     if (qFuzzyCompare(m_pressure, pressure))
0067         return;
0068 
0069     m_pressure = pressure;
0070     emit pressureChanged(pressure);
0071     updateWidth();
0072 }
0073 
0074 void PressureEquation::updateWidth()
0075 {
0076     m_width = computeWidth(m_minWidth, m_maxWidth, m_pressure);
0077     emit widthChanged(m_width);
0078 }