2014-08-20 15:02:41 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vspline_p.h
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 20 8, 2014
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2014-08-20 15:02:41 +02:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2014-08-20 15:02:41 +02:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#ifndef VSPLINE_P_H
|
|
|
|
#define VSPLINE_P_H
|
|
|
|
|
|
|
|
#include <QLineF>
|
2023-07-13 16:49:20 +02:00
|
|
|
#include <QSharedData>
|
2022-11-21 17:49:41 +01:00
|
|
|
#include <QtMath>
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2023-07-13 16:42:22 +02:00
|
|
|
#include "../vmisc/vabstractvalapplication.h"
|
2016-02-26 15:38:42 +01:00
|
|
|
#include "vpointf.h"
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
2017-05-30 17:44:16 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
|
2014-08-23 08:18:07 +02:00
|
|
|
|
2021-09-25 10:43:05 +02:00
|
|
|
class VSplineData final : public QSharedData
|
2014-08-20 15:02:41 +02:00
|
|
|
{
|
|
|
|
public:
|
2023-07-13 16:49:20 +02:00
|
|
|
VSplineData() = default;
|
|
|
|
VSplineData(const VSplineData &spline) = default;
|
|
|
|
VSplineData(const VPointF &p1, const VPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2,
|
|
|
|
qreal kCurve);
|
|
|
|
VSplineData(const VPointF &p1, QPointF p2, QPointF p3, const VPointF &p4);
|
|
|
|
VSplineData(const VPointF &p1, const VPointF &p4, qreal angle1, const QString &angle1F, qreal angle2,
|
|
|
|
const QString &angle2F, qreal c1Length, const QString &c1LengthF, qreal c2Length,
|
|
|
|
const QString &c2LengthF);
|
|
|
|
~VSplineData() = default;
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
static auto GetL(const QPointF &p1, const QPointF &p4, qreal kCurve) -> qreal;
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
/** @brief p1 first spline point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
VPointF p1{}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
/** @brief p4 fourth spline point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
VPointF p4{}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
|
|
|
/** @brief angle1 first angle control line. */
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal angle1{0}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
/** @brief angle1F the first control point angle formula*/
|
2023-07-13 16:49:20 +02:00
|
|
|
QString angle1F{'0'}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
|
|
|
/** @brief angle2 second angle control line. */
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal angle2{0}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
/** @brief angle2F the second control point angle formula*/
|
2023-07-13 16:49:20 +02:00
|
|
|
QString angle2F{'0'}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
/** @brief c1Length the length from the first spline point to the first control point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal c1Length{0}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
/** @brief c1LengthF the formula from the first spline point to the first control point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
QString c1LengthF{'0'}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
/** @brief c2Length the length from the fourth spline point to the second control point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal c2Length{0}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
/** @brief c2LengthF the formula length from the fourth spline point to the second control point. */
|
2023-07-13 16:49:20 +02:00
|
|
|
QString c2LengthF{'0'}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2014-08-20 15:02:41 +02:00
|
|
|
|
|
|
|
/** @brief kCurve coefficient of curvature spline. */
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal kCurve{1}; // NOLINT(misc-non-private-member-variables-in-classes)
|
2015-10-31 13:56:28 +01:00
|
|
|
|
|
|
|
private:
|
2023-05-02 16:38:30 +02:00
|
|
|
Q_DISABLE_ASSIGN_MOVE(VSplineData) // NOLINT
|
2014-08-20 15:02:41 +02:00
|
|
|
};
|
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
inline VSplineData::VSplineData(const VPointF &p1, const VPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
|
|
|
|
qreal kAsm2, qreal kCurve)
|
|
|
|
: p1(p1),
|
|
|
|
p4(p4),
|
|
|
|
angle1(angle1),
|
|
|
|
angle1F(QString::number(angle1)),
|
|
|
|
angle2(angle2),
|
|
|
|
angle2F(QString::number(angle2)),
|
|
|
|
kCurve(kCurve)
|
2016-02-24 20:47:39 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
const qreal L = GetL(static_cast<QPointF>(p1), static_cast<QPointF>(p4), kCurve);
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y());
|
|
|
|
p1p2.setAngle(angle1);
|
|
|
|
c1Length = p1p2.length();
|
2023-08-05 16:51:23 +02:00
|
|
|
if (VAbstractValApplication::VApp())
|
|
|
|
{
|
|
|
|
c1LengthF = QString::number(VAbstractValApplication::VApp()->fromPixel(c1Length));
|
|
|
|
}
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
QLineF p4p3(p4.x(), p4.y(), p4.x() + L * kAsm2, p4.y());
|
|
|
|
p4p3.setAngle(angle2);
|
|
|
|
c2Length = p4p3.length();
|
2023-08-05 16:51:23 +02:00
|
|
|
if (VAbstractValApplication::VApp())
|
|
|
|
{
|
|
|
|
c2LengthF = QString::number(VAbstractValApplication::VApp()->fromPixel(c2Length));
|
|
|
|
}
|
2016-02-24 20:47:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
inline VSplineData::VSplineData(const VPointF &p1, QPointF p2, QPointF p3, const VPointF &p4)
|
|
|
|
: p1(p1),
|
|
|
|
p4(p4)
|
2016-02-24 20:47:39 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF p1p2(static_cast<QPointF>(p1), static_cast<QPointF>(p2));
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
angle1 = p1p2.angle();
|
2023-07-13 16:49:20 +02:00
|
|
|
angle1F = QString::number(angle1);
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
c1Length = p1p2.length();
|
2023-08-05 16:51:23 +02:00
|
|
|
if (VAbstractValApplication::VApp())
|
|
|
|
{
|
|
|
|
c1LengthF = QString::number(VAbstractValApplication::VApp()->fromPixel(c1Length));
|
|
|
|
}
|
2016-02-24 20:47:39 +01:00
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
QLineF p4p3(static_cast<QPointF>(p4), static_cast<QPointF>(p3));
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
angle2 = p4p3.angle();
|
2023-07-13 16:49:20 +02:00
|
|
|
angle2F = QString::number(angle2);
|
2016-02-24 20:47:39 +01:00
|
|
|
|
|
|
|
c2Length = p4p3.length();
|
2023-08-05 16:51:23 +02:00
|
|
|
if (VAbstractValApplication::VApp())
|
|
|
|
{
|
|
|
|
c2LengthF = QString::number(VAbstractValApplication::VApp()->fromPixel(c2Length));
|
|
|
|
}
|
2016-02-24 20:47:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
inline VSplineData::VSplineData(const VPointF &p1, const VPointF &p4, qreal angle1, const QString &angle1F,
|
|
|
|
qreal angle2, const QString &angle2F, qreal c1Length, const QString &c1LengthF,
|
|
|
|
qreal c2Length, const QString &c2LengthF)
|
|
|
|
: p1(p1),
|
|
|
|
p4(p4),
|
|
|
|
angle1(angle1),
|
|
|
|
angle1F(angle1F),
|
|
|
|
angle2(angle2),
|
|
|
|
angle2F(angle2F),
|
|
|
|
c1Length(c1Length),
|
|
|
|
c1LengthF(c1LengthF),
|
|
|
|
c2Length(c2Length),
|
|
|
|
c2LengthF(c2LengthF)
|
|
|
|
{
|
|
|
|
}
|
2014-09-11 18:52:02 +02:00
|
|
|
|
2016-02-24 20:47:39 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
inline auto VSplineData::GetL(const QPointF &p1, const QPointF &p4, qreal kCurve) -> qreal
|
2016-02-24 20:47:39 +01:00
|
|
|
{
|
|
|
|
static const qreal angle = 90;
|
2023-07-13 16:49:20 +02:00
|
|
|
qreal length = VFuzzyComparePoints(p1, p4) ? accuracyPointOnLine * 2 : QLineF(p1, p4).length();
|
|
|
|
const qreal radius = length / M_SQRT2;
|
|
|
|
return kCurve * radius * 4 / 3 * qTan(angle * M_PI_4 / 180.0);
|
2016-02-24 20:47:39 +01:00
|
|
|
}
|
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2014-08-20 15:02:41 +02:00
|
|
|
|
|
|
|
#endif // VSPLINE_P_H
|