Seamly2D
Code documentation
vspline_p.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_p.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 20 8, 2014
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_P_H
53 #define VSPLINE_P_H
54 
55 #include <QSharedData>
56 #include <QLineF>
57 
58 #include "vpointf.h"
59 #include "../vmisc/vabstractapplication.h"
60 #include "../vmisc/vmath.h"
61 
62 QT_WARNING_PUSH
63 QT_WARNING_DISABLE_GCC("-Weffc++")
64 QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
65 
66 class VSplineData : public QSharedData
67 {
68 public:
69  VSplineData();
70  VSplineData(const VSplineData &spline);
71  VSplineData(VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve);
72  VSplineData(VPointF p1, QPointF p2, QPointF p3, VPointF p4);
73  VSplineData(VPointF p1, VPointF p4, qreal angle1, const QString &angle1F, qreal angle2, const QString &angle2F,
74  qreal c1Length, const QString &c1LengthF, qreal c2Length, const QString &c2LengthF);
75  virtual ~VSplineData();
76 
77  static qreal GetL(const QPointF &p1, const QPointF &p4, qreal kCurve);
78 
79  /** @brief p1 first spline point. */
81 
82  /** @brief p4 fourth spline point. */
84 
85  /** @brief angle1 first angle control line. */
86  qreal angle1;
87 
88  /** @brief angle1F the first control point angle formula*/
89  QString angle1F;
90 
91  /** @brief angle2 second angle control line. */
92  qreal angle2;
93 
94  /** @brief angle2F the second control point angle formula*/
95  QString angle2F;
96 
97  /** @brief c1Length the length from the first spline point to the first control point. */
98  qreal c1Length;
99 
100  /** @brief c1LengthF the formula from the first spline point to the first control point. */
101  QString c1LengthF;
102 
103  /** @brief c2Length the length from the fourth spline point to the second control point. */
104  qreal c2Length;
105 
106  /** @brief c2LengthF the formula length from the fourth spline point to the second control point. */
107  QString c2LengthF;
108 
109  /** @brief kCurve coefficient of curvature spline. */
110  qreal kCurve;
111 
112 private:
113  VSplineData &operator=(const VSplineData &) Q_DECL_EQ_DELETE;
114 };
115 
116 //---------------------------------------------------------------------------------------------------------------------
118  : p1(),
119  p4(),
120  angle1(0),
121  angle1F("0"),
122  angle2(0),
123  angle2F("0"),
124  c1Length(0),
125  c1LengthF("0"),
126  c2Length(0),
127  c2LengthF("0"),
128  kCurve(1)
129 {}
130 
131 //---------------------------------------------------------------------------------------------------------------------
133  : QSharedData(spline),
134  p1(spline.p1),
135  p4(spline.p4),
136  angle1(spline.angle1),
137  angle1F(spline.angle1F),
138  angle2(spline.angle2),
139  angle2F(spline.angle2F),
140  c1Length(spline.c1Length),
141  c1LengthF(spline.c1LengthF),
142  c2Length(spline.c2Length),
143  c2LengthF(spline.c2LengthF),
144  kCurve(spline.kCurve)
145 {}
146 
147 //---------------------------------------------------------------------------------------------------------------------
148 VSplineData::VSplineData(VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve)
149  : p1(p1),
150  p4(p4),
151  angle1(angle1),
152  angle1F(QString().number(angle1)),
153  angle2(angle2),
154  angle2F(QString().number(angle2)),
155  c1Length(0),
156  c1LengthF("0"),
157  c2Length(0),
158  c2LengthF("0"),
159  kCurve(kCurve)
160 {
161  const qreal L = GetL(static_cast<QPointF>(p1), static_cast<QPointF>(p4), kCurve);
162 
163  QLineF p1p2(p1.x(), p1.y(), p1.x() + L * kAsm1, p1.y());
164  p1p2.setAngle(angle1);
165  c1Length = p1p2.length();
166  c1LengthF = QString().number(qApp->fromPixel(c1Length));
167 
168  QLineF p4p3(p4.x(), p4.y(), p4.x() + L * kAsm2, p4.y());
169  p4p3.setAngle(angle2);
170  c2Length = p4p3.length();
171  c2LengthF = QString().number(qApp->fromPixel(c2Length));
172 }
173 
174 //---------------------------------------------------------------------------------------------------------------------
175 VSplineData::VSplineData(VPointF p1, QPointF p2, QPointF p3, VPointF p4)
176  : p1(p1),
177  p4(p4),
178  angle1(0),
179  angle1F("0"),
180  angle2(0),
181  angle2F("0"),
182  c1Length(0),
183  c1LengthF("0"),
184  c2Length(0),
185  c2LengthF("0"),
186  kCurve(1)
187 {
188  QLineF p1p2(static_cast<QPointF>(p1), static_cast<QPointF>(p2));
189 
190  angle1 = p1p2.angle();
191  angle1F = QString().number(angle1);
192 
193  c1Length = p1p2.length();
194  c1LengthF = QString().number(qApp->fromPixel(c1Length));
195 
196  QLineF p4p3(static_cast<QPointF>(p4), static_cast<QPointF>(p3));
197 
198  angle2 = p4p3.angle();
199  angle2F = QString().number(angle2);
200 
201  c2Length = p4p3.length();
202  c2LengthF = QString().number(qApp->fromPixel(c2Length));
203 }
204 
205 //---------------------------------------------------------------------------------------------------------------------
206 VSplineData::VSplineData(VPointF p1, VPointF p4, qreal angle1, const QString &angle1F, qreal angle2,
207  const QString &angle2F, qreal c1Length, const QString &c1LengthF,
208  qreal c2Length, const QString &c2LengthF)
209  : p1(p1),
210  p4(p4),
211  angle1(angle1),
212  angle1F(angle1F),
213  angle2(angle2),
214  angle2F(angle2F),
215  c1Length(c1Length),
216  c1LengthF(c1LengthF),
217  c2Length(c2Length),
218  c2LengthF(c2LengthF),
219  kCurve(1)
220 {}
221 
222 //---------------------------------------------------------------------------------------------------------------------
224 {}
225 
226 //---------------------------------------------------------------------------------------------------------------------
227 qreal VSplineData::GetL(const QPointF &p1, const QPointF &p4, qreal kCurve)
228 {
229  static const qreal angle = 90;
230  const qreal radius = QLineF(p1, p4).length()/M_SQRT2;
231  return kCurve * radius * 4 / 3 * qTan( angle * M_PI_4 / 180.0 );
232 }
233 
235 
236 #endif // VSPLINE_P_H
The VPointF class keep data of point.
Definition: vpointf.h:75
qreal y() const
y return y coordinate
Definition: vpointf.cpp:243
qreal x() const
x return x coordinate
Definition: vpointf.cpp:223
static qreal GetL(const QPointF &p1, const QPointF &p4, qreal kCurve)
Definition: vspline_p.h:227
VPointF p1
p1 first spline point.
Definition: vspline_p.h:80
QString angle1F
angle1F the first control point angle formula
Definition: vspline_p.h:89
qreal angle2
angle2 second angle control line.
Definition: vspline_p.h:92
virtual ~VSplineData()
Definition: vspline_p.h:223
qreal c1Length
c1Length the length from the first spline point to the first control point.
Definition: vspline_p.h:98
qreal c2Length
c2Length the length from the fourth spline point to the second control point.
Definition: vspline_p.h:104
qreal kCurve
kCurve coefficient of curvature spline.
Definition: vspline_p.h:110
QString c1LengthF
c1LengthF the formula from the first spline point to the first control point.
Definition: vspline_p.h:101
QString angle2F
angle2F the second control point angle formula
Definition: vspline_p.h:95
VPointF p4
p4 fourth spline point.
Definition: vspline_p.h:83
QString c2LengthF
c2LengthF the formula length from the fourth spline point to the second control point.
Definition: vspline_p.h:107
qreal angle1
angle1 first angle control line.
Definition: vspline_p.h:86
VSplineData & operator=(const VSplineData &) Q_DECL_EQ_DELETE
#define qApp
Definition: vapplication.h:67