Seamly2D
Code documentation
vpointf.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 vpointf.cpp
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 #include "vpointf.h"
53 #include "vpointf_p.h"
54 #include <QLineF>
55 #include <QPointF>
56 #include <QString>
57 #include <QTransform>
58 
59 #ifdef Q_COMPILER_RVALUE_REFS
60 VPointF &VPointF::operator=(VPointF &&point) Q_DECL_NOTHROW { Swap(point); return *this; }
61 #endif
62 
63 void VPointF::Swap(VPointF &point) Q_DECL_NOTHROW
64 { VGObject::Swap(point); std::swap(d, point.d); }
65 
66 //---------------------------------------------------------------------------------------------------------------------
67 /**
68  * @brief VPointF creat empty point
69  */
72  , d(new VPointFData)
73 {}
74 
75 //---------------------------------------------------------------------------------------------------------------------
77  : VGObject(point)
78  , d(point.d)
79 {}
80 
81 //---------------------------------------------------------------------------------------------------------------------
82 VPointF::VPointF(const QPointF &point)
83  : VGObject(VPointF())
84  , d(new VPointFData(point))
85 {}
86 
87 //---------------------------------------------------------------------------------------------------------------------
88 /**
89  * @brief VPointF create new point
90  * @param x x coordinate
91  * @param y y coordinate
92  * @param name point label
93  * @param mx offset name respect to x
94  * @param my offset name respect to y
95  */
96 VPointF::VPointF(qreal x, qreal y, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
97  : VGObject(GOType::Point, idObject, mode)
98  , d(new VPointFData(x, y, mx, my))
99 {
100  setName(name);
101 }
102 
103 //---------------------------------------------------------------------------------------------------------------------
104 /**
105  * @brief VPointF create new point
106  * @param point point
107  * @param name point label
108  * @param mx offset name respect to x
109  * @param my offset name respect to y
110  */
111 VPointF::VPointF(const QPointF &point, const QString &name, qreal mx, qreal my, quint32 idObject, const Draw &mode)
112  : VGObject(GOType::Point, idObject, mode)
113  , d(new VPointFData(point, mx, my))
114 {
115  setName(name);
116 }
117 
118 //---------------------------------------------------------------------------------------------------------------------
120 {}
121 
122 //---------------------------------------------------------------------------------------------------------------------
123 /**
124  * @brief operator = assignment operator
125  * @param point point
126  * @return point
127  */
129 {
130  if ( &point == this )
131  {
132  return *this;
133  }
134  VGObject::operator=(point);
135  d = point.d;
136  return *this;
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
140 VPointF::operator QPointF() const
141 {
142  return toQPointF();
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 VPointF VPointF::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const
147 {
148  const QPointF newPoint = RotatePF(originPoint, toQPointF(), degrees);
149  VPointF rotated(newPoint, name() + prefix, mx(), my());
151  return rotated;
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
155 VPointF VPointF::Flip(const QLineF &axis, const QString &prefix) const
156 {
157  const QPointF newPoint = FlipPF(axis, toQPointF());
158  VPointF flipped(newPoint, name() + prefix, mx(), my());
160  return flipped;
161 }
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 VPointF VPointF::Move(qreal length, qreal angle, const QString &prefix) const
165 {
166  const QPointF newPoint = MovePF(toQPointF(), length, angle);
167  VPointF moved(newPoint, name() + prefix, mx(), my());
169  return moved;
170 }
171 
172 //---------------------------------------------------------------------------------------------------------------------
173 /**
174  * @brief mx return offset name respect to x
175  * @return offset
176  */
177 qreal VPointF::mx() const
178 {
179  return d->_mx;
180 }
181 
182 //---------------------------------------------------------------------------------------------------------------------
183 /**
184  * @brief my return offset name respect to y
185  * @return offset
186  */
187 qreal VPointF::my() const
188 {
189  return d->_my;
190 }
191 
192 //---------------------------------------------------------------------------------------------------------------------
193 /**
194  * @brief setMx set offset name respect to x
195  * @param mx offset
196  */
197 void VPointF::setMx(qreal mx)
198 {
199  d->_mx = mx;
200 }
201 
202 //---------------------------------------------------------------------------------------------------------------------
203 /**
204  * @brief setMy set offset name respect to y
205  * @param my offset
206  */
207 void VPointF::setMy(qreal my)
208 {
209  d->_my = my;
210 }
211 
212 //---------------------------------------------------------------------------------------------------------------------
213 QPointF VPointF::toQPointF() const
214 {
215  return QPointF(d->_x, d->_y);
216 }
217 
218 //---------------------------------------------------------------------------------------------------------------------
219 /**
220  * @brief x return x coordinate
221  * @return value
222  */
223 qreal VPointF::x() const
224 {
225  return d->_x;
226 }
227 
228 //---------------------------------------------------------------------------------------------------------------------
229 /**
230  * @brief setX set x coordinate
231  * @param value x coordinate
232  */
233 void VPointF::setX(const qreal &value)
234 {
235  d->_x = value;
236 }
237 
238 //---------------------------------------------------------------------------------------------------------------------
239 /**
240  * @brief y return y coordinate
241  * @return value
242  */
243 qreal VPointF::y() const
244 {
245  return d->_y;
246 }
247 
248 //---------------------------------------------------------------------------------------------------------------------
249 /**
250  * @brief setY set y coordinate
251  * @param value y coordinate
252  */
253 void VPointF::setY(const qreal &value)
254 {
255  d->_y = value;
256 }
257 
258 //---------------------------------------------------------------------------------------------------------------------
260 {
261  return d->m_showPointName;
262 }
263 
264 //---------------------------------------------------------------------------------------------------------------------
266 {
267  d->m_showPointName = show;
268 }
269 
270 //---------------------------------------------------------------------------------------------------------------------
271 QPointF VPointF::RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees)
272 {
273  QLineF axis(originPoint, point);
274  axis.setAngle(axis.angle() + degrees);
275  return axis.p2();
276 }
277 
278 //---------------------------------------------------------------------------------------------------------------------
279 QPointF VPointF::FlipPF(const QLineF &axis, const QPointF &point)
280 {
281  const QTransform transform = flipTransform(axis);
282  return transform.map(point);
283 }
284 
285 //---------------------------------------------------------------------------------------------------------------------
286 QPointF VPointF::MovePF(const QPointF &originPoint, qreal length, qreal angle)
287 {
288  QLineF line(originPoint.x(), originPoint.y(), originPoint.x() + length, originPoint.y());
289  line.setAngle(angle);
290  return line.p2();
291 }
The VGObject class keep information graphical objects.
Definition: vgobject.h:74
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
VGObject & operator=(const VGObject &obj)
operator = assignment operator.
Definition: vgobject.cpp:109
static QTransform flipTransform(const QLineF &axis)
Definition: vgobject.cpp:591
void Swap(VGObject &obj) Q_DECL_NOTHROW
Definition: vgobject.cpp:72
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
void setMx(qreal mx)
setMx set offset name respect to x
Definition: vpointf.cpp:197
void setX(const qreal &value)
setX set x coordinate
Definition: vpointf.cpp:233
virtual ~VPointF() Q_DECL_OVERRIDE
Definition: vpointf.cpp:119
VPointF()
VPointF creat empty point.
Definition: vpointf.cpp:70
void setMy(qreal my)
setMy set offset name respect to y
Definition: vpointf.cpp:207
VPointF & operator=(const VPointF &point)
operator = assignment operator
Definition: vpointf.cpp:128
void setY(const qreal &value)
setY set y coordinate
Definition: vpointf.cpp:253
static QPointF RotatePF(const QPointF &originPoint, const QPointF &point, qreal degrees)
Definition: vpointf.cpp:271
qreal mx() const
mx return offset name respect to x
Definition: vpointf.cpp:177
void Swap(VPointF &point) Q_DECL_NOTHROW
Definition: vpointf.cpp:63
static QPointF MovePF(const QPointF &originPoint, qreal length, qreal angle)
Definition: vpointf.cpp:286
QSharedDataPointer< VPointFData > d
Definition: vpointf.h:115
bool isShowPointName() const
Definition: vpointf.cpp:259
VPointF Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix=QString()) const
Definition: vpointf.cpp:146
void setShowPointName(bool show)
Definition: vpointf.cpp:265
VPointF Flip(const QLineF &axis, const QString &prefix=QString()) const
Definition: vpointf.cpp:155
QPointF toQPointF() const
Definition: vpointf.cpp:213
qreal y() const
y return y coordinate
Definition: vpointf.cpp:243
qreal my() const
my return offset name respect to y
Definition: vpointf.cpp:187
VPointF Move(qreal length, qreal angle, const QString &prefix=QString()) const
Definition: vpointf.cpp:164
static QPointF FlipPF(const QLineF &axis, const QPointF &point)
Definition: vpointf.cpp:279
qreal x() const
x return x coordinate
Definition: vpointf.cpp:223
GOType
Definition: vgeometrydef.h:56
Draw
Definition: vgeometrydef.h:55
@ Calculation