Implicit Sharing for class VSpline.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-20 16:02:41 +03:00
parent 7a8ba8f707
commit 40eab84c41
4 changed files with 222 additions and 174 deletions

View File

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

View File

@ -27,6 +27,7 @@
*************************************************************************/ *************************************************************************/
#include "vspline.h" #include "vspline.h"
#include "vspline_p.h"
#include <QDebug> #include <QDebug>
#include <QPainterPath> #include <QPainterPath>
@ -39,8 +40,7 @@
* @brief VSpline default constructor * @brief VSpline default constructor
*/ */
VSpline::VSpline() VSpline::VSpline()
:VAbstractCurve(GOType::Spline), p1(VPointF()), p2(QPointF()), p3(QPointF()), p4(VPointF()), angle1(0), angle2(0), :VAbstractCurve(GOType::Spline), d(new VSplineData)
kAsm1(1), kAsm2(1), kCurve(1)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -49,9 +49,7 @@ VSpline::VSpline()
* @param spline spline from which the copy. * @param spline spline from which the copy.
*/ */
VSpline::VSpline ( const VSpline & spline ) VSpline::VSpline ( const VSpline & spline )
:VAbstractCurve(spline), p1(spline.GetP1 ()), p2(spline.GetP2 ()), p3(spline.GetP3 ()), p4(spline.GetP4 ()), :VAbstractCurve(spline), d(spline.d)
angle1(spline.GetAngle1 ()), angle2(spline.GetAngle2 ()), kAsm1(spline.GetKasm1()), kAsm2(spline.GetKasm2()),
kCurve(spline.GetKcurve())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -67,30 +65,9 @@ VSpline::VSpline ( const VSpline & spline )
*/ */
VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve, VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
quint32 idObject, Draw mode) quint32 idObject, Draw mode)
:VAbstractCurve(GOType::Spline, idObject, mode), p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), :VAbstractCurve(GOType::Spline, idObject, mode), d(new VSplineData(p1, p4, angle1, angle2, kAsm1, kAsm2, kCurve))
angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2), kCurve(kCurve)
{ {
CreateName(); CreateName();
this->p1 = p1;
this->p4 = p4;
this->angle1 = angle1;
this->angle2 = angle2;
this->kAsm1 = kAsm1;
this->kAsm2 = kAsm2;
this->kCurve = kCurve;
qreal L = 0, radius = 0, angle = 90;
QPointF point1 = GetP1().toQPointF();
QPointF point4 = GetP4().toQPointF();
radius = QLineF(point1, point4).length()/1.414213;//1.414213=sqrt(2);
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
QLineF p1p2(GetP1().x(), GetP1().y(), GetP1().x() + L * kAsm1, GetP1().y());
p1p2.setAngle(angle1);
QLineF p4p3(GetP4().x(), GetP4().y(), GetP4().x() + L * kAsm2, GetP4().y());
p4p3.setAngle(angle2);
this->p2 = p1p2.p2();
this->p3 = p4p3.p2();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -102,29 +79,16 @@ VSpline::VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm
* @param p4 second point spline. * @param p4 second point spline.
*/ */
VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject, Draw mode) VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject, Draw mode)
:VAbstractCurve(GOType::Spline, idObject, mode), p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), :VAbstractCurve(GOType::Spline, idObject, mode), d(new VSplineData(p1, p2, p3, p4, kCurve))
kAsm2(1), kCurve(1)
{ {
CreateName(); CreateName();
this->p1 = p1;
this->p2 = p2;
this->p3 = p3;
this->p4 = p4;
this->angle1 = QLineF ( GetP1().toQPointF(), p2 ).angle();
this->angle2 = QLineF ( GetP4().toQPointF(), p3 ).angle();
qreal L = 0, radius = 0, angle = 90;
QPointF point1 = GetP1().toQPointF();
QPointF point4 = GetP4().toQPointF();
radius = QLineF(point1, point4).length()/1.414213;//1.414213=sqrt(2);
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
this->kCurve = kCurve;
this->kAsm1 = QLineF ( GetP1().toQPointF(), p2 ).length()/L;
this->kAsm2 = QLineF ( GetP4().toQPointF(), p3 ).length()/L;
} }
//---------------------------------------------------------------------------------------------------------------------
VSpline::~VSpline()
{}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief GetLength return length of spline. * @brief GetLength return length of spline.
@ -132,7 +96,7 @@ VSpline::VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve,
*/ */
qreal VSpline::GetLength () const qreal VSpline::GetLength () const
{ {
return LengthBezier ( GetP1().toQPointF(), this->p2, this->p3, GetP4().toQPointF()); return LengthBezier ( GetP1().toQPointF(), d->p2, d->p3, GetP4().toQPointF());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -284,7 +248,7 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo
*/ */
QVector<QPointF> VSpline::GetPoints () const QVector<QPointF> VSpline::GetPoints () const
{ {
return GetPoints(GetP1().toQPointF(), p2, p3, GetP4().toQPointF()); return GetPoints(GetP1().toQPointF(), d->p2, d->p3, GetP4().toQPointF());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -693,14 +657,96 @@ VSpline &VSpline::operator =(const VSpline &spline)
return *this; return *this;
} }
VAbstractCurve::operator=(spline); VAbstractCurve::operator=(spline);
this->p1 = spline.GetP1 (); d = spline.d;
this->p2 = spline.GetP2 ();
this->p3 = spline.GetP3 ();
this->p4 = spline.GetP4 ();
this->angle1 = spline.GetAngle1 ();
this->angle2 = spline.GetAngle2 ();
this->kAsm1 = spline.GetKasm1();
this->kAsm2 = spline.GetKasm2();
this->kCurve = spline.GetKcurve();
return *this; return *this;
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP1 return first spline point.
* @return first point.
*/
VPointF VSpline::GetP1() const
{
return d->p1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP2 return first control point.
* @return first control point.
*/
QPointF VSpline::GetP2() const
{
return d->p2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP3 return second control point.
* @return second control point.
*/
QPointF VSpline::GetP3() const
{
return d->p3;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP4 return last spline point.
* @return остання точка сплайну.
*/
VPointF VSpline::GetP4() const
{
return d->p4;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle1 return first angle control line.
* @return angle.
*/
qreal VSpline::GetAngle1() const
{
return d->angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle2 return second angle control line.
* @return angle.
*/
qreal VSpline::GetAngle2() const
{
return d->angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKasm1 return coefficient of length first control line.
* @return coefficient.
*/
qreal VSpline::GetKasm1() const
{
return d->kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKasm2 return coefficient of length second control line.
* @return coefficient.
*/
qreal VSpline::GetKasm2() const
{
return d->kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKcurve return coefficient of curvature spline.
* @return coefficient
*/
qreal VSpline::GetKcurve() const
{
return d->kCurve;
}

View File

@ -35,6 +35,7 @@
#include <QPointF> #include <QPointF>
class QPainterPath; class QPainterPath;
class VSplineData;
#define M_2PI 6.28318530717958647692528676655900576 #define M_2PI 6.28318530717958647692528676655900576
@ -50,6 +51,7 @@ public:
quint32 idObject = 0, Draw mode = Draw::Calculation); quint32 idObject = 0, Draw mode = Draw::Calculation);
VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject = 0, VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject = 0,
Draw mode = Draw::Calculation); Draw mode = Draw::Calculation);
virtual ~VSpline();
VSpline &operator=(const VSpline &spl); VSpline &operator=(const VSpline &spl);
VPointF GetP1 () const; VPointF GetP1 () const;
QPointF GetP2 () const; QPointF GetP2 () const;
@ -72,32 +74,7 @@ public:
protected: protected:
static QVector<QPointF> GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ); static QVector<QPointF> GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 );
private: private:
/** @brief p1 first spline point. */ QSharedDataPointer<VSplineData> d;
VPointF p1;
/** @brief p2 first control point. */
QPointF p2;
/** @brief p3 second control point. */
QPointF p3;
/** @brief p4 last spline point. */
VPointF p4;
/** @brief angle1 first angle control line. */
qreal angle1;
/** @brief angle2 second angle control line. */
qreal angle2;
/** @brief kAsm1 coefficient of length first control line. */
qreal kAsm1;
/** @brief kAsm2 coefficient of length second control line. */
qreal kAsm2;
/** @brief kCurve coefficient of curvature spline. */
qreal kCurve;
qreal LengthBezier (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ) const; qreal LengthBezier (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ) const;
static void PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4, static void PointBezier_r ( qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4,
qint16 level, QVector<qreal> &px, QVector<qreal> &py); qint16 level, QVector<qreal> &px, QVector<qreal> &py);
@ -105,94 +82,4 @@ private:
void CreateName(); void CreateName();
}; };
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP1 return first spline point.
* @return first point.
*/
inline VPointF VSpline::GetP1() const
{
return p1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP2 return first control point.
* @return first control point.
*/
inline QPointF VSpline::GetP2() const
{
return p2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP3 return second control point.
* @return second control point.
*/
inline QPointF VSpline::GetP3() const
{
return p3;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetP4 return last spline point.
* @return остання точка сплайну.
*/
inline VPointF VSpline::GetP4() const
{
return p4;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle1 return first angle control line.
* @return angle.
*/
inline qreal VSpline::GetAngle1() const
{
return angle1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngle2 return second angle control line.
* @return angle.
*/
inline qreal VSpline::GetAngle2() const
{
return angle2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKasm1 return coefficient of length first control line.
* @return coefficient.
*/
inline qreal VSpline::GetKasm1() const
{
return kAsm1;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKasm2 return coefficient of length second control line.
* @return coefficient.
*/
inline qreal VSpline::GetKasm2() const
{
return kAsm2;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetKcurve return coefficient of curvature spline.
* @return coefficient
*/
inline qreal VSpline::GetKcurve() const
{
return kCurve;
}
#endif // VSPLINE_H #endif // VSPLINE_H

View File

@ -0,0 +1,114 @@
/************************************************************************
**
** @file vspline_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 VSPLINE_P_H
#define VSPLINE_P_H
#include <QSharedData>
#include "../options.h"
#include "vpointf.h"
#include <QLineF>
class VSplineData : public QSharedData
{
public:
VSplineData()
:p1(VPointF()), p2(QPointF()), p3(QPointF()), p4(VPointF()), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
{}
VSplineData ( const VSplineData &spline )
:QSharedData(spline), p1(spline.p1), p2(spline.p2), p3(spline.p3), p4(spline.p4), angle1(spline.angle1),
angle2(spline.angle2), kAsm1(spline.angle2), kAsm2(spline.kAsm1), kCurve(spline.kCurve)
{}
VSplineData (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve)
:p1(p1), p2(QPointF()), p3(QPointF()), p4(p4), angle1(angle1), angle2(angle2), kAsm1(kAsm1), kAsm2(kAsm2),
kCurve(kCurve)
{
qreal L = 0, radius = 0, angle = 90;
QPointF point1 = this->p1.toQPointF();
QPointF point4 = this->p4.toQPointF();
radius = QLineF(point1, point4).length()/1.414213;//1.414213=sqrt(2);
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
QLineF p1p2(this->p1.x(), this->p1.y(), this->p1.x() + L * kAsm1, this->p1.y());
p1p2.setAngle(angle1);
QLineF p4p3(this->p4.x(), this->p4.y(), this->p4.x() + L * kAsm2, this->p4.y());
p4p3.setAngle(angle2);
this->p2 = p1p2.p2();
this->p3 = p4p3.p2();
}
VSplineData (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve)
:p1(p1), p2(p2), p3(p3), p4(p4), angle1(0), angle2(0), kAsm1(1), kAsm2(1), kCurve(1)
{
this->angle1 = QLineF ( this->p1.toQPointF(), this->p2 ).angle();
this->angle2 = QLineF ( this->p4.toQPointF(), this->p3 ).angle();
qreal L = 0, radius = 0, angle = 90;
QPointF point1 = this->p1.toQPointF();
QPointF point4 = this->p4.toQPointF();
radius = QLineF(point1, point4).length()/1.414213;//1.414213=sqrt(2);
L = kCurve * radius * 4 / 3 * tan( angle * M_PI / 180.0 / 4 );
this->kCurve = kCurve;
this->kAsm1 = QLineF ( this->p1.toQPointF(), this->p2 ).length()/L;
this->kAsm2 = QLineF ( this->p4.toQPointF(), this->p3 ).length()/L;
}
virtual ~VSplineData() {}
/** @brief p1 first spline point. */
VPointF p1;
/** @brief p2 first control point. */
QPointF p2;
/** @brief p3 second control point. */
QPointF p3;
/** @brief p4 last spline point. */
VPointF p4;
/** @brief angle1 first angle control line. */
qreal angle1;
/** @brief angle2 second angle control line. */
qreal angle2;
/** @brief kAsm1 coefficient of length first control line. */
qreal kAsm1;
/** @brief kAsm2 coefficient of length second control line. */
qreal kAsm2;
/** @brief kCurve coefficient of curvature spline. */
qreal kCurve;
};
#endif // VSPLINE_P_H