From c9c46cc9548c3f21a2e9c7088f134c4f6df2ba16 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 20 May 2022 17:08:32 +0300 Subject: [PATCH] Code style. --- src/libs/vgeometry/vabstractarc.cpp | 27 +- src/libs/vgeometry/vabstractarc.h | 52 ++-- src/libs/vgeometry/vabstractcubicbezier.cpp | 36 +-- src/libs/vgeometry/vabstractcubicbezier.h | 43 +-- .../vgeometry/vabstractcubicbezierpath.cpp | 43 ++- src/libs/vgeometry/vabstractcubicbezierpath.h | 46 ++-- src/libs/vgeometry/varc.cpp | 250 +++++++++--------- src/libs/vgeometry/varc.h | 57 ++-- src/libs/vgeometry/vellipticalarc.cpp | 64 ++--- src/libs/vgeometry/vellipticalarc.h | 103 ++++---- src/libs/vgeometry/vspline.cpp | 113 ++++---- src/libs/vgeometry/vspline.h | 104 ++++---- .../toolcut/vtoolcutspline.cpp | 2 +- 13 files changed, 474 insertions(+), 466 deletions(-) diff --git a/src/libs/vgeometry/vabstractarc.cpp b/src/libs/vgeometry/vabstractarc.cpp index 3aee72f97..bd321c58d 100644 --- a/src/libs/vgeometry/vabstractarc.cpp +++ b/src/libs/vgeometry/vabstractarc.cpp @@ -67,7 +67,7 @@ VAbstractArc::VAbstractArc(const VAbstractArc &arc) {} //--------------------------------------------------------------------------------------------------------------------- -VAbstractArc &VAbstractArc::operator=(const VAbstractArc &arc) +auto VAbstractArc::operator=(const VAbstractArc &arc) -> VAbstractArc & { if ( &arc == this ) { @@ -81,11 +81,12 @@ VAbstractArc &VAbstractArc::operator=(const VAbstractArc &arc) #ifdef Q_COMPILER_RVALUE_REFS //--------------------------------------------------------------------------------------------------------------------- VAbstractArc::VAbstractArc(VAbstractArc &&arc) Q_DECL_NOTHROW - : VAbstractCurve(arc), d (arc.d) + : VAbstractCurve(std::move(arc)), + d(std::move(arc.d)) {} //--------------------------------------------------------------------------------------------------------------------- -VAbstractArc &VAbstractArc::operator=(VAbstractArc &&arc) Q_DECL_NOTHROW +auto VAbstractArc::operator=(VAbstractArc &&arc) Q_DECL_NOTHROW -> VAbstractArc & { VAbstractCurve::operator=(arc); std::swap(d, arc.d); @@ -94,11 +95,11 @@ VAbstractArc &VAbstractArc::operator=(VAbstractArc &&arc) Q_DECL_NOTHROW #endif //--------------------------------------------------------------------------------------------------------------------- -VAbstractArc::~VAbstractArc() +VAbstractArc::~VAbstractArc() // NOLINT(hicpp-use-equals-default, modernize-use-equals-default) {} //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractArc::GetFormulaF1() const +auto VAbstractArc::GetFormulaF1() const -> QString { return d->formulaF1; } @@ -111,13 +112,13 @@ void VAbstractArc::SetFormulaF1(const QString &formula, qreal value) } //--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractArc::GetStartAngle() const +auto VAbstractArc::GetStartAngle() const -> qreal { return d->f1; } //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractArc::GetFormulaF2() const +auto VAbstractArc::GetFormulaF2() const -> QString { return d->formulaF2; } @@ -130,13 +131,13 @@ void VAbstractArc::SetFormulaF2(const QString &formula, qreal value) } //--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractArc::GetEndAngle() const +auto VAbstractArc::GetEndAngle() const -> qreal { return d->f2; } //--------------------------------------------------------------------------------------------------------------------- -VPointF VAbstractArc::GetCenter() const +auto VAbstractArc::GetCenter() const -> VPointF { return d->center; } @@ -148,7 +149,7 @@ void VAbstractArc::SetCenter(const VPointF &point) } //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractArc::GetFormulaLength() const +auto VAbstractArc::GetFormulaLength() const -> QString { return d->formulaLength; } @@ -168,7 +169,7 @@ void VAbstractArc::setId(const quint32 &id) } //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractArc::NameForHistory(const QString &toolName) const +auto VAbstractArc::NameForHistory(const QString &toolName) const -> QString { QString name = toolName + QString(" %1").arg(GetCenter().name()); @@ -193,13 +194,13 @@ QString VAbstractArc::NameForHistory(const QString &toolName) const } //--------------------------------------------------------------------------------------------------------------------- -bool VAbstractArc::IsFlipped() const +auto VAbstractArc::IsFlipped() const -> bool { return d->isFlipped; } //--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractArc::AngleArc() const +auto VAbstractArc::AngleArc() const -> qreal { { const qreal angleDiff = qAbs(GetStartAngle() - GetEndAngle()); diff --git a/src/libs/vgeometry/vabstractarc.h b/src/libs/vgeometry/vabstractarc.h index 768422469..b979481ee 100644 --- a/src/libs/vgeometry/vabstractarc.h +++ b/src/libs/vgeometry/vabstractarc.h @@ -48,42 +48,42 @@ class VAbstractArc : public VAbstractCurve { public: explicit VAbstractArc(const GOType &type, const quint32 &idObject = NULL_ID, const Draw &mode = Draw::Calculation); - VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, - const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); - VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, qreal f2, quint32 idObject = 0, - Draw mode = Draw::Calculation); - VAbstractArc (const GOType &type, const QString &formulaLength, const VPointF ¢er, qreal f1, - const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); - VAbstractArc (const GOType &type, const VPointF ¢er, qreal f1, quint32 idObject = 0, - Draw mode = Draw::Calculation); - explicit VAbstractArc(const VAbstractArc &arc); - virtual ~VAbstractArc(); + VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); + VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, qreal f2, quint32 idObject = 0, + Draw mode = Draw::Calculation); + VAbstractArc(const GOType &type, const QString &formulaLength, const VPointF ¢er, qreal f1, + const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + VAbstractArc(const GOType &type, const VPointF ¢er, qreal f1, quint32 idObject = 0, + Draw mode = Draw::Calculation); + VAbstractArc(const VAbstractArc &arc); + ~VAbstractArc() override; - VAbstractArc& operator= (const VAbstractArc &arc); + auto operator= (const VAbstractArc &arc) -> VAbstractArc&; #ifdef Q_COMPILER_RVALUE_REFS VAbstractArc(VAbstractArc &&arc) Q_DECL_NOTHROW; - VAbstractArc &operator=(VAbstractArc &&arc) Q_DECL_NOTHROW; + auto operator=(VAbstractArc &&arc) Q_DECL_NOTHROW -> VAbstractArc &; #endif - QString GetFormulaF1 () const; - void SetFormulaF1 (const QString &formula, qreal value); - virtual qreal GetStartAngle () const override; + auto GetFormulaF1 () const -> QString; + void SetFormulaF1 (const QString &formula, qreal value); + auto GetStartAngle () const -> qreal override; - QString GetFormulaF2 () const; - void SetFormulaF2 (const QString &formula, qreal value); - virtual qreal GetEndAngle () const override; + auto GetFormulaF2 () const -> QString; + void SetFormulaF2 (const QString &formula, qreal value); + auto GetEndAngle () const -> qreal override; - virtual VPointF GetCenter () const; - void SetCenter (const VPointF &point); + auto GetCenter () const -> VPointF; + void SetCenter (const VPointF &point); - QString GetFormulaLength () const; - void SetFormulaLength (const QString &formula, qreal value); + auto GetFormulaLength () const -> QString; + void SetFormulaLength (const QString &formula, qreal value); - virtual void setId(const quint32 &id) override; - virtual QString NameForHistory(const QString &toolName) const override; + void setId(const quint32 &id) override; + auto NameForHistory(const QString &toolName) const -> QString override; - bool IsFlipped() const; - qreal AngleArc() const; + auto IsFlipped() const -> bool; + auto AngleArc() const -> qreal; protected: void SetFlipped(bool value); virtual void FindF2(qreal length)=0; diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 6b9e8b5ed..c7cbcb4b3 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -52,7 +52,7 @@ namespace * @param y2 у coordinate second point. * @return squared length. */ -inline qreal CalcSqDistance(qreal x1, qreal y1, qreal x2, qreal y2) +inline auto CalcSqDistance(qreal x1, qreal y1, qreal x2, qreal y2) -> qreal { const qreal dx = x2 - x1; const qreal dy = y2 - y1; @@ -74,8 +74,8 @@ inline qreal CalcSqDistance(qreal x1, qreal y1, qreal x2, qreal y2) * @param points spline points coordinates. * @param approximationScale curve approximation scale. */ -QVector PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, - qint16 level, QVector points, qreal approximationScale) +auto PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, + qint16 level, QVector points, qreal approximationScale) -> QVector { if (points.size() >= 2) { @@ -373,17 +373,10 @@ QVector PointBezier_r(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, //--------------------------------------------------------------------------------------------------------------------- VAbstractCubicBezier::VAbstractCubicBezier(const GOType &type, const quint32 &idObject, const Draw &mode) : VAbstractBezier(type, idObject, mode) -{ -} +{} //--------------------------------------------------------------------------------------------------------------------- -VAbstractCubicBezier::VAbstractCubicBezier(const VAbstractCubicBezier &curve) - : VAbstractBezier(curve) -{ -} - -//--------------------------------------------------------------------------------------------------------------------- -VAbstractCubicBezier &VAbstractCubicBezier::operator=(const VAbstractCubicBezier &curve) +auto VAbstractCubicBezier::operator=(const VAbstractCubicBezier &curve) -> VAbstractCubicBezier & { if ( &curve == this ) { @@ -395,8 +388,7 @@ VAbstractCubicBezier &VAbstractCubicBezier::operator=(const VAbstractCubicBezier //--------------------------------------------------------------------------------------------------------------------- VAbstractCubicBezier::~VAbstractCubicBezier() -{ -} +{} //--------------------------------------------------------------------------------------------------------------------- /** @@ -409,8 +401,8 @@ VAbstractCubicBezier::~VAbstractCubicBezier() * @param pointName cutting point name. * @return point of cutting. This point is forth point of first spline and first point of second spline. */ -QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, - QPointF &spl2p3, const QString &pointName) const +auto VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, + QPointF &spl2p3, const QString &pointName) const -> QPointF { //Always need return two splines, so we must correct wrong length. const qreal minLength = ToPixel(1, Unit::Mm); @@ -500,7 +492,7 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & } //--------------------------------------------------------------------------------------------------------------------- -QString VAbstractCubicBezier::NameForHistory(const QString &toolName) const +auto VAbstractCubicBezier::NameForHistory(const QString &toolName) const -> QString { QString name = toolName + QString(" %1_%2").arg(GetP1().name(), GetP4().name()); if (GetDuplicate() > 0) @@ -589,8 +581,8 @@ void VAbstractCubicBezier::CreateAlias() * @param approximationScale curve approximation scale. * @return list of points. */ -QVector VAbstractCubicBezier::GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, - const QPointF &p4, qreal approximationScale) +auto VAbstractCubicBezier::GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, + const QPointF &p4, qreal approximationScale) -> QVector { QVector pvector; pvector.append(p1); @@ -610,14 +602,14 @@ QVector VAbstractCubicBezier::GetCubicBezierPoints(const QPointF &p1, c * @param approximationScale curve approximation scale. * @return length. */ -qreal VAbstractCubicBezier::LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, - qreal approximationScale) +auto VAbstractCubicBezier::LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, + qreal approximationScale) -> qreal { return PathLength(GetCubicBezierPoints(p1, p2, p3, p4, approximationScale)); } //--------------------------------------------------------------------------------------------------------------------- -qreal VAbstractCubicBezier::RealLengthByT(qreal t) const +auto VAbstractCubicBezier::RealLengthByT(qreal t) const -> qreal { if (t < 0 || t > 1) { diff --git a/src/libs/vgeometry/vabstractcubicbezier.h b/src/libs/vgeometry/vabstractcubicbezier.h index a23bcbf43..0cc49787e 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.h +++ b/src/libs/vgeometry/vabstractcubicbezier.h @@ -47,35 +47,36 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-types") class VAbstractCubicBezier : public VAbstractBezier { public: - VAbstractCubicBezier(const GOType &type, const quint32 &idObject = NULL_ID, const Draw &mode = Draw::Calculation); - VAbstractCubicBezier(const VAbstractCubicBezier &curve); - VAbstractCubicBezier& operator= (const VAbstractCubicBezier &curve); - virtual ~VAbstractCubicBezier(); + explicit VAbstractCubicBezier(const GOType &type, const quint32 &idObject = NULL_ID, + const Draw &mode = Draw::Calculation); + VAbstractCubicBezier(const VAbstractCubicBezier &curve) = default; + auto operator= (const VAbstractCubicBezier &curve) -> VAbstractCubicBezier&; + ~VAbstractCubicBezier() override; - virtual VPointF GetP1 () const =0; - virtual VPointF GetP2 () const =0; - virtual VPointF GetP3 () const =0; - virtual VPointF GetP4 () const =0; + virtual auto GetP1 () const -> VPointF =0; + virtual auto GetP2 () const -> VPointF =0; + virtual auto GetP3 () const -> VPointF =0; + virtual auto GetP4 () const -> VPointF =0; - QPointF CutSpline (qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3, - const QString &pointName) const; + auto CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3, + const QString &pointName) const -> QPointF; - virtual QString NameForHistory(const QString &toolName) const override; + auto NameForHistory(const QString &toolName) const -> QString override; - qreal GetParmT(qreal length) const; - qreal RealLengthByT(qreal t) const; + auto GetParmT(qreal length) const -> qreal; + auto RealLengthByT(qreal t) const -> qreal; protected: - virtual void CreateName() override; - virtual void CreateAlias() override; + void CreateName() override; + void CreateAlias() override; - static QVector GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, - const QPointF &p4, qreal approximationScale); - static qreal LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, - qreal approximationScale); + static auto GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, + const QPointF &p4, qreal approximationScale) -> QVector; + static auto LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4, + qreal approximationScale) -> qreal; - virtual QPointF GetControlPoint1() const =0; - virtual QPointF GetControlPoint2() const =0; + virtual auto GetControlPoint1() const -> QPointF =0; + virtual auto GetControlPoint2() const -> QPointF =0; virtual auto GetRealLength() const -> qreal =0; }; diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 6a5371c95..a5e37ad44 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -46,13 +46,7 @@ VAbstractCubicBezierPath::VAbstractCubicBezierPath(const GOType &type, const qui } //--------------------------------------------------------------------------------------------------------------------- -VAbstractCubicBezierPath::VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve) - : VAbstractBezier(curve) -{ -} - -//--------------------------------------------------------------------------------------------------------------------- -VAbstractCubicBezierPath &VAbstractCubicBezierPath::operator=(const VAbstractCubicBezierPath &curve) +auto VAbstractCubicBezierPath::operator=(const VAbstractCubicBezierPath &curve) -> VAbstractCubicBezierPath & { if ( &curve == this ) { @@ -72,7 +66,7 @@ VAbstractCubicBezierPath::~VAbstractCubicBezierPath() * @brief GetPath return QPainterPath which reprezent spline path. * @return path. */ -QPainterPath VAbstractCubicBezierPath::GetPath() const +auto VAbstractCubicBezierPath::GetPath() const -> QPainterPath { QPainterPath painterPath; for (qint32 i = 1; i <= CountSubSpl(); ++i) @@ -87,7 +81,7 @@ QPainterPath VAbstractCubicBezierPath::GetPath() const * @brief GetPathPoints return list of points what located on path. * @return list. */ -QVector VAbstractCubicBezierPath::GetPoints() const +auto VAbstractCubicBezierPath::GetPoints() const -> QVector { QVector pathPoints; for (qint32 i = 1; i <= CountSubSpl(); ++i) @@ -107,7 +101,7 @@ QVector VAbstractCubicBezierPath::GetPoints() const * @brief GetLength return length of spline path. * @return length. */ -qreal VAbstractCubicBezierPath::GetLength() const +auto VAbstractCubicBezierPath::GetLength() const -> qreal { qreal length = 0; for (qint32 i = 1; i <= CountSubSpl(); ++i) @@ -118,7 +112,7 @@ qreal VAbstractCubicBezierPath::GetLength() const } //--------------------------------------------------------------------------------------------------------------------- -QVector VAbstractCubicBezierPath::DirectionArrows() const +auto VAbstractCubicBezierPath::DirectionArrows() const -> QVector { QVector arrows; for (qint32 i = 1; i <= CountSubSpl(); ++i) @@ -129,7 +123,7 @@ QVector VAbstractCubicBezierPath::DirectionArrows() const } //--------------------------------------------------------------------------------------------------------------------- -int VAbstractCubicBezierPath::Segment(const QPointF &p) const +auto VAbstractCubicBezierPath::Segment(const QPointF &p) const -> int { int index = -1; for (qint32 i = 1; i <= CountSubSpl(); ++i) @@ -167,8 +161,9 @@ int VAbstractCubicBezierPath::Segment(const QPointF &p) const * @param pointName cutting point name. * @return cutting point. */ -QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, - QPointF &spl2p2, QPointF &spl2p3, const QString &pointName) const +auto VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, + QPointF &spl2p2, QPointF &spl2p3, + const QString &pointName) const -> QPointF { if (CountSubSpl() < 1) { @@ -184,7 +179,7 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 p1 = p2 = -1; spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF(); - const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name()); + const QString errorMsg = tr("Unable to cut curve '%1'. The curve is too short.").arg(name()); VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; @@ -200,12 +195,12 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 QString errorMsg; if (not pointName.isEmpty()) { - errorMsg = QObject::tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal " - "value.").arg(name(), pointName); + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal value.") + .arg(name(), pointName); } else { - errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") + errorMsg = tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") .arg(name()); } VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : @@ -218,12 +213,12 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 QString errorMsg; if (not pointName.isEmpty()) { - errorMsg = QObject::tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") .arg(name(), pointName); } else { - errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") + errorMsg = tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") .arg(name()); } VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : @@ -247,7 +242,7 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 if (p1 > 0) { - const VSplinePoint splP1 = points.at(p1); + const VSplinePoint &splP1 = points.at(p1); QLineF line(splP1.P().toQPointF(), spl1p2); if (qFuzzyIsNull(line.length())) { @@ -261,7 +256,7 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 if (p2 < points.size() - 1) { - const VSplinePoint splP2 = points.at(p2); + const VSplinePoint &splP2 = points.at(p2); QLineF line(splP2.P().toQPointF(), spl2p3); if (qFuzzyIsNull(line.length())) { @@ -277,7 +272,7 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 } p1 = p2 = -1; spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF(); - return QPointF(); + return {}; } //--------------------------------------------------------------------------------------------------------------------- @@ -286,7 +281,7 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 * @param toolName first part of name. Like 'Spline path' or 'Cubic Bezier path'. * @return name of curve for history records. */ -QString VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const +auto VAbstractCubicBezierPath::NameForHistory(const QString &toolName) const -> QString { QString name = toolName; if (CountPoints() > 0) diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.h b/src/libs/vgeometry/vabstractcubicbezierpath.h index 9b88815de..b2d3be9f3 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.h +++ b/src/libs/vgeometry/vabstractcubicbezierpath.h @@ -49,39 +49,39 @@ QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods") class VAbstractCubicBezierPath : public VAbstractBezier { - Q_DECLARE_TR_FUNCTIONS(VAbstractCubicBezierPath) + Q_DECLARE_TR_FUNCTIONS(VAbstractCubicBezierPath) // NOLINT public: - VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject = NULL_ID, - const Draw &mode = Draw::Calculation); - VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve); - VAbstractCubicBezierPath& operator= (const VAbstractCubicBezierPath &curve); - virtual ~VAbstractCubicBezierPath(); + explicit VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject = NULL_ID, + const Draw &mode = Draw::Calculation); + VAbstractCubicBezierPath(const VAbstractCubicBezierPath &curve) = default; + auto operator= (const VAbstractCubicBezierPath &curve) -> VAbstractCubicBezierPath&; + ~VAbstractCubicBezierPath() override; - virtual qint32 CountSubSpl() const =0; - virtual qint32 CountPoints() const =0; - virtual void Clear() =0; - virtual VSpline GetSpline(qint32 index) const =0; - virtual QVector GetSplinePath() const =0; + virtual auto CountSubSpl() const -> qint32 =0; + virtual auto CountPoints() const -> qint32 =0; + virtual void Clear() =0; + virtual auto GetSpline(qint32 index) const -> VSpline =0; + virtual auto GetSplinePath() const -> QVector =0; - virtual QPainterPath GetPath() const override; - virtual QVector GetPoints() const override; - virtual qreal GetLength() const override; + auto GetPath() const -> QPainterPath override; + auto GetPoints() const -> QVector override; + auto GetLength() const -> qreal override; - virtual QVector DirectionArrows() const override; + auto DirectionArrows() const -> QVector override; - int Segment(const QPointF &p) const; + auto Segment(const QPointF &p) const -> int; - QPointF CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, - QPointF &spl2p3, const QString &pointName) const; + auto CutSplinePath(qreal length, qint32 &p1, qint32 &p2, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, + QPointF &spl2p3, const QString &pointName) const -> QPointF; - virtual QString NameForHistory(const QString &toolName) const override; + auto NameForHistory(const QString &toolName) const -> QString override; protected: - virtual void CreateName() override; - virtual void CreateAlias() override; + void CreateName() override; + void CreateAlias() override; - virtual VPointF FirstPoint() const =0; - virtual VPointF LastPoint() const =0; + virtual auto FirstPoint() const -> VPointF =0; + virtual auto LastPoint() const -> VPointF =0; }; QT_WARNING_POP diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 22e66fac6..aef43715c 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -108,7 +108,7 @@ VArc::VArc(const VArc &arc) * @param arc arc * @return arc */ -VArc &VArc::operator =(const VArc &arc) +auto VArc::operator =(const VArc &arc) -> VArc & { if ( &arc == this ) { @@ -126,7 +126,7 @@ VArc::VArc(VArc &&arc) Q_DECL_NOTHROW {} //--------------------------------------------------------------------------------------------------------------------- -VArc &VArc::operator=(VArc &&arc) Q_DECL_NOTHROW +auto VArc::operator=(VArc &&arc) Q_DECL_NOTHROW -> VArc & { VAbstractArc::operator=(arc); std::swap(d, arc.d); @@ -135,7 +135,7 @@ VArc &VArc::operator=(VArc &&arc) Q_DECL_NOTHROW #endif //--------------------------------------------------------------------------------------------------------------------- -VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +auto VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const -> VArc { const VPointF center = GetCenter().Rotate(originPoint, degrees); @@ -161,7 +161,7 @@ VArc VArc::Rotate(const QPointF &originPoint, qreal degrees, const QString &pref } //--------------------------------------------------------------------------------------------------------------------- -VArc VArc::Flip(const QLineF &axis, const QString &prefix) const +auto VArc::Flip(const QLineF &axis, const QString &prefix) const -> VArc { const VPointF center = GetCenter().Flip(axis); @@ -187,7 +187,7 @@ VArc VArc::Flip(const QLineF &axis, const QString &prefix) const } //--------------------------------------------------------------------------------------------------------------------- -VArc VArc::Move(qreal length, qreal angle, const QString &prefix) const +auto VArc::Move(qreal length, qreal angle, const QString &prefix) const -> VArc { const VPointF center = GetCenter().Move(length, angle); @@ -213,7 +213,7 @@ VArc VArc::Move(qreal length, qreal angle, const QString &prefix) const } //--------------------------------------------------------------------------------------------------------------------- -VArc::~VArc() +VArc::~VArc() // NOLINT(hicpp-use-equals-default, modernize-use-equals-default) {} //--------------------------------------------------------------------------------------------------------------------- @@ -221,7 +221,7 @@ VArc::~VArc() * @brief GetLength return arc length. * @return length. */ -qreal VArc::GetLength() const +auto VArc::GetLength() const -> qreal { qreal length = d->radius * qDegreesToRadians(AngleArc()); if (IsFlipped()) @@ -237,7 +237,7 @@ qreal VArc::GetLength() const * @brief GetP1 return point associated with start angle. * @return point. */ -QPointF VArc::GetP1() const +auto VArc::GetP1() const -> QPointF { QPointF p1 ( GetCenter().x () + d->radius, GetCenter().y () ); QLineF centerP1(static_cast(GetCenter()), p1); @@ -250,7 +250,7 @@ QPointF VArc::GetP1() const * @brief GetP2 return point associated with end angle. * @return точку point. */ -QPointF VArc::GetP2 () const +auto VArc::GetP2 () const -> QPointF { QPointF p2 ( GetCenter().x () + d->radius, GetCenter().y () ); QLineF centerP2(static_cast(GetCenter()), p2); @@ -263,7 +263,7 @@ QPointF VArc::GetP2 () const * @brief GetPoints return list of points needed for drawing arc. * @return list of points */ -QVector VArc::GetPoints() const +auto VArc::GetPoints() const -> QVector { if (qFuzzyIsNull(GetRadius())) { @@ -293,6 +293,7 @@ QVector VArc::GetPoints() const const qreal angleInterpolation = 45; //degree const int sections = qFloor(angle / angleInterpolation); + sectionAngle.reserve(sections+1); for (int i = 0; i < sections; ++i) { sectionAngle.append(angleInterpolation); @@ -355,118 +356,23 @@ auto VArc::CutArc(qreal length, VArc &arc1, VArc &arc2, const QString &pointName arc1 = VArc(); arc2 = VArc(); - const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name()); + const QString errorMsg = tr("Unable to cut curve '%1'. The curve is too short.").arg(name()); VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; return {}; } - QLineF line(static_cast(GetCenter()), GetP1()); + QLineF line = not IsFlipped() ? CutPoint(length, fullLength, pointName) + : CutPointFlipped(length, fullLength, pointName); - if (not IsFlipped()) - { - if (length < 0) - { - length = fullLength + length; - } - - const qreal minLength = ToPixel(1, Unit::Mm); - const qreal maxLength = fullLength - ToPixel(1, Unit::Mm); - - if (length < minLength) - { - QString errorMsg; - if (not pointName.isEmpty()) - { - errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal value.") - .arg(name(), pointName); - } - else - { - errorMsg = tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") - .arg(name()); - } - VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; - } - else if (length > maxLength) - { - QString errorMsg; - if (not pointName.isEmpty()) - { - errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") - .arg(name(), pointName); - } - else - { - - errorMsg = tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") - .arg(name()); - } - VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; - } - - length = qBound(minLength, length, maxLength); - - line.setAngle(line.angle() + qRadiansToDegrees(length/d->radius)); - } - else - { - if (length > 0) - { - length = fullLength + length; - } - - const qreal minLength = fullLength + ToPixel(1, Unit::Mm); - const qreal maxLength = ToPixel(-1, Unit::Mm); - - if (length > minLength) - { - QString errorMsg; - if (not pointName.isEmpty()) - { - errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal value.") - .arg(name(), pointName); - } - else - { - errorMsg = tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") - .arg(name()); - } - VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; - } - else if (length < maxLength) - { - QString errorMsg; - if (not pointName.isEmpty()) - { - errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") - .arg(name(), errorMsg); - } - else - { - errorMsg = tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") - .arg(name()); - } - VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : - qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; - } - - length = qBound(minLength, length, maxLength); - - line.setAngle(line.angle() - qRadiansToDegrees(qAbs(length)/d->radius)); - } - - arc1 = VArc (GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(), - QString().setNum(line.angle()), getIdObject(), getMode()); + arc1 = VArc(GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(), + QString().setNum(line.angle()), getIdObject(), getMode()); arc1.SetApproximationScale(GetApproximationScale()); arc1.SetFlipped(IsFlipped()); - arc2 = VArc (GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(), - GetFormulaF2(), getIdObject(), getMode()); + arc2 = VArc(GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(), + GetFormulaF2(), getIdObject(), getMode()); arc2.SetApproximationScale(GetApproximationScale()); arc2.SetFlipped(IsFlipped()); return line.p2(); @@ -474,7 +380,7 @@ auto VArc::CutArc(qreal length, VArc &arc1, VArc &arc2, const QString &pointName //--------------------------------------------------------------------------------------------------------------------- -QPointF VArc::CutArc(qreal length, const QString &pointName) const +auto VArc::CutArc(qreal length, const QString &pointName) const -> QPointF { VArc arc1; VArc arc2; @@ -485,19 +391,20 @@ QPointF VArc::CutArc(qreal length, const QString &pointName) const void VArc::CreateName() { QString name = ARC_ + this->GetCenter().name(); + const QString nameStr = QStringLiteral("_%1"); if (getMode() == Draw::Modeling && getIdObject() != NULL_ID) { - name += QString("_%1").arg(getIdObject()); + name += nameStr.arg(getIdObject()); } else if (VAbstractCurve::id() != NULL_ID) { - name += QString("_%1").arg(VAbstractCurve::id()); + name += nameStr.arg(VAbstractCurve::id()); } if (GetDuplicate() > 0) { - name += QString("_%1").arg(GetDuplicate()); + name += nameStr.arg(GetDuplicate()); } setName(name); @@ -536,21 +443,124 @@ void VArc::FindF2(qreal length) QLineF startAngle(0, 0, 100, 0); startAngle.setAngle(GetStartAngle() + arcAngle);// We use QLineF just because it is easy way correct angle value - SetFormulaF2(QString().number(startAngle.angle()), startAngle.angle()); + SetFormulaF2(QString::number(startAngle.angle()), startAngle.angle()); } //--------------------------------------------------------------------------------------------------------------------- -qreal VArc::MaxLength() const +auto VArc::MaxLength() const -> qreal { return M_2PI*d->radius; } +//--------------------------------------------------------------------------------------------------------------------- +auto VArc::CutPoint(qreal length, qreal fullLength, const QString &pointName) const -> QLineF +{ + if (length < 0) + { + length = fullLength + length; + } + + const qreal minLength = ToPixel(1, Unit::Mm); + const qreal maxLength = fullLength - ToPixel(1, Unit::Mm); + + if (length < minLength) + { + QString errorMsg; + if (not pointName.isEmpty()) + { + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal value.") + .arg(name(), pointName); + } + else + { + errorMsg = tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") + .arg(name()); + } + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; + } + else if (length > maxLength) + { + QString errorMsg; + if (not pointName.isEmpty()) + { + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") + .arg(name(), pointName); + } + else + { + + errorMsg = tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") + .arg(name()); + } + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; + } + + length = qBound(minLength, length, maxLength); + + QLineF line(static_cast(GetCenter()), GetP1()); + line.setAngle(line.angle() + qRadiansToDegrees(length/d->radius)); + return line; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VArc::CutPointFlipped(qreal length, qreal fullLength, const QString &pointName) const -> QLineF +{ + if (length > 0) + { + length = fullLength + length; + } + + const qreal minLength = fullLength + ToPixel(1, Unit::Mm); + const qreal maxLength = ToPixel(-1, Unit::Mm); + + if (length > minLength) + { + QString errorMsg; + if (not pointName.isEmpty()) + { + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too small. Optimize it to minimal value.") + .arg(name(), pointName); + } + else + { + errorMsg = tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal value.") + .arg(name()); + } + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; + } + else if (length < maxLength) + { + QString errorMsg; + if (not pointName.isEmpty()) + { + errorMsg = tr("Curve '%1'. Length of a cut segment (%2) is too big. Optimize it to maximal value.") + .arg(name(), errorMsg); + } + else + { + errorMsg = tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal value.") + .arg(name()); + } + VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) : + qWarning() << VAbstractApplication::warningMessageSignature + errorMsg; + } + + length = qBound(minLength, length, maxLength); + + QLineF line(static_cast(GetCenter()), GetP1()); + line.setAngle(line.angle() - qRadiansToDegrees(qAbs(length)/d->radius)); + return line; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return arc radius. * @return radius. */ -QString VArc::GetFormulaRadius() const +auto VArc::GetFormulaRadius() const -> QString { return d->formulaRadius; } @@ -567,7 +577,7 @@ void VArc::SetFormulaRadius(const QString &formula, qreal value) * @brief GetRadius return formula for radius. * @return string with formula. */ -qreal VArc::GetRadius() const +auto VArc::GetRadius() const -> qreal { return d->radius; } diff --git a/src/libs/vgeometry/varc.h b/src/libs/vgeometry/varc.h index cfbd80d47..7de41967d 100644 --- a/src/libs/vgeometry/varc.h +++ b/src/libs/vgeometry/varc.h @@ -49,48 +49,51 @@ class VArcData; */ class VArc final : public VAbstractArc { - Q_DECLARE_TR_FUNCTIONS(VArc) + Q_DECLARE_TR_FUNCTIONS(VArc) // NOLINT public: - VArc (); - VArc (const VPointF ¢er, qreal radius, const QString &formulaRadius, qreal f1, const QString &formulaF1, - qreal f2, const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); - VArc (const VPointF ¢er, qreal radius, qreal f1, qreal f2); - VArc (qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius, const QString &formulaRadius, - qreal f1, const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); - VArc (qreal length, const VPointF ¢er, qreal radius, qreal f1); + VArc(); + VArc(const VPointF ¢er, qreal radius, const QString &formulaRadius, qreal f1, const QString &formulaF1, + qreal f2, const QString &formulaF2, quint32 idObject = 0, Draw mode = Draw::Calculation); + VArc(const VPointF ¢er, qreal radius, qreal f1, qreal f2); + VArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius, const QString &formulaRadius, + qreal f1, const QString &formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + VArc(qreal length, const VPointF ¢er, qreal radius, qreal f1); VArc(const VArc &arc); - VArc Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; - VArc Flip(const QLineF &axis, const QString &prefix = QString()) const; - VArc Move(qreal length, qreal angle, const QString &prefix = QString()) const; - virtual ~VArc() override; + auto Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const -> VArc; + auto Flip(const QLineF &axis, const QString &prefix = QString()) const -> VArc; + auto Move(qreal length, qreal angle, const QString &prefix = QString()) const -> VArc; + ~VArc() override; - VArc& operator= (const VArc &arc); + auto operator= (const VArc &arc) -> VArc&; #ifdef Q_COMPILER_RVALUE_REFS VArc(VArc &&arc) Q_DECL_NOTHROW; - VArc &operator=(VArc &&arc) Q_DECL_NOTHROW; + auto operator=(VArc &&arc) Q_DECL_NOTHROW -> VArc &; #endif - QString GetFormulaRadius () const; - void SetFormulaRadius (const QString &formula, qreal value); - qreal GetRadius () const; + auto GetFormulaRadius() const -> QString; + void SetFormulaRadius(const QString &formula, qreal value); + auto GetRadius() const -> qreal; - virtual qreal GetLength () const override; + auto GetLength() const -> qreal override; - QPointF GetP1() const; - QPointF GetP2 () const; + auto GetP1() const -> QPointF; + auto GetP2() const -> QPointF; - virtual QVector GetPoints () const override; + auto GetPoints() const -> QVector override; - QPointF CutArc (qreal length, VArc &arc1, VArc &arc2, const QString &pointName) const; - QPointF CutArc (qreal length, const QString &pointName) const; + auto CutArc(qreal length, VArc &arc1, VArc &arc2, const QString &pointName) const -> QPointF; + auto CutArc(qreal length, const QString &pointName) const -> QPointF; protected: - virtual void CreateName() override; - virtual void CreateAlias() override; - virtual void FindF2(qreal length) override; + void CreateName() override; + void CreateAlias() override; + void FindF2(qreal length) override; private: QSharedDataPointer d; - qreal MaxLength() const; + auto MaxLength() const -> qreal; + + auto CutPoint(qreal length, qreal fullLength, const QString &pointName) const -> QLineF; + auto CutPointFlipped(qreal length, qreal fullLength, const QString &pointName) const -> QLineF; }; Q_DECLARE_TYPEINFO(VArc, Q_MOVABLE_TYPE); // NOLINT diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index f89b09ce3..7ec84790a 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -116,7 +116,7 @@ VEllipticalArc::VEllipticalArc(const VEllipticalArc &arc) * @param arc arc * @return arc */ -VEllipticalArc &VEllipticalArc::operator =(const VEllipticalArc &arc) +auto VEllipticalArc::operator =(const VEllipticalArc &arc) -> VEllipticalArc & { if ( &arc == this ) { @@ -129,12 +129,13 @@ VEllipticalArc &VEllipticalArc::operator =(const VEllipticalArc &arc) #ifdef Q_COMPILER_RVALUE_REFS //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::VEllipticalArc(const VEllipticalArc &&arc) Q_DECL_NOTHROW - : VAbstractArc(arc), d (arc.d) +VEllipticalArc::VEllipticalArc(VEllipticalArc &&arc) Q_DECL_NOTHROW + : VAbstractArc(std::move(arc)), + d(std::move(arc.d)) {} //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc &VEllipticalArc::operator=(VEllipticalArc &&arc) Q_DECL_NOTHROW +auto VEllipticalArc::operator=(VEllipticalArc &&arc) Q_DECL_NOTHROW -> VEllipticalArc & { VAbstractArc::operator=(arc); std::swap(d, arc.d); @@ -143,7 +144,7 @@ VEllipticalArc &VEllipticalArc::operator=(VEllipticalArc &&arc) Q_DECL_NOTHROW #endif //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc VEllipticalArc::Rotate(QPointF originPoint, qreal degrees, const QString &prefix) const +auto VEllipticalArc::Rotate(QPointF originPoint, qreal degrees, const QString &prefix) const -> VEllipticalArc { originPoint = d->m_transform.inverted().map(originPoint); @@ -169,7 +170,7 @@ VEllipticalArc VEllipticalArc::Rotate(QPointF originPoint, qreal degrees, const } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const +auto VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) const -> VEllipticalArc { VEllipticalArc elArc(VAbstractArc::GetCenter(), GetRadius1(), GetRadius2(), VAbstractArc::GetStartAngle(), VAbstractArc::GetEndAngle(), GetRotationAngle()); @@ -188,7 +189,7 @@ VEllipticalArc VEllipticalArc::Flip(const QLineF &axis, const QString &prefix) c } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc VEllipticalArc::Move(qreal length, qreal angle, const QString &prefix) const +auto VEllipticalArc::Move(qreal length, qreal angle, const QString &prefix) const -> VEllipticalArc { const VPointF oldCenter = VAbstractArc::GetCenter(); const VPointF center = oldCenter.Move(length, angle); @@ -216,7 +217,7 @@ VEllipticalArc VEllipticalArc::Move(qreal length, qreal angle, const QString &pr } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::~VEllipticalArc() +VEllipticalArc::~VEllipticalArc() // NOLINT(hicpp-use-equals-default, modernize-use-equals-default) {} //--------------------------------------------------------------------------------------------------------------------- @@ -224,7 +225,7 @@ VEllipticalArc::~VEllipticalArc() * @brief GetLength return arc length. * @return length. */ -qreal VEllipticalArc::GetLength() const +auto VEllipticalArc::GetLength() const -> qreal { qreal length = PathLength(GetPoints()); @@ -241,7 +242,7 @@ qreal VEllipticalArc::GetLength() const * @brief GetP1 return point associated with start angle. * @return point. */ -QPointF VEllipticalArc::GetP1() const +auto VEllipticalArc::GetP1() const -> QPointF { return GetTransform().map(GetP(VAbstractArc::GetStartAngle())); } @@ -251,13 +252,13 @@ QPointF VEllipticalArc::GetP1() const * @brief GetP2 return point associated with end angle. * @return point. */ -QPointF VEllipticalArc::GetP2 () const +auto VEllipticalArc::GetP2 () const -> QPointF { return GetTransform().map(GetP(VAbstractArc::GetEndAngle())); } //--------------------------------------------------------------------------------------------------------------------- -QTransform VEllipticalArc::GetTransform() const +auto VEllipticalArc::GetTransform() const -> QTransform { return d->m_transform; } @@ -269,7 +270,7 @@ void VEllipticalArc::SetTransform(const QTransform &matrix, bool combine) } //--------------------------------------------------------------------------------------------------------------------- -VPointF VEllipticalArc::GetCenter() const +auto VEllipticalArc::GetCenter() const -> VPointF { VPointF center = VAbstractArc::GetCenter(); const QPointF p = d->m_transform.map(center.toQPointF()); @@ -283,7 +284,7 @@ VPointF VEllipticalArc::GetCenter() const * @brief GetPoints return list of points needed for drawing arc. * @return list of points */ -QVector VEllipticalArc::GetPoints() const +auto VEllipticalArc::GetPoints() const -> QVector { const QPointF center = VAbstractArc::GetCenter().toQPointF(); QRectF box(center.x() - d->radius1, center.y() - d->radius2, d->radius1*2, d->radius2*2); @@ -328,13 +329,13 @@ QVector VEllipticalArc::GetPoints() const } //--------------------------------------------------------------------------------------------------------------------- -qreal VEllipticalArc::GetStartAngle() const +auto VEllipticalArc::GetStartAngle() const -> qreal { return QLineF(GetCenter().toQPointF(), GetP1()).angle() - GetRotationAngle(); } //--------------------------------------------------------------------------------------------------------------------- -qreal VEllipticalArc::GetEndAngle() const +auto VEllipticalArc::GetEndAngle() const -> qreal { return QLineF(GetCenter().toQPointF(), GetP2()).angle() - GetRotationAngle(); } @@ -347,8 +348,8 @@ qreal VEllipticalArc::GetEndAngle() const * @param arc2 second arc. * @return point cutting */ -QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2, - const QString &pointName) const +auto VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2, + const QString &pointName) const -> QPointF { //Always need return two arcs, so we must correct wrong length. qreal len = 0; @@ -424,7 +425,7 @@ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllip //--------------------------------------------------------------------------------------------------------------------- -QPointF VEllipticalArc::CutArc(const qreal &length, const QString &pointName) const +auto VEllipticalArc::CutArc(const qreal &length, const QString &pointName) const -> QPointF { VEllipticalArc arc1; VEllipticalArc arc2; @@ -435,19 +436,20 @@ QPointF VEllipticalArc::CutArc(const qreal &length, const QString &pointName) co void VEllipticalArc::CreateName() { QString name = ELARC_ + QString("%1").arg(this->GetCenter().name()); + const QString nameStr = QStringLiteral("_%1"); if (getMode() == Draw::Modeling && getIdObject() != NULL_ID) { - name += QString("_%1").arg(getIdObject()); + name += nameStr.arg(getIdObject()); } else if (VAbstractCurve::id() != NULL_ID) { - name += QString("_%1").arg(VAbstractCurve::id()); + name += nameStr.arg(VAbstractCurve::id()); } if (GetDuplicate() > 0) { - name += QString("_%1").arg(GetDuplicate()); + name += nameStr.arg(GetDuplicate()); } setName(name); @@ -519,7 +521,7 @@ void VEllipticalArc::FindF2(qreal length) } //--------------------------------------------------------------------------------------------------------------------- -qreal VEllipticalArc::MaxLength() const +auto VEllipticalArc::MaxLength() const -> qreal { const qreal h = qPow(d->radius1 - d->radius2, 2) / qPow(d->radius1 + d->radius2, 2); const qreal ellipseLength = M_PI * (d->radius1 + d->radius2) * (1+3*h/(10+qSqrt(4-3*h))); @@ -527,7 +529,7 @@ qreal VEllipticalArc::MaxLength() const } //--------------------------------------------------------------------------------------------------------------------- -QPointF VEllipticalArc::GetP(qreal angle) const +auto VEllipticalArc::GetP(qreal angle) const -> QPointF { if (qFuzzyIsNull(GetRadius1()) && qFuzzyIsNull(GetRadius2())) { @@ -556,7 +558,7 @@ QPointF VEllipticalArc::GetP(qreal angle) const } //--------------------------------------------------------------------------------------------------------------------- -qreal VEllipticalArc::RealEndAngle() const +auto VEllipticalArc::RealEndAngle() const -> qreal { qreal endAngle = VEllipticalArc::OptimizeAngle(VAbstractArc::GetEndAngle()); @@ -580,7 +582,7 @@ qreal VEllipticalArc::RealEndAngle() const * @brief GetFormulaRadius1 return formula for major radius. * @return radius. */ -QString VEllipticalArc::GetFormulaRadius1() const +auto VEllipticalArc::GetFormulaRadius1() const -> QString { return d->formulaRadius1; } @@ -590,7 +592,7 @@ QString VEllipticalArc::GetFormulaRadius1() const * @brief GetFormulaRadius2 return formula for minor radius. * @return radius. */ -QString VEllipticalArc::GetFormulaRadius2() const +auto VEllipticalArc::GetFormulaRadius2() const -> QString { return d->formulaRadius2; } @@ -600,7 +602,7 @@ QString VEllipticalArc::GetFormulaRadius2() const * @brief GetFormulaRotationAngle return formula for rotation angle. * @return rotationAngle. */ -QString VEllipticalArc::GetFormulaRotationAngle() const +auto VEllipticalArc::GetFormulaRotationAngle() const -> QString { return d->formulaRotationAngle; } @@ -652,7 +654,7 @@ void VEllipticalArc::SetRotationAngle(qreal value) * @brief GetRadius1 return elliptical arc major radius. * @return string with formula. */ -qreal VEllipticalArc::GetRadius1() const +auto VEllipticalArc::GetRadius1() const -> qreal { return d->radius1; } @@ -662,7 +664,7 @@ qreal VEllipticalArc::GetRadius1() const * @brief GetRadius2 return elliptical arc minor radius. * @return string with formula. */ -qreal VEllipticalArc::GetRadius2() const +auto VEllipticalArc::GetRadius2() const -> qreal { return d->radius2; } @@ -672,7 +674,7 @@ qreal VEllipticalArc::GetRadius2() const * @brief GetRotationAngle return rotation angle. * @return rotationAngle. */ -qreal VEllipticalArc::GetRotationAngle() const +auto VEllipticalArc::GetRotationAngle() const -> qreal { return d->rotationAngle; } diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index e56678007..3386e1fa9 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -46,84 +46,85 @@ class VEllipticalArcData; class VEllipticalArc final : public VAbstractArc { - Q_DECLARE_TR_FUNCTIONS(VEllipticalArc) + Q_DECLARE_TR_FUNCTIONS(VEllipticalArc) // NOLINT public: VEllipticalArc(); - VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, const QString &formulaRadius1, - const QString &formulaRadius2, qreal f1, const QString &formulaF1, qreal f2, - const QString &formulaF2, qreal rotationAngle, const QString &formulaRotationAngle, - quint32 idObject = 0, Draw mode = Draw::Calculation); - VEllipticalArc (const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); - VEllipticalArc (qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius1, qreal radius2, - const QString &formulaRadius1, const QString &formulaRadius2, qreal f1, const QString &formulaF1, - qreal rotationAngle, const QString &formulaRotationAngle, quint32 idObject = 0, - Draw mode = Draw::Calculation); - VEllipticalArc (qreal length, const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle); + VEllipticalArc(const VPointF ¢er, qreal radius1, qreal radius2, const QString &formulaRadius1, + const QString &formulaRadius2, qreal f1, const QString &formulaF1, qreal f2, + const QString &formulaF2, qreal rotationAngle, const QString &formulaRotationAngle, + quint32 idObject = 0, Draw mode = Draw::Calculation); + VEllipticalArc(const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); + VEllipticalArc(qreal length, const QString &formulaLength, const VPointF ¢er, qreal radius1, qreal radius2, + const QString &formulaRadius1, const QString &formulaRadius2, qreal f1, const QString &formulaF1, + qreal rotationAngle, const QString &formulaRotationAngle, quint32 idObject = 0, + Draw mode = Draw::Calculation); + VEllipticalArc(qreal length, const VPointF ¢er, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle); VEllipticalArc(const VEllipticalArc &arc); - VEllipticalArc Rotate(QPointF originPoint, qreal degrees, const QString &prefix = QString()) const; - VEllipticalArc Flip(const QLineF &axis, const QString &prefix = QString()) const; - VEllipticalArc Move(qreal length, qreal angle, const QString &prefix = QString()) const; + auto Rotate(QPointF originPoint, qreal degrees, const QString &prefix = QString()) const -> VEllipticalArc; + auto Flip(const QLineF &axis, const QString &prefix = QString()) const -> VEllipticalArc; + auto Move(qreal length, qreal angle, const QString &prefix = QString()) const -> VEllipticalArc; - virtual ~VEllipticalArc() override; + ~VEllipticalArc() override; - VEllipticalArc& operator= (const VEllipticalArc &arc); + auto operator= (const VEllipticalArc &arc) -> VEllipticalArc&; #ifdef Q_COMPILER_RVALUE_REFS - VEllipticalArc(const VEllipticalArc &&arc) Q_DECL_NOTHROW; - VEllipticalArc &operator=(VEllipticalArc &&arc) Q_DECL_NOTHROW; + VEllipticalArc(VEllipticalArc &&arc) Q_DECL_NOTHROW; + auto operator=(VEllipticalArc &&arc) Q_DECL_NOTHROW -> VEllipticalArc &; #endif - QString GetFormulaRotationAngle () const; - void SetFormulaRotationAngle (const QString &formula, qreal value); - void SetRotationAngle(qreal value); - qreal GetRotationAngle() const; + auto GetFormulaRotationAngle() const -> QString; + void SetFormulaRotationAngle(const QString &formula, qreal value); + void SetRotationAngle(qreal value); + auto GetRotationAngle() const -> qreal; - QString GetFormulaRadius1 () const; - void SetFormulaRadius1 (const QString &formula, qreal value); - void SetRadius1 (qreal value); - qreal GetRadius1 () const; + auto GetFormulaRadius1() const -> QString; + void SetFormulaRadius1(const QString &formula, qreal value); + void SetRadius1(qreal value); + auto GetRadius1() const -> qreal; - QString GetFormulaRadius2 () const; - void SetFormulaRadius2 (const QString &formula, qreal value); - void SetRadius2 (qreal value); - qreal GetRadius2 () const; + auto GetFormulaRadius2() const -> QString; + void SetFormulaRadius2(const QString &formula, qreal value); + void SetRadius2(qreal value); + auto GetRadius2() const -> qreal; - virtual qreal GetLength () const override; + auto GetLength() const -> qreal override; - QPointF GetP1() const; - QPointF GetP2() const; + auto GetP1() const -> QPointF; + auto GetP2() const -> QPointF; - QTransform GetTransform() const; - void SetTransform(const QTransform &matrix, bool combine = false); + auto GetTransform() const -> QTransform; + void SetTransform(const QTransform &matrix, bool combine = false); - virtual VPointF GetCenter () const override; - virtual QVector GetPoints () const override; - virtual qreal GetStartAngle () const override; - virtual qreal GetEndAngle () const override; + auto GetCenter() const -> VPointF; + auto GetPoints() const -> QVector override; + auto GetStartAngle() const -> qreal override; + auto GetEndAngle() const -> qreal override; - QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2, const QString &pointName) const; - QPointF CutArc (const qreal &length, const QString &pointName) const; + auto CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2, + const QString &pointName) const -> QPointF; + auto CutArc (const qreal &length, const QString &pointName) const -> QPointF; - static qreal OptimizeAngle(qreal angle); + static auto OptimizeAngle(qreal angle) -> qreal; protected: - virtual void CreateName() override; - virtual void CreateAlias() override; - virtual void FindF2(qreal length) override; + void CreateName() override; + void CreateAlias() override; + void FindF2(qreal length) override; private: QSharedDataPointer d; - qreal MaxLength() const; + auto MaxLength() const -> qreal; - QPointF GetP(qreal angle) const; + auto GetP(qreal angle) const -> QPointF; - qreal RealEndAngle() const; + auto RealEndAngle() const -> qreal; }; -Q_DECLARE_METATYPE(VEllipticalArc) -Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(VEllipticalArc) // NOLINT +Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); // NOLINT //--------------------------------------------------------------------------------------------------------------------- -inline qreal VEllipticalArc::OptimizeAngle(qreal angle) +inline auto VEllipticalArc::OptimizeAngle(qreal angle) -> qreal { return angle - 360.*qFloor(angle/360.); } diff --git a/src/libs/vgeometry/vspline.cpp b/src/libs/vgeometry/vspline.cpp index 30619886f..6712c635a 100644 --- a/src/libs/vgeometry/vspline.cpp +++ b/src/libs/vgeometry/vspline.cpp @@ -40,7 +40,8 @@ * @brief VSpline default constructor */ VSpline::VSpline() - :VAbstractCubicBezier(GOType::Spline), d(new VSplineData) + : VAbstractCubicBezier(GOType::Spline), + d(new VSplineData) {} //--------------------------------------------------------------------------------------------------------------------- @@ -48,8 +49,9 @@ VSpline::VSpline() * @brief VSpline constructor. * @param spline spline from which the copy. */ -VSpline::VSpline ( const VSpline & spline ) - :VAbstractCubicBezier(spline), d(spline.d) +VSpline::VSpline(const VSpline &spline) + : VAbstractCubicBezier(spline), + d(spline.d) {} //--------------------------------------------------------------------------------------------------------------------- @@ -112,7 +114,7 @@ VSpline::VSpline(const VPointF &p1, const VPointF &p4, qreal angle1, const QStri } //--------------------------------------------------------------------------------------------------------------------- -VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const +auto VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const -> VSpline { const VPointF p1 = GetP1().Rotate(originPoint, degrees); const VPointF p4 = GetP4().Rotate(originPoint, degrees); @@ -135,7 +137,7 @@ VSpline VSpline::Rotate(const QPointF &originPoint, qreal degrees, const QString } //--------------------------------------------------------------------------------------------------------------------- -VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const +auto VSpline::Flip(const QLineF &axis, const QString &prefix) const -> VSpline { const VPointF p1 = GetP1().Flip(axis); const VPointF p4 = GetP4().Flip(axis); @@ -158,7 +160,7 @@ VSpline VSpline::Flip(const QLineF &axis, const QString &prefix) const } //--------------------------------------------------------------------------------------------------------------------- -VSpline VSpline::Move(qreal length, qreal angle, const QString &prefix) const +auto VSpline::Move(qreal length, qreal angle, const QString &prefix) const -> VSpline { const VPointF p1 = GetP1().Move(length, angle); const VPointF p4 = GetP4().Move(length, angle); @@ -181,7 +183,7 @@ VSpline VSpline::Move(qreal length, qreal angle, const QString &prefix) const } //--------------------------------------------------------------------------------------------------------------------- -VSpline::~VSpline() +VSpline::~VSpline() // NOLINT(hicpp-use-equals-default, modernize-use-equals-default) {} //--------------------------------------------------------------------------------------------------------------------- @@ -189,14 +191,14 @@ VSpline::~VSpline() * @brief GetLength return length of spline. * @return length. */ -qreal VSpline::GetLength () const +auto VSpline::GetLength () const -> qreal { return LengthBezier ( static_cast(GetP1()), static_cast(GetP2()), static_cast(GetP3()), static_cast(GetP4()), GetApproximationScale()); } //--------------------------------------------------------------------------------------------------------------------- -QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2, const QString &pointName) const +auto VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2, const QString &pointName) const -> QPointF { QPointF spl1p2; QPointF spl1p3; @@ -217,7 +219,7 @@ QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2, const QSt * @brief GetPoints return list with spline points. * @return list of points. */ -QVector VSpline::GetPoints () const +auto VSpline::GetPoints () const -> QVector { return GetCubicBezierPoints(static_cast(GetP1()), static_cast(GetP2()), static_cast(GetP3()), static_cast(GetP4()), GetApproximationScale()); @@ -236,8 +238,8 @@ QVector VSpline::GetPoints () const * @return list with spline points. */ // cppcheck-suppress unusedFunction -QVector VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, - qreal kAsm2, qreal kCurve, qreal approximationScale) +auto VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, + qreal kAsm2, qreal kCurve, qreal approximationScale) -> QVector { QLineF p1pX(p1.x(), p1.y(), p1.x() + 100, p1.y()); p1pX.setAngle( angle1 ); @@ -254,7 +256,7 @@ QVector VSpline::SplinePoints(const QPointF &p1, const QPointF &p4, qre } //--------------------------------------------------------------------------------------------------------------------- -VSpline &VSpline::operator =(const VSpline &spline) +auto VSpline::operator =(const VSpline &spline) -> VSpline & { if ( &spline == this ) { @@ -267,12 +269,13 @@ VSpline &VSpline::operator =(const VSpline &spline) #ifdef Q_COMPILER_RVALUE_REFS //--------------------------------------------------------------------------------------------------------------------- -VSpline::VSpline(const VSpline &&spline) Q_DECL_NOTHROW - :VAbstractCubicBezier(spline), d(spline.d) +VSpline::VSpline(VSpline &&spline) Q_DECL_NOTHROW + : VAbstractCubicBezier(spline), + d(spline.d) {} //--------------------------------------------------------------------------------------------------------------------- -VSpline &VSpline::operator=(VSpline &&spline) Q_DECL_NOTHROW +auto VSpline::operator=(VSpline &&spline) Q_DECL_NOTHROW -> VSpline & { VAbstractCubicBezier::operator=(spline); std::swap(d, spline.d); @@ -285,7 +288,7 @@ VSpline &VSpline::operator=(VSpline &&spline) Q_DECL_NOTHROW * @brief GetP1 return first spline point. * @return first point. */ -VPointF VSpline::GetP1() const +auto VSpline::GetP1() const -> VPointF { return d->p1; } @@ -301,7 +304,7 @@ void VSpline::SetP1(const VPointF &p) * @brief GetP2 return first control point. * @return first control point. */ -VPointF VSpline::GetP2() const +auto VSpline::GetP2() const -> VPointF { QLineF p1p2(d->p1.x(), d->p1.y(), d->p1.x() + d->c1Length, d->p1.y()); p1p2.setAngle(d->angle1); @@ -313,7 +316,7 @@ VPointF VSpline::GetP2() const * @brief GetP3 return second control point. * @return second control point. */ -VPointF VSpline::GetP3() const +auto VSpline::GetP3() const -> VPointF { QLineF p4p3(d->p4.x(), d->p4.y(), d->p4.x() + d->c2Length, d->p4.y()); p4p3.setAngle(d->angle2); @@ -325,7 +328,7 @@ VPointF VSpline::GetP3() const * @brief GetP4 return last spline point. * @return остання точка сплайну. */ -VPointF VSpline::GetP4() const +auto VSpline::GetP4() const -> VPointF { return d->p4; } @@ -341,7 +344,7 @@ void VSpline::SetP4(const VPointF &p) * @brief GetAngle1 return first angle control line. * @return angle. */ -qreal VSpline::GetStartAngle() const +auto VSpline::GetStartAngle() const -> qreal { return d->angle1; } @@ -351,19 +354,19 @@ qreal VSpline::GetStartAngle() const * @brief GetAngle2 return second angle control line. * @return angle. */ -qreal VSpline::GetEndAngle() const +auto VSpline::GetEndAngle() const -> qreal { return d->angle2; } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::GetStartAngleFormula() const +auto VSpline::GetStartAngleFormula() const -> QString { return d->angle1F; } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::GetEndAngleFormula() const +auto VSpline::GetEndAngleFormula() const -> QString { return d->angle2F; } @@ -383,25 +386,25 @@ void VSpline::SetEndAngle(qreal angle, const QString &formula) } //--------------------------------------------------------------------------------------------------------------------- -qreal VSpline::GetC1Length() const +auto VSpline::GetC1Length() const -> qreal { return d->c1Length; } //--------------------------------------------------------------------------------------------------------------------- -qreal VSpline::GetC2Length() const +auto VSpline::GetC2Length() const -> qreal { return d->c2Length; } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::GetC1LengthFormula() const +auto VSpline::GetC1LengthFormula() const -> QString { return d->c1LengthF; } //--------------------------------------------------------------------------------------------------------------------- -QString VSpline::GetC2LengthFormula() const +auto VSpline::GetC2LengthFormula() const -> QString { return d->c2LengthF; } @@ -425,7 +428,7 @@ void VSpline::SetC2Length(qreal length, const QString &formula) * @brief GetKasm1 return coefficient of length first control line. * @return coefficient. */ -qreal VSpline::GetKasm1() const +auto VSpline::GetKasm1() const -> qreal { return QLineF(static_cast(d->p1), static_cast(GetP2())).length() / VSplineData::GetL(static_cast(d->p1), static_cast(d->p4), d->kCurve); @@ -436,7 +439,7 @@ qreal VSpline::GetKasm1() const * @brief GetKasm2 return coefficient of length second control line. * @return coefficient. */ -qreal VSpline::GetKasm2() const +auto VSpline::GetKasm2() const -> qreal { return QLineF(static_cast(d->p4), static_cast(GetP3())).length() / VSplineData::GetL(static_cast(d->p1), static_cast(d->p4), d->kCurve); @@ -447,13 +450,13 @@ qreal VSpline::GetKasm2() const * @brief GetKcurve return coefficient of curvature spline. * @return coefficient */ -qreal VSpline::GetKcurve() const +auto VSpline::GetKcurve() const -> qreal { return d->kCurve; } //--------------------------------------------------------------------------------------------------------------------- -int VSpline::Sign(long double ld) +auto VSpline::Sign(long double ld) -> int { if (qAbs(ld)<0.00000000001) { @@ -481,7 +484,7 @@ int VSpline::Sign(long double ld) * 1 - 1 real root + 2 complex; * 2 - 1 real root + complex roots imaginary part is zero (i.e. 2 real roots). */ -qint32 VSpline::Cubic(QVector &x, qreal a, qreal b, qreal c) +auto VSpline::Cubic(QVector &x, qreal a, qreal b, qreal c) -> qint32 { //To find cubic equation roots in the case of real coefficients, calculated at the beginning const qreal q = (pow(a, 2) - 3*b)/9.; @@ -494,26 +497,25 @@ qint32 VSpline::Cubic(QVector &x, qreal a, qreal b, qreal c) x.insert(2, -2.*sqrt(q)*cos(t - (2*M_2PI/3.)) - a/3.); return(3); } - else - { // 1 real root + 2 complex - //Formula Cardano - const qreal aa = -Sign(r)*pow(fabs(r)+sqrt(pow(r, 2)-pow(q, 3)), 1./3.); - const qreal bb = Sign(aa) == 0 ? 0 : q/aa; - x.insert(0, aa+bb-a/3.); // Real root - x.insert(1, (-0.5)*(aa+bb)-a/3.); //Complex root - x.insert(2, (sqrt(3.)*0.5)*fabs(aa-bb)); // Complex root - if (qFuzzyIsNull(x.at(2))) - { - return(2); - } - return(1); + // 1 real root + 2 complex + //Formula Cardano + const qreal aa = -Sign(r)*pow(fabs(r)+sqrt(pow(r, 2)-pow(q, 3)), 1./3.); + const qreal bb = Sign(aa) == 0 ? 0 : q/aa; + + x.insert(0, aa+bb-a/3.); // Real root + x.insert(1, (-0.5)*(aa+bb)-a/3.); //Complex root + x.insert(2, (sqrt(3.)*0.5)*fabs(aa-bb)); // Complex root + if (qFuzzyIsNull(x.at(2))) + { + return(2); } + return(1); } //--------------------------------------------------------------------------------------------------------------------- -QVector VSpline::CalcT (qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, - qreal curveCoord4, qreal pointCoord) const +auto VSpline::CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, + qreal pointCoord) -> QVector { const qreal a = -curveCoord1 + 3*curveCoord2 - 3*curveCoord3 + curveCoord4; const qreal b = 3*curveCoord1 - 6*curveCoord2 + 3*curveCoord3; @@ -524,11 +526,12 @@ QVector VSpline::CalcT (qreal curveCoord1, qreal curveCoord2, qreal curve Cubic(t, b/a, c/a, d/a); QVector retT; - for (int i=0; i < t.size(); ++i) + retT.reserve(t.size()); + for (auto i : qAsConst(t)) { - if ( t.at(i) >= 0 && t.at(i) <= 1 ) + if (i >= 0 && i <= 1 ) { - retT.append(t.at(i)); + retT.append(i); } } @@ -544,7 +547,7 @@ QVector VSpline::CalcT (qreal curveCoord1, qreal curveCoord2, qreal curve * @param pBt point on curve * @return t coeffient that reprezent this point on curve. Return -1 if point doesn't belongs to curve. */ -qreal VSpline::ParamT (const QPointF &pBt) const +auto VSpline::ParamT (const QPointF &pBt) const -> qreal { QVector ts; // Calculate t coefficient for each axis @@ -583,7 +586,7 @@ qreal VSpline::ParamT (const QPointF &pBt) const } //--------------------------------------------------------------------------------------------------------------------- -QJsonObject VSpline::ToJson() const +auto VSpline::ToJson() const -> QJsonObject { QJsonObject object = VAbstractCubicBezier::ToJson(); object[QLatin1String("aScale")] = GetApproximationScale(); @@ -601,13 +604,13 @@ QJsonObject VSpline::ToJson() const } //--------------------------------------------------------------------------------------------------------------------- -QPointF VSpline::GetControlPoint1() const +auto VSpline::GetControlPoint1() const -> QPointF { return static_cast(GetP2 ()); } //--------------------------------------------------------------------------------------------------------------------- -QPointF VSpline::GetControlPoint2() const +auto VSpline::GetControlPoint2() const -> QPointF { return static_cast(GetP3 ()); } diff --git a/src/libs/vgeometry/vspline.h b/src/libs/vgeometry/vspline.h index 6430bb560..6386930d1 100644 --- a/src/libs/vgeometry/vspline.h +++ b/src/libs/vgeometry/vspline.h @@ -52,81 +52,81 @@ class VSpline final :public VAbstractCubicBezier { public: VSpline(); - VSpline (const VSpline &spline ); - VSpline (const VPointF &p1, const VPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, - quint32 idObject = 0, Draw mode = Draw::Calculation); - VSpline (const VPointF &p1, const QPointF &p2, const QPointF &p3, const VPointF &p4, quint32 idObject = 0, - Draw mode = Draw::Calculation); - VSpline (const VPointF &p1, const VPointF &p4, qreal angle1, const QString &angle1Formula, qreal angle2, - const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, - const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation); - VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const; - VSpline Flip(const QLineF &axis, const QString &prefix = QString()) const; - VSpline Move(qreal length, qreal angle, const QString &prefix = QString()) const; - virtual ~VSpline(); + VSpline(const VSpline &spline ); + VSpline(const VPointF &p1, const VPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, + quint32 idObject = 0, Draw mode = Draw::Calculation); + VSpline(const VPointF &p1, const QPointF &p2, const QPointF &p3, const VPointF &p4, quint32 idObject = 0, + Draw mode = Draw::Calculation); + VSpline(const VPointF &p1, const VPointF &p4, qreal angle1, const QString &angle1Formula, qreal angle2, + const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length, + const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation); + auto Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const -> VSpline; + auto Flip(const QLineF &axis, const QString &prefix = QString()) const -> VSpline; + auto Move(qreal length, qreal angle, const QString &prefix = QString()) const -> VSpline; + ~VSpline() override; - VSpline &operator=(const VSpline &spline); + auto operator=(const VSpline &spline) -> VSpline &; #ifdef Q_COMPILER_RVALUE_REFS - VSpline(const VSpline &&spline) Q_DECL_NOTHROW; - VSpline &operator=(VSpline &&spline) Q_DECL_NOTHROW; + VSpline(VSpline &&spline) Q_DECL_NOTHROW; + auto operator=(VSpline &&spline) Q_DECL_NOTHROW -> VSpline &; #endif - virtual VPointF GetP1 () const override; - void SetP1 (const VPointF &p); + auto GetP1() const -> VPointF override; + void SetP1(const VPointF &p); - virtual VPointF GetP2 () const override; - virtual VPointF GetP3 () const override; + auto GetP2() const -> VPointF override; + auto GetP3() const -> VPointF override; - virtual VPointF GetP4 () const override; - void SetP4 (const VPointF &p); + auto GetP4() const -> VPointF override; + void SetP4(const VPointF &p); - virtual qreal GetStartAngle () const override; - virtual qreal GetEndAngle() const override; + auto GetStartAngle() const -> qreal override; + auto GetEndAngle() const -> qreal override; - QString GetStartAngleFormula () const; - QString GetEndAngleFormula() const; + auto GetStartAngleFormula () const -> QString; + auto GetEndAngleFormula() const -> QString; - void SetStartAngle(qreal angle, const QString &formula); - void SetEndAngle(qreal angle, const QString &formula); + void SetStartAngle(qreal angle, const QString &formula); + void SetEndAngle(qreal angle, const QString &formula); - virtual qreal GetC1Length() const override; - virtual qreal GetC2Length() const override; + auto GetC1Length() const -> qreal override; + auto GetC2Length() const -> qreal override; - QString GetC1LengthFormula() const; - QString GetC2LengthFormula() const; + auto GetC1LengthFormula() const -> QString; + auto GetC2LengthFormula() const -> QString; - void SetC1Length(qreal length, const QString &formula); - void SetC2Length(qreal length, const QString &formula); + void SetC1Length(qreal length, const QString &formula); + void SetC2Length(qreal length, const QString &formula); - virtual qreal GetLength () const override; - qreal GetKasm1() const; - qreal GetKasm2() const; - qreal GetKcurve() const; + auto GetLength() const -> qreal override; + auto GetKasm1() const -> qreal; + auto GetKasm2() const -> qreal; + auto GetKcurve() const -> qreal; using VAbstractCubicBezier::CutSpline; - QPointF CutSpline(qreal length, VSpline &spl1, VSpline &spl2, const QString &pointName) const; + auto CutSpline(qreal length, VSpline &spl1, VSpline &spl2, const QString &pointName) const -> QPointF; - virtual QVector GetPoints () const override; + auto GetPoints() const -> QVector override; // cppcheck-suppress unusedFunction - static QVector SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, - qreal kAsm2, qreal kCurve, qreal approximationScale); - qreal ParamT(const QPointF &pBt) const; + static auto SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, + qreal kAsm2, qreal kCurve, qreal approximationScale) -> QVector; + auto ParamT(const QPointF &pBt) const -> qreal; - virtual QJsonObject ToJson() const override; + auto ToJson() const -> QJsonObject override; protected: - virtual QPointF GetControlPoint1() const override; - virtual QPointF GetControlPoint2() const override; - auto GetRealLength () const -> qreal override; + auto GetControlPoint1() const -> QPointF override; + auto GetControlPoint2() const -> QPointF override; + auto GetRealLength() const -> qreal override; private: QSharedDataPointer d; - QVector CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, - qreal pointCoord) const; - static qint32 Cubic(QVector &x, qreal a, qreal b, qreal c); - static int Sign(long double ld); + static auto CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, + qreal pointCoord) -> QVector; + static auto Cubic(QVector &x, qreal a, qreal b, qreal c) -> qint32; + static auto Sign(long double ld) -> int; }; -Q_DECLARE_METATYPE(VSpline) -Q_DECLARE_TYPEINFO(VSpline, Q_MOVABLE_TYPE); +Q_DECLARE_METATYPE(VSpline) // NOLINT +Q_DECLARE_TYPEINFO(VSpline, Q_MOVABLE_TYPE); // NOLINT #endif // VSPLINE_H diff --git a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp index 2f13d7956..efa39d012 100644 --- a/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp +++ b/src/libs/vtools/tools/drawTools/toolpoint/toolsinglepoint/toolcut/vtoolcutspline.cpp @@ -278,7 +278,7 @@ void VToolCutSpline::SetVisualization() } //--------------------------------------------------------------------------------------------------------------------- -QString VToolCutSpline::MakeToolTip() const +auto VToolCutSpline::MakeToolTip() const -> QString { const auto spl = VAbstractTool::data.GeometricObject(baseCurveId);