2016-03-08 18:48:10 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vcubicbezier.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 8 3, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-03-08 18:48:10 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
** Copyright (C) 2016 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2016-03-08 18:48:10 +01: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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vcubicbezier.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
2016-03-08 18:48:10 +01:00
|
|
|
#include "vcubicbezier_p.h"
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezier::VCubicBezier()
|
|
|
|
: VAbstractCubicBezier(GOType::CubicBezier), d(new VCubicBezierData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezier::VCubicBezier(const VCubicBezier &curve)
|
|
|
|
: VAbstractCubicBezier(curve), d(curve.d)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezier::VCubicBezier(const VPointF &p1, const VPointF &p2, const VPointF &p3, const VPointF &p4, quint32 idObject,
|
|
|
|
Draw mode)
|
|
|
|
: VAbstractCubicBezier(GOType::CubicBezier, idObject, mode), d(new VCubicBezierData(p1, p2, p3, p4))
|
|
|
|
{
|
|
|
|
CreateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::operator=(const VCubicBezier &curve) -> VCubicBezier &
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
|
|
|
if ( &curve == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VAbstractCubicBezier::operator=(curve);
|
|
|
|
d = curve.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VCubicBezier::VCubicBezier(VCubicBezier &&curve) noexcept
|
2022-08-12 17:50:13 +02:00
|
|
|
: VAbstractCubicBezier(std::move(curve)), d(std::move(curve.d))
|
2019-12-30 16:13:18 +01:00
|
|
|
{}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
auto VCubicBezier::operator=(VCubicBezier &&curve) noexcept->VCubicBezier &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VAbstractCubicBezier::operator=(curve);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, curve.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2016-04-10 13:40:04 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const -> VCubicBezier
|
2016-04-10 13:40:04 +02:00
|
|
|
{
|
|
|
|
const VPointF p1 = GetP1().Rotate(originPoint, degrees);
|
|
|
|
const VPointF p2 = GetP2().Rotate(originPoint, degrees);
|
|
|
|
const VPointF p3 = GetP3().Rotate(originPoint, degrees);
|
|
|
|
const VPointF p4 = GetP4().Rotate(originPoint, degrees);
|
|
|
|
VCubicBezier curve(p1, p2, p3, p4);
|
|
|
|
curve.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
curve.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
curve.SetColor(GetColor());
|
|
|
|
curve.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
curve.SetApproximationScale(GetApproximationScale());
|
2016-04-10 13:40:04 +02:00
|
|
|
return curve;
|
2016-09-10 20:40:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const -> VCubicBezier
|
2016-09-10 20:40:30 +02:00
|
|
|
{
|
|
|
|
const VPointF p1 = GetP1().Flip(axis);
|
|
|
|
const VPointF p2 = GetP2().Flip(axis);
|
|
|
|
const VPointF p3 = GetP3().Flip(axis);
|
|
|
|
const VPointF p4 = GetP4().Flip(axis);
|
|
|
|
VCubicBezier curve(p1, p2, p3, p4);
|
|
|
|
curve.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
curve.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
curve.SetColor(GetColor());
|
|
|
|
curve.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
curve.SetApproximationScale(GetApproximationScale());
|
2016-09-10 20:40:30 +02:00
|
|
|
return curve;
|
2016-04-10 13:40:04 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 16:34:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::Move(qreal length, qreal angle, const QString &prefix) const -> VCubicBezier
|
2016-10-04 16:34:37 +02:00
|
|
|
{
|
|
|
|
const VPointF p1 = GetP1().Move(length, angle);
|
|
|
|
const VPointF p2 = GetP2().Move(length, angle);
|
|
|
|
const VPointF p3 = GetP3().Move(length, angle);
|
|
|
|
const VPointF p4 = GetP4().Move(length, angle);
|
|
|
|
VCubicBezier curve(p1, p2, p3, p4);
|
|
|
|
curve.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
curve.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
curve.SetColor(GetColor());
|
|
|
|
curve.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
curve.SetApproximationScale(GetApproximationScale());
|
2016-10-04 16:34:37 +02:00
|
|
|
return curve;
|
|
|
|
}
|
|
|
|
|
2016-03-10 14:55:04 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VCubicBezier::~VCubicBezier()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-03-08 18:48:10 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetP1() const -> VPointF
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
|
|
|
return d->p1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCubicBezier::SetP1(const VPointF &p)
|
|
|
|
{
|
|
|
|
d->p1 = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetP2() const -> VPointF
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
|
|
|
return d->p2;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCubicBezier::SetP2(const VPointF &p)
|
|
|
|
{
|
|
|
|
d->p2 = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetP3() const -> VPointF
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
|
|
|
return d->p3;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCubicBezier::SetP3(const VPointF &p)
|
|
|
|
{
|
|
|
|
d->p3 = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetP4() const -> VPointF
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
|
|
|
return d->p4;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VCubicBezier::SetP4(const VPointF &p)
|
|
|
|
{
|
|
|
|
d->p4 = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetStartAngle() const -> qreal
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return QLineF(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2())).angle();
|
2016-03-08 18:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetEndAngle() const -> qreal
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return QLineF(static_cast<QPointF>(GetP4()), static_cast<QPointF>(GetP3())).angle();
|
2016-03-08 18:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetLength return length of cubic bezier curve.
|
|
|
|
* @return length.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetLength() const -> qreal
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return LengthBezier (static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2()),
|
2017-10-11 12:51:06 +02:00
|
|
|
static_cast<QPointF>(GetP3()), static_cast<QPointF>(GetP4()), GetApproximationScale());
|
2016-03-08 18:48:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief GetPoints return list with cubic bezier curve points.
|
|
|
|
* @return list of points.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetPoints() const -> QVector<QPointF>
|
2016-03-08 18:48:10 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return GetCubicBezierPoints(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2()),
|
2017-10-11 12:51:06 +02:00
|
|
|
static_cast<QPointF>(GetP3()), static_cast<QPointF>(GetP4()), GetApproximationScale());
|
2016-03-08 18:48:10 +01:00
|
|
|
}
|
2016-03-10 17:09:38 +01:00
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetC1Length() const -> qreal
|
2016-09-24 19:44:06 +02:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return QLineF(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2())).length();
|
2016-09-24 19:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetC2Length() const -> qreal
|
2016-09-24 19:44:06 +02:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return QLineF(static_cast<QPointF>(GetP4()), static_cast<QPointF>(GetP3())).length();
|
2016-09-24 19:44:06 +02:00
|
|
|
}
|
|
|
|
|
2016-03-10 17:09:38 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetControlPoint1() const -> QPointF
|
2016-03-10 17:09:38 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return static_cast<QPointF>(GetP2());
|
2016-03-10 17:09:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetControlPoint2() const -> QPointF
|
2016-03-10 17:09:38 +01:00
|
|
|
{
|
2017-03-31 16:04:11 +02:00
|
|
|
return static_cast<QPointF>(GetP3());
|
2016-03-10 17:09:38 +01:00
|
|
|
}
|
2022-02-03 14:48:52 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VCubicBezier::GetRealLength() const -> qreal
|
2022-02-03 14:48:52 +01:00
|
|
|
{
|
|
|
|
return LengthBezier (static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2()),
|
|
|
|
static_cast<QPointF>(GetP3()), static_cast<QPointF>(GetP4()), maxCurveApproximationScale);
|
|
|
|
}
|