Seamly2D
Code documentation
vspline.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vspline.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VSPLINE_H
53 #define VSPLINE_H
54 
55 #include <qcompilerdetection.h>
56 #include <QLineF>
57 #include <QMetaType>
58 #include <QPointF>
59 #include <QSharedDataPointer>
60 #include <QString>
61 #include <QTypeInfo>
62 #include <QVector>
63 #include <QtGlobal>
64 
65 #include "vabstractcubicbezier.h"
66 #include "vgeometrydef.h"
67 #include "vpointf.h"
68 
69 class VSplineData;
70 
71 /**
72  * @brief VSpline class that implements the spline.
73  */
75 {
76 public:
77  VSpline();
78  VSpline (const VSpline &spline );
79  VSpline (const VPointF &p1, const VPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
80  quint32 idObject = 0, Draw mode = Draw::Calculation);
81  VSpline (const VPointF &p1, const QPointF &p2, const QPointF &p3, const VPointF &p4, quint32 idObject = 0,
82  Draw mode = Draw::Calculation);
83  VSpline (const VPointF &p1, const VPointF &p4, qreal angle1, const QString &angle1Formula, qreal angle2,
84  const QString &angle2Formula, qreal c1Length, const QString &c1LengthFormula, qreal c2Length,
85  const QString &c2LengthFormula, quint32 idObject = 0, Draw mode = Draw::Calculation);
86  VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix = QString()) const;
87  VSpline Flip(const QLineF &axis, const QString &prefix = QString()) const;
88  VSpline Move(qreal length, qreal angle, const QString &prefix = QString()) const;
89  virtual ~VSpline();
90 
91  VSpline &operator=(const VSpline &spline);
92 #ifdef Q_COMPILER_RVALUE_REFS
93  VSpline &operator=(VSpline &&spline) Q_DECL_NOTHROW;
94 #endif
95 
96  void Swap(VSpline &spline) Q_DECL_NOTHROW;
97 
98  virtual VPointF GetP1 () const Q_DECL_OVERRIDE;
99  void SetP1 (const VPointF &p);
100 
101  virtual VPointF GetP2 () const Q_DECL_OVERRIDE;
102  virtual VPointF GetP3 () const Q_DECL_OVERRIDE;
103 
104  virtual VPointF GetP4 () const Q_DECL_OVERRIDE;
105  void SetP4 (const VPointF &p);
106 
107  virtual qreal GetStartAngle () const Q_DECL_OVERRIDE;
108  virtual qreal GetEndAngle() const Q_DECL_OVERRIDE;
109 
110  QString GetStartAngleFormula () const;
111  QString GetEndAngleFormula() const;
112 
113  void SetStartAngle(qreal angle, const QString &formula);
114  void SetEndAngle(qreal angle, const QString &formula);
115 
116  virtual qreal GetC1Length() const Q_DECL_OVERRIDE;
117  virtual qreal GetC2Length() const Q_DECL_OVERRIDE;
118 
119  QString GetC1LengthFormula() const;
120  QString GetC2LengthFormula() const;
121 
122  void SetC1Length(qreal length, const QString &formula);
123  void SetC2Length(qreal length, const QString &formula);
124 
125  virtual qreal GetLength () const Q_DECL_OVERRIDE;
126  qreal GetKasm1() const;
127  qreal GetKasm2() const;
128  qreal GetKcurve() const;
129 
131  QPointF CutSpline ( qreal length, VSpline &spl1, VSpline &spl2) const;
132 
133  virtual QVector<QPointF> getPoints() const Q_DECL_OVERRIDE;
134  // cppcheck-suppress unusedFunction
135  static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
136  qreal kAsm2, qreal kCurve);
137  qreal ParamT(const QPointF &pBt) const;
138 
139 protected:
140  virtual QPointF GetControlPoint1() const Q_DECL_OVERRIDE;
141  virtual QPointF GetControlPoint2() const Q_DECL_OVERRIDE;
142 private:
143  QSharedDataPointer<VSplineData> d;
144  QVector<qreal> CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4,
145  qreal pointCoord) const;
146  static qint32 Cubic(QVector<qreal> &x, qreal a, qreal b, qreal c);
147  static int Sign(long double ld);
148 };
149 
150 Q_DECLARE_METATYPE(VSpline)
151 Q_DECLARE_TYPEINFO(VSpline, Q_MOVABLE_TYPE);
152 
153 #endif // VSPLINE_H
QPointF CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const
CutSpline cut spline.
The VPointF class keep data of point.
Definition: vpointf.h:75
VSpline class that implements the spline.
Definition: vspline.h:75
virtual qreal GetLength() const Q_DECL_OVERRIDE
GetLength return length of spline.
Definition: vspline.cpp:203
VSpline Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
Definition: vspline.cpp:144
virtual QPointF GetControlPoint2() const Q_DECL_OVERRIDE
Definition: vspline.cpp:586
static qint32 Cubic(QVector< qreal > &x, qreal a, qreal b, qreal c)
Cubic Cubic equation solution. Real coefficients case.
Definition: vspline.cpp:477
virtual qreal GetC2Length() const Q_DECL_OVERRIDE
Definition: vspline.cpp:385
virtual VPointF GetP4() const Q_DECL_OVERRIDE
GetP4 return last spline point.
Definition: vspline.cpp:321
void SetP4(const VPointF &p)
Definition: vspline.cpp:327
void SetC1Length(qreal length, const QString &formula)
Definition: vspline.cpp:403
QString GetC1LengthFormula() const
Definition: vspline.cpp:391
VSpline()
VSpline default constructor.
Definition: vspline.cpp:71
qreal GetKcurve() const
GetKcurve return coefficient of curvature spline.
Definition: vspline.cpp:443
void SetC2Length(qreal length, const QString &formula)
Definition: vspline.cpp:410
VSpline & operator=(const VSpline &spline)
Definition: vspline.cpp:265
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
GetAngle1 return first angle control line.
Definition: vspline.cpp:337
virtual ~VSpline()
Definition: vspline.cpp:195
void SetP1(const VPointF &p)
Definition: vspline.cpp:287
qreal ParamT(const QPointF &pBt) const
VSpline::ParamT calculate t coeffient that reprezent point on curve.
Definition: vspline.cpp:540
VSpline Flip(const QLineF &axis, const QString &prefix=QString()) const
Definition: vspline.cpp:161
virtual VPointF GetP1() const Q_DECL_OVERRIDE
GetP1 return first spline point.
Definition: vspline.cpp:281
virtual VPointF GetP2() const Q_DECL_OVERRIDE
GetP2 return first control point.
Definition: vspline.cpp:297
QString GetStartAngleFormula() const
Definition: vspline.cpp:353
QString GetEndAngleFormula() const
Definition: vspline.cpp:359
qreal GetKasm1() const
GetKasm1 return coefficient of length first control line.
Definition: vspline.cpp:421
static QVector< QPointF > SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve)
SplinePoints return list with spline points.
Definition: vspline.cpp:247
QPointF CutSpline(qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const
CutSpline cut spline.
virtual qreal GetC1Length() const Q_DECL_OVERRIDE
Definition: vspline.cpp:379
void Swap(VSpline &spline) Q_DECL_NOTHROW
Definition: vspline.cpp:64
virtual VPointF GetP3() const Q_DECL_OVERRIDE
GetP3 return second control point.
Definition: vspline.cpp:309
QString GetC2LengthFormula() const
Definition: vspline.cpp:397
VSpline Move(qreal length, qreal angle, const QString &prefix=QString()) const
Definition: vspline.cpp:178
QVector< qreal > CalcT(qreal curveCoord1, qreal curveCoord2, qreal curveCoord3, qreal curveCoord4, qreal pointCoord) const
Definition: vspline.cpp:508
void SetStartAngle(qreal angle, const QString &formula)
Definition: vspline.cpp:365
virtual QVector< QPointF > getPoints() const Q_DECL_OVERRIDE
GetPoints return list with spline points.
Definition: vspline.cpp:228
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
GetAngle2 return second angle control line.
Definition: vspline.cpp:347
void SetEndAngle(qreal angle, const QString &formula)
Definition: vspline.cpp:372
QSharedDataPointer< VSplineData > d
Definition: vspline.h:143
virtual QPointF GetControlPoint1() const Q_DECL_OVERRIDE
Definition: vspline.cpp:580
static int Sign(long double ld)
Definition: vspline.cpp:449
qreal GetKasm2() const
GetKasm2 return coefficient of length second control line.
Definition: vspline.cpp:432
Draw
Definition: vgeometrydef.h:55
@ Calculation
Q_DECLARE_TYPEINFO(VSpline, Q_MOVABLE_TYPE)