Seamly2D
Code documentation
vcubicbezier.cpp
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 vcubicbezier.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 8 3, 2016
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) 2016 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 #include "vcubicbezier.h"
53 
54 #include <QLineF>
55 
56 #include "vcubicbezier_p.h"
57 
58 #ifdef Q_COMPILER_RVALUE_REFS
59 VCubicBezier &VCubicBezier::operator=(VCubicBezier &&curve) Q_DECL_NOTHROW
60 { Swap(curve); return *this; }
61 #endif
62 
63 void VCubicBezier::Swap(VCubicBezier &curve) Q_DECL_NOTHROW
64 { VAbstractCubicBezier::Swap(curve); std::swap(d, curve.d); }
65 
66 //---------------------------------------------------------------------------------------------------------------------
69 {
70 }
71 
72 //---------------------------------------------------------------------------------------------------------------------
74  : VAbstractCubicBezier(curve), d(curve.d)
75 {
76 }
77 
78 //---------------------------------------------------------------------------------------------------------------------
79 VCubicBezier::VCubicBezier(const VPointF &p1, const VPointF &p2, const VPointF &p3, const VPointF &p4, quint32 idObject,
80  Draw mode)
81  : VAbstractCubicBezier(GOType::CubicBezier, idObject, mode), d(new VCubicBezierData(p1, p2, p3, p4))
82 {
83  CreateName();
84 }
85 
86 //---------------------------------------------------------------------------------------------------------------------
88 {
89  if ( &curve == this )
90  {
91  return *this;
92  }
94  d = curve.d;
95  return *this;
96 }
97 
98 //---------------------------------------------------------------------------------------------------------------------
99 VCubicBezier VCubicBezier::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const
100 {
101  const VPointF p1 = GetP1().Rotate(originPoint, degrees);
102  const VPointF p2 = GetP2().Rotate(originPoint, degrees);
103  const VPointF p3 = GetP3().Rotate(originPoint, degrees);
104  const VPointF p4 = GetP4().Rotate(originPoint, degrees);
105  VCubicBezier curve(p1, p2, p3, p4);
106  curve.setName(name() + prefix);
107  curve.setLineColor(getLineColor());
108  curve.SetPenStyle(GetPenStyle());
109  curve.setLineWeight(getLineWeight());
110  return curve;
111 }
112 
113 //---------------------------------------------------------------------------------------------------------------------
114 VCubicBezier VCubicBezier::Flip(const QLineF &axis, const QString &prefix) const
115 {
116  const VPointF p1 = GetP1().Flip(axis);
117  const VPointF p2 = GetP2().Flip(axis);
118  const VPointF p3 = GetP3().Flip(axis);
119  const VPointF p4 = GetP4().Flip(axis);
120  VCubicBezier curve(p1, p2, p3, p4);
121  curve.setName(name() + prefix);
122  curve.setLineColor(getLineColor());
123  curve.SetPenStyle(GetPenStyle());
124  curve.setLineWeight(getLineWeight());
125  return curve;
126 }
127 
128 //---------------------------------------------------------------------------------------------------------------------
129 VCubicBezier VCubicBezier::Move(qreal length, qreal angle, const QString &prefix) const
130 {
131  const VPointF p1 = GetP1().Move(length, angle);
132  const VPointF p2 = GetP2().Move(length, angle);
133  const VPointF p3 = GetP3().Move(length, angle);
134  const VPointF p4 = GetP4().Move(length, angle);
135  VCubicBezier curve(p1, p2, p3, p4);
136  curve.setName(name() + prefix);
137  curve.setLineColor(getLineColor());
138  curve.SetPenStyle(GetPenStyle());
139  curve.setLineWeight(getLineWeight());
140  return curve;
141 }
142 
143 //---------------------------------------------------------------------------------------------------------------------
145 {
146 }
147 
148 //---------------------------------------------------------------------------------------------------------------------
150 {
151  return d->p1;
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
156 {
157  d->p1 = p;
158 }
159 
160 //---------------------------------------------------------------------------------------------------------------------
162 {
163  return d->p2;
164 }
165 
166 //---------------------------------------------------------------------------------------------------------------------
168 {
169  d->p2 = p;
170 }
171 
172 //---------------------------------------------------------------------------------------------------------------------
174 {
175  return d->p3;
176 }
177 
178 //---------------------------------------------------------------------------------------------------------------------
180 {
181  d->p3 = p;
182 }
183 
184 //---------------------------------------------------------------------------------------------------------------------
186 {
187  return d->p4;
188 }
189 
190 //---------------------------------------------------------------------------------------------------------------------
192 {
193  d->p4 = p;
194 }
195 
196 //---------------------------------------------------------------------------------------------------------------------
198 {
199  return QLineF(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2())).angle();
200 }
201 
202 //---------------------------------------------------------------------------------------------------------------------
204 {
205  return QLineF(static_cast<QPointF>(GetP4()), static_cast<QPointF>(GetP3())).angle();
206 }
207 
208 //---------------------------------------------------------------------------------------------------------------------
209 /**
210  * @brief GetLength return length of cubic bezier curve.
211  * @return length.
212  */
214 {
215  return LengthBezier (static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2()),
216  static_cast<QPointF>(GetP3()), static_cast<QPointF>(GetP4()));
217 }
218 
219 //---------------------------------------------------------------------------------------------------------------------
220 /**
221  * @brief GetPoints return list with cubic bezier curve points.
222  * @return list of points.
223  */
225 {
226  return GetCubicBezierPoints(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2()),
227  static_cast<QPointF>(GetP3()), static_cast<QPointF>(GetP4()));
228 }
229 
230 //---------------------------------------------------------------------------------------------------------------------
232 {
233  return QLineF(static_cast<QPointF>(GetP1()), static_cast<QPointF>(GetP2())).length();
234 }
235 
236 //---------------------------------------------------------------------------------------------------------------------
238 {
239  return QLineF(static_cast<QPointF>(GetP4()), static_cast<QPointF>(GetP3())).length();
240 }
241 
242 //---------------------------------------------------------------------------------------------------------------------
244 {
245  return static_cast<QPointF>(GetP2());
246 }
247 
248 //---------------------------------------------------------------------------------------------------------------------
250 {
251  return static_cast<QPointF>(GetP3());
252 }
VAbstractCubicBezier & operator=(const VAbstractCubicBezier &curve)
static qreal LengthBezier(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
LengthBezier return spline length using 4 spline point.
virtual void CreateName() Q_DECL_OVERRIDE
static QVector< QPointF > GetCubicBezierPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
GetCubicBezierPoints return list with cubic bezier curve points.
QString getLineWeight() const
getLineWeight return weight of the lines
void SetPenStyle(const QString &penStyle)
void setLineColor(const QString &color)
void setLineWeight(const QString &lineWeight)
setLineWeight set weight of the lines
QString GetPenStyle() const
void Swap(VAbstractCurve &curve) Q_DECL_NOTHROW
QString getLineColor() const
virtual qreal GetC2Length() const Q_DECL_OVERRIDE
virtual qreal GetStartAngle() const Q_DECL_OVERRIDE
void Swap(VCubicBezier &curve) Q_DECL_NOTHROW
void SetP4(const VPointF &p)
void SetP3(const VPointF &p)
virtual QPointF GetControlPoint1() const Q_DECL_OVERRIDE
virtual qreal GetEndAngle() const Q_DECL_OVERRIDE
virtual VPointF GetP1() const Q_DECL_OVERRIDE
QSharedDataPointer< VCubicBezierData > d
Definition: vcubicbezier.h:113
VCubicBezier Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
virtual qreal GetC1Length() const Q_DECL_OVERRIDE
VCubicBezier Move(qreal length, qreal angle, const QString &prefix=QString()) const
VCubicBezier & operator=(const VCubicBezier &curve)
virtual VPointF GetP3() const Q_DECL_OVERRIDE
void SetP1(const VPointF &p)
virtual QPointF GetControlPoint2() const Q_DECL_OVERRIDE
virtual qreal GetLength() const Q_DECL_OVERRIDE
GetLength return length of cubic bezier curve.
virtual VPointF GetP2() const Q_DECL_OVERRIDE
void SetP2(const VPointF &p)
VCubicBezier Flip(const QLineF &axis, const QString &prefix=QString()) const
virtual QVector< QPointF > getPoints() const Q_DECL_OVERRIDE
GetPoints return list with cubic bezier curve points.
virtual ~VCubicBezier()
virtual VPointF GetP4() const Q_DECL_OVERRIDE
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
void setName(const QString &name)
setName set name graphical object.
Definition: vgobject.cpp:158
The VPointF class keep data of point.
Definition: vpointf.h:75
VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
Definition: vpointf.cpp:146
VPointF Flip(const QLineF &axis, const QString &prefix=QString()) const
Definition: vpointf.cpp:155
VPointF Move(qreal length, qreal angle, const QString &prefix=QString()) const
Definition: vpointf.cpp:164
GOType
Definition: vgeometrydef.h:56
@ CubicBezier
Draw
Definition: vgeometrydef.h:55