2013-11-15 13:41:26 +01:00
|
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
|
** @file vspline.h
|
2013-11-15 13:41:26 +01:00
|
|
|
|
** @author Roman Telezhinsky <dismine@gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
** @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) 2013 Valentina project
|
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
|
** 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.
|
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
|
** 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/>.
|
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
|
2013-08-05 10:37:56 +02:00
|
|
|
|
#ifndef VSPLINE_H
|
|
|
|
|
#define VSPLINE_H
|
|
|
|
|
|
2013-12-29 17:48:57 +01:00
|
|
|
|
#include "vpointf.h"
|
|
|
|
|
#include "vgobject.h"
|
2013-08-05 10:37:56 +02:00
|
|
|
|
|
2013-11-21 13:05:26 +01:00
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QLineF>
|
|
|
|
|
#include <QPainterPath>
|
|
|
|
|
|
2013-11-12 13:48:45 +01:00
|
|
|
|
class QString;
|
|
|
|
|
|
2013-10-26 22:42:54 +02:00
|
|
|
|
#define M_2PI 6.28318530717958647692528676655900576
|
2013-08-05 10:37:56 +02:00
|
|
|
|
|
|
|
|
|
/**
|
2013-12-18 12:13:32 +01:00
|
|
|
|
* @brief VSpline class that implements the spline.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
class VSpline :public VGObject
|
2013-11-04 21:35:15 +01:00
|
|
|
|
{
|
2013-08-05 10:37:56 +02:00
|
|
|
|
public:
|
2013-12-18 12:13:32 +01:00
|
|
|
|
/**
|
|
|
|
|
* @brief VSpline default constructor
|
|
|
|
|
*/
|
|
|
|
|
VSpline();
|
|
|
|
|
/**
|
|
|
|
|
* @brief VSpline constructor.
|
|
|
|
|
* @param spline spline from which the copy.
|
|
|
|
|
*/
|
|
|
|
|
VSpline (const VSpline &spline );
|
|
|
|
|
/**
|
|
|
|
|
* @brief VSpline constructor.
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @param p1 first point spline.
|
|
|
|
|
* @param p4 last point spline.
|
|
|
|
|
* @param angle1 angle from first point to first control point.
|
|
|
|
|
* @param angle2 angle from second point to second control point.
|
|
|
|
|
* @param kCurve coefficient of curvature spline.
|
|
|
|
|
* @param kAsm1 coefficient of length first control line.
|
|
|
|
|
* @param kAsm2 coefficient of length second control line.
|
2013-12-18 12:13:32 +01:00
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
VSpline (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve,
|
2014-02-25 15:40:24 +01:00
|
|
|
|
quint32 idObject = 0, Draw::Draws mode = Draw::Calculation);
|
2013-12-18 12:13:32 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief VSpline constructor.
|
|
|
|
|
* @param p1 first point spline.
|
|
|
|
|
* @param p2 first control point.
|
|
|
|
|
* @param p3 second control point.
|
|
|
|
|
* @param p4 second point spline.
|
2013-12-18 12:13:32 +01:00
|
|
|
|
*/
|
2014-02-25 15:40:24 +01:00
|
|
|
|
VSpline (VPointF p1, QPointF p2, QPointF p3, VPointF p4, qreal kCurve, quint32 idObject = 0,
|
2013-12-29 17:48:57 +01:00
|
|
|
|
Draw::Draws mode = Draw::Calculation);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetP1 return first spline point.
|
|
|
|
|
* @return first point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
VPointF GetP1 () const {return p1;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetP2 return first control point.
|
|
|
|
|
* @return first control point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline QPointF GetP2 () const {return p2;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetP3 return second control point.
|
|
|
|
|
* @return second control point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline QPointF GetP3 () const {return p3;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetP4 return last spline point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
* @return остання точка сплайну.
|
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
inline VPointF GetP4 () const {return p4;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetAngle1 return first angle control line.
|
|
|
|
|
* @return angle.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline qreal GetAngle1 () const {return angle1;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetAngle2 return second angle control line.
|
|
|
|
|
* @return angle.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline qreal GetAngle2() const {return angle2;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetLength return length of spline.
|
|
|
|
|
* @return length.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
qreal GetLength () const;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief name return spline name. Used for variables.
|
|
|
|
|
* @return name.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
QString name () const;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetKasm1 return coefficient of length first control line.
|
|
|
|
|
* @return coefficient.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline qreal GetKasm1() const {return kAsm1;}
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetKasm2 return coefficient of length second control line.
|
|
|
|
|
* @return coefficient.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline qreal GetKasm2() const {return kAsm2;}
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetKcurve return coefficient of curvature spline.
|
|
|
|
|
* @return coefficient
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
inline qreal GetKcurve() const {return kCurve;}
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief CrossingSplLine check intersection spline with line.
|
|
|
|
|
* @param line line.
|
|
|
|
|
* @param intersectionPoint intersection point.
|
|
|
|
|
* @return result intersection.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
|
|
|
|
QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const;
|
2013-12-18 12:13:32 +01:00
|
|
|
|
qreal LengthT(qreal t) const;
|
|
|
|
|
/**
|
|
|
|
|
* @brief CutSpline cut spline. GetPointP1() of base spline will return first point for first spline, GetPointP4()
|
|
|
|
|
* of base spline will return forth point of second spline.
|
|
|
|
|
* @param length length first spline
|
|
|
|
|
* @param spl1p2 second point of first spline
|
|
|
|
|
* @param spl1p3 third point of first spline
|
|
|
|
|
* @param spl2p2 second point of second spline
|
|
|
|
|
* @param spl2p3 third point of second spline
|
|
|
|
|
* @return point of cutting. This point is forth point of first spline and first point of second spline.
|
|
|
|
|
*/
|
|
|
|
|
QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetPoints return list with spline points.
|
|
|
|
|
* @return list of points.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
|
|
|
|
QVector<QPointF> GetPoints () const;
|
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetPath return QPainterPath for this spline.
|
|
|
|
|
* @return path.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
QPainterPath GetPath() const;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief SplinePoints return list with spline points.
|
|
|
|
|
* @param p1 first spline point.
|
|
|
|
|
* @param p4 last spline point.
|
|
|
|
|
* @param angle1 angle from first point to first control point.
|
|
|
|
|
* @param angle2 angle from second point to second control point.
|
|
|
|
|
* @param kAsm1 coefficient of length first control line.
|
|
|
|
|
* @param kAsm2 coefficient of length second control line.
|
|
|
|
|
* @param kCurve coefficient of curvature spline.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
* @return
|
|
|
|
|
*/
|
2013-11-07 15:40:39 +01:00
|
|
|
|
static QVector<QPointF> SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1,
|
|
|
|
|
qreal kAsm2, qreal kCurve);
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief operator = assignmeant operator
|
|
|
|
|
* @param spl spline
|
|
|
|
|
* @return spline
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
VSpline &operator=(const VSpline &spl);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
protected:
|
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief GetPoints return list with spline points.
|
|
|
|
|
* @param p1 first spline point.
|
|
|
|
|
* @param p2 first control point.
|
|
|
|
|
* @param p3 second control point.
|
|
|
|
|
* @param p4 last spline point.
|
|
|
|
|
* @return list of points.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-11-07 15:40:39 +01:00
|
|
|
|
static QVector<QPointF> GetPoints (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 );
|
2013-08-05 10:37:56 +02:00
|
|
|
|
private:
|
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief p1 first spline point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
VPointF p1;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief p2 first control point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
QPointF p2;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief p3 second control point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
QPointF p3;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief p4 last spline point.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
VPointF p4;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief angle1 first angle control line.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
qreal angle1;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief angle2 second angle control line.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2014-01-21 18:18:05 +01:00
|
|
|
|
qreal angle2;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief kAsm1 coefficient of length first control line.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
qreal kAsm1;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief kAsm2 coefficient of length second control line.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
qreal kAsm2;
|
2013-11-19 21:56:49 +01:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief kCurve coefficient of curvature spline.
|
2013-11-19 21:56:49 +01:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
qreal kCurve;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief LengthBezier return spline length using 4 spline point.
|
|
|
|
|
* @param p1 first spline point
|
|
|
|
|
* @param p2 first control point.
|
|
|
|
|
* @param p3 second control point.
|
|
|
|
|
* @param p4 last spline point.
|
|
|
|
|
* @return length.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-11-07 15:40:39 +01:00
|
|
|
|
qreal LengthBezier (const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4 ) const;
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief PointBezier_r find spline point using four point of spline.
|
|
|
|
|
* @param x1 х coordinate first point.
|
|
|
|
|
* @param y1 у coordinate first point.
|
|
|
|
|
* @param x2 х coordinate first control point.
|
|
|
|
|
* @param y2 у coordinate first control point.
|
|
|
|
|
* @param x3 х coordinate second control point.
|
|
|
|
|
* @param y3 у coordinate second control point.
|
|
|
|
|
* @param x4 х coordinate last point.
|
|
|
|
|
* @param y4 у coordinate last point.
|
|
|
|
|
* @param level level of recursion. In the begin 0.
|
|
|
|
|
* @param px list х coordinat spline points.
|
|
|
|
|
* @param py list у coordinat spline points.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
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);
|
2013-08-05 10:37:56 +02:00
|
|
|
|
/**
|
2014-01-21 18:18:05 +01:00
|
|
|
|
* @brief CalcSqDistance calculate squared distance.
|
|
|
|
|
* @param x1 х coordinate first point.
|
|
|
|
|
* @param y1 у coordinate first point.
|
|
|
|
|
* @param x2 х coordinate second point.
|
|
|
|
|
* @param y2 у coordinate second point.
|
|
|
|
|
* @return squared length.
|
2013-08-05 10:37:56 +02:00
|
|
|
|
*/
|
2013-10-26 22:42:54 +02:00
|
|
|
|
static qreal CalcSqDistance ( qreal x1, qreal y1, qreal x2, qreal y2);
|
2014-01-21 18:18:05 +01:00
|
|
|
|
/**
|
|
|
|
|
* @brief CreateName create spline name.
|
|
|
|
|
*/
|
2013-12-29 17:48:57 +01:00
|
|
|
|
void CreateName();
|
2013-08-05 10:37:56 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // VSPLINE_H
|