Implicit Sharing for class VSplinePoint.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 16:21:43 +03:00
parent 40eab84c41
commit 2aaf98f20c
4 changed files with 180 additions and 115 deletions

View file

@ -13,7 +13,8 @@ HEADERS += \
geometry/vdetail_p.h \
geometry/vgobject_p.h \
geometry/varc_p.h \
geometry/vspline_p.h
geometry/vspline_p.h \
geometry/vsplinepoint_p.h
SOURCES += \
geometry/vsplinepoint.cpp \

View file

@ -27,6 +27,7 @@
*************************************************************************/
#include "vsplinepoint.h"
#include "vsplinepoint_p.h"
#include <QDebug>
#include <QLineF>
@ -35,7 +36,7 @@
* @brief VSplinePoint default constructor.
*/
VSplinePoint::VSplinePoint()
:pSpline(VPointF()), angle1(0), angle2(180), kAsm1(1), kAsm2(1)
:d(new VSplinePointData)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -48,14 +49,8 @@ VSplinePoint::VSplinePoint()
* @param angle2 second angle control line.
*/
VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2)
:pSpline(pSpline), angle1(0), angle2(180), kAsm1(kAsm1), kAsm2(kAsm2)
{
if (qFuzzyCompare(qAbs(angle1-angle2), 180) == false)
{
qDebug()<<"angle1 and angle2 are not equal.";
}
SetAngle2(angle2);
}
:d(new VSplinePointData(pSpline, kAsm1, angle1, kAsm2, angle2))
{}
//---------------------------------------------------------------------------------------------------------------------
/**
@ -63,7 +58,7 @@ VSplinePoint::VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAs
* @param point point
*/
VSplinePoint::VSplinePoint(const VSplinePoint &point)
:pSpline(point.P()), angle1(point.Angle1()), angle2(point.Angle2()), kAsm1(point.KAsm1()), kAsm2(point.KAsm2())
:d(point.d)
{}
//---------------------------------------------------------------------------------------------------------------------
@ -73,14 +68,14 @@ VSplinePoint &VSplinePoint::operator=(const VSplinePoint &point)
{
return *this;
}
this->pSpline = point.P();
this->angle1 = point.Angle1();
this->angle2 = point.Angle2();
this->kAsm1 = point.KAsm1();
this->kAsm2 = point.KAsm2();
d = point.d;
return *this;
}
//---------------------------------------------------------------------------------------------------------------------
VSplinePoint::~VSplinePoint()
{}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetAngle1 set first angle of spline.
@ -90,10 +85,10 @@ void VSplinePoint::SetAngle1(const qreal &value)
{
QLineF line(0, 0, 100, 0);
line.setAngle(value);
angle1 = line.angle();
d->angle1 = line.angle();
line.setAngle(value+180);
angle2 = line.angle();
d->angle2 = line.angle();
}
//---------------------------------------------------------------------------------------------------------------------
@ -105,8 +100,88 @@ void VSplinePoint::SetAngle2(const qreal &value)
{
QLineF line(0, 0, 100, 0);
line.setAngle(value);
angle2 = line.angle();
d->angle2 = line.angle();
line.setAngle(value-180);
angle1 = line.angle();
d->angle1 = line.angle();
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief P return point.
* @return point.
*/
VPointF VSplinePoint::P() const
{
return d->pSpline;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetP set point.
* @param value point.
*/
void VSplinePoint::SetP(const VPointF &value)
{
d->pSpline = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Angle1 return first angle of spline.
* @return angle.
*/
qreal VSplinePoint::Angle1() const
{
return d->angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Angle2 return second angle of spline.
* @return angle.
*/
qreal VSplinePoint::Angle2() const
{
return d->angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief KAsm1 return coefficient of length first control line.
* @return coefficient.
*/
qreal VSplinePoint::KAsm1() const
{
return d->kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm1 set coefficient of length first control line.
* @param value coefficient.
*/
void VSplinePoint::SetKAsm1(const qreal &value)
{
d->kAsm1 = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief KAsm2 return coefficient of length second control line.
* @return coefficient.
*/
qreal VSplinePoint::KAsm2() const
{
return d->kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm2 set coefficient of length second control line.
* @param value coefficient.
*/
void VSplinePoint::SetKAsm2(const qreal &value)
{
d->kAsm2 = value;
}

View file

@ -32,6 +32,8 @@
#include "vpointf.h"
#include <QMetaType>
class VSplinePointData;
/**
* @brief The VSplinePoint class keep information about point in spline path. Each point have two angles and two
* coefficient. Point represent at the same time first and last point of spline.
@ -43,7 +45,8 @@ public:
VSplinePoint(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2);
VSplinePoint(const VSplinePoint &point);
VSplinePoint &operator=(const VSplinePoint &point);
~VSplinePoint() {}
~VSplinePoint();
VPointF P() const;
void SetP(const VPointF &value);
qreal Angle1() const;
@ -55,102 +58,9 @@ public:
qreal KAsm2() const;
void SetKAsm2(const qreal &value);
protected:
/** @brief pSpline point. */
VPointF pSpline;
/** @brief angle1 first angle spline. */
qreal angle1;
/** @brief angle2 second angle spline. */
qreal angle2;
/** @brief kAsm1 coefficient of length first control line. */
qreal kAsm1;
/** @brief kAsm2 coefficient of length second control line. */
qreal kAsm2;
QSharedDataPointer<VSplinePointData> d;
};
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief P return point.
* @return point.
*/
inline VPointF VSplinePoint::P() const
{
return pSpline;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetP set point.
* @param value point.
*/
inline void VSplinePoint::SetP(const VPointF &value)
{
pSpline = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Angle1 return first angle of spline.
* @return angle.
*/
inline qreal VSplinePoint::Angle1() const
{
return angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief Angle2 return second angle of spline.
* @return angle.
*/
inline qreal VSplinePoint::Angle2() const
{
return angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief KAsm1 return coefficient of length first control line.
* @return coefficient.
*/
inline qreal VSplinePoint::KAsm1() const
{
return kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm1 set coefficient of length first control line.
* @param value coefficient.
*/
inline void VSplinePoint::SetKAsm1(const qreal &value)
{
kAsm1 = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief KAsm2 return coefficient of length second control line.
* @return coefficient.
*/
inline qreal VSplinePoint::KAsm2() const
{
return kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SetKAsm2 set coefficient of length second control line.
* @param value coefficient.
*/
inline void VSplinePoint::SetKAsm2(const qreal &value)
{
kAsm2 = value;
}
Q_DECLARE_METATYPE(VSplinePoint)
#endif // VSPLINEPOINT_H

View file

@ -0,0 +1,79 @@
/************************************************************************
**
** @file vsplinepoint_p.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 20 8, 2014
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2014 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VSPLINEPOINT_P_H
#define VSPLINEPOINT_P_H
#include <QSharedData>
#include "../options.h"
#include "vpointf.h"
class VSplinePointData : public QSharedData
{
public:
VSplinePointData()
:pSpline(VPointF()), angle1(0), angle2(180), kAsm1(1), kAsm2(1)
{}
VSplinePointData(VPointF pSpline, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2)
:pSpline(pSpline), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2)
{
if (qFuzzyCompare(qAbs(angle1-angle2), 180) == false)
{
qWarning()<<"angle1 and angle2 are not equal.";
this->angle1 = angle1;
this->angle2 = angle1 + 180;
}
}
VSplinePointData(const VSplinePointData &point)
:QSharedData(point), pSpline(point.pSpline), angle1(point.angle1), angle2(point.angle2), kAsm1(point.kAsm1),
kAsm2(point.kAsm2)
{}
virtual ~VSplinePointData() {}
/** @brief pSpline point. */
VPointF pSpline;
/** @brief angle1 first angle spline. */
qreal angle1;
/** @brief angle2 second angle spline. */
qreal angle2;
/** @brief kAsm1 coefficient of length first control line. */
qreal kAsm1;
/** @brief kAsm2 coefficient of length second control line. */
qreal kAsm2;
};
#endif // VSPLINEPOINT_P_H