Fixed GetLength and changed the rotation of point
--HG-- branch : feature
This commit is contained in:
parent
560a3dc1d1
commit
37eb0e9e21
|
@ -146,7 +146,7 @@ extern const QString ColorYellow;
|
||||||
// Hacks for avoiding the linker error "undefined reference to"
|
// Hacks for avoiding the linker error "undefined reference to"
|
||||||
#define SPL_ "Spl_"
|
#define SPL_ "Spl_"
|
||||||
#define ARC_ "Arc_"
|
#define ARC_ "Arc_"
|
||||||
#define EARC_ "EllipticalArc_"
|
#define EARC_ "ElArc_"
|
||||||
|
|
||||||
extern const QString line_;
|
extern const QString line_;
|
||||||
extern const QString angleLine_;
|
extern const QString angleLine_;
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "../ifc/ifcdef.h"
|
#include "../ifc/ifcdef.h"
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
#include <QLineF>
|
#include <QLineF>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
|
@ -124,25 +125,15 @@ VEllipticalArc::~VEllipticalArc()
|
||||||
*/
|
*/
|
||||||
qreal VEllipticalArc::GetLength() const
|
qreal VEllipticalArc::GetLength() const
|
||||||
{
|
{
|
||||||
qreal length = 0;
|
qreal length;
|
||||||
|
QPainterPath elArc;
|
||||||
QVector<qreal> sectionAngle = GetAngles();
|
QVector<QPointF> points = GetPoints();
|
||||||
|
elArc.moveTo(points.at(0));
|
||||||
for (int i = 0; i < sectionAngle.size()-1; ++i)
|
for (qint32 i = 1; i < points.count(); ++i)
|
||||||
{
|
{
|
||||||
QPointF firstPoint = GetPoint(sectionAngle.at(i));
|
elArc.lineTo(points.at(i));
|
||||||
QPointF point2 = GetPoint((2*sectionAngle.at(i) + sectionAngle.at(i+1))/3);
|
|
||||||
QPointF point3 = GetPoint((sectionAngle.at(i) + 2*sectionAngle.at(i+1))/3);
|
|
||||||
QPointF lastPoint = GetPoint(sectionAngle.at(i+1));
|
|
||||||
|
|
||||||
qreal dx1 = point2.rx() - firstPoint.rx();
|
|
||||||
qreal dy1 = point2.ry() - firstPoint.ry();
|
|
||||||
qreal dx2 = point3.rx() - point2.rx();
|
|
||||||
qreal dy2 = point3.ry() - point2.ry();
|
|
||||||
qreal dx3 = lastPoint.rx() - point3.rx();
|
|
||||||
qreal dy3 = lastPoint.ry() - point3.ry();
|
|
||||||
length += qSqrt(dx1*dx1 + dy1*dy1) + qSqrt(dx2*dx2 + dy2*dy2) + qSqrt(dx3*dx3 + dy3*dy3);
|
|
||||||
}
|
}
|
||||||
|
length = elArc.length();
|
||||||
|
|
||||||
if (d->isFlipped)
|
if (d->isFlipped)
|
||||||
{
|
{
|
||||||
|
@ -163,11 +154,10 @@ QPointF VEllipticalArc::GetP1() const
|
||||||
QPointF p1 ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(d->f1*M_PI/180)),
|
QPointF p1 ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(d->f1*M_PI/180)),
|
||||||
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f1*M_PI/180)));
|
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f1*M_PI/180)));
|
||||||
// rotation of point
|
// rotation of point
|
||||||
QPointF pointRotation;
|
QLineF line(GetCenter().toQPointF(), p1);
|
||||||
pointRotation.setX(p1.rx()*qCos(GetRotationAngle()) - p1.ry()*qSin(GetRotationAngle()));
|
line.setAngle(line.angle() + GetRotationAngle());
|
||||||
pointRotation.setY(p1.rx()*qSin(GetRotationAngle()) + p1.ry()*qCos(GetRotationAngle()));
|
|
||||||
|
|
||||||
return pointRotation;
|
return line.p2();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -181,11 +171,10 @@ QPointF VEllipticalArc::GetP2 () const
|
||||||
QPointF p2 ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(d->f2*M_PI/180)),
|
QPointF p2 ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(d->f2*M_PI/180)),
|
||||||
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f2*M_PI/180)));
|
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f2*M_PI/180)));
|
||||||
// rotation of point
|
// rotation of point
|
||||||
QPointF pointRotation;
|
QLineF line(GetCenter().toQPointF(), p2);
|
||||||
pointRotation.setX(p2.rx()*qCos(GetRotationAngle()) - p2.ry()*qSin(GetRotationAngle()));
|
line.setAngle(line.angle() + GetRotationAngle());
|
||||||
pointRotation.setY(p2.rx()*qSin(GetRotationAngle()) + p2.ry()*qCos(GetRotationAngle()));
|
|
||||||
|
|
||||||
return pointRotation;
|
return line.p2();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -198,13 +187,11 @@ QPointF VEllipticalArc::GetPoint (qreal angle) const
|
||||||
// p - point without rotation
|
// p - point without rotation
|
||||||
QPointF p ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(angle*M_PI/180)),
|
QPointF p ( GetCenter().x () + qFloor((d->radius1 + d->radius2)*cos(angle*M_PI/180)),
|
||||||
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(angle*M_PI/180)));
|
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(angle*M_PI/180)));
|
||||||
|
|
||||||
// rotation of point
|
// rotation of point
|
||||||
QPointF pointRotation;
|
QLineF line(GetCenter().toQPointF(), p);
|
||||||
pointRotation.setX(p.rx()*qCos(GetRotationAngle()) - p.ry()*qSin(GetRotationAngle()));
|
line.setAngle(line.angle() + GetRotationAngle());
|
||||||
pointRotation.setY(p.rx()*qSin(GetRotationAngle()) + p.ry()*qCos(GetRotationAngle()));
|
|
||||||
|
|
||||||
return pointRotation;
|
return line.p2();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -233,6 +220,7 @@ qreal VEllipticalArc::AngleArc() const
|
||||||
|
|
||||||
return ang;
|
return ang;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief GetAngles return list of angles needed for drawing arc.
|
* @brief GetAngles return list of angles needed for drawing arc.
|
||||||
|
@ -241,7 +229,6 @@ qreal VEllipticalArc::AngleArc() const
|
||||||
QVector<qreal> VEllipticalArc::GetAngles() const
|
QVector<qreal> VEllipticalArc::GetAngles() const
|
||||||
{
|
{
|
||||||
QVector<qreal> sectionAngle;
|
QVector<qreal> sectionAngle;
|
||||||
{
|
|
||||||
qreal angle = AngleArc();
|
qreal angle = AngleArc();
|
||||||
|
|
||||||
if (qFuzzyIsNull(angle))
|
if (qFuzzyIsNull(angle))
|
||||||
|
@ -269,7 +256,6 @@ QVector<qreal> VEllipticalArc::GetAngles() const
|
||||||
{
|
{
|
||||||
sectionAngle.append(tail);
|
sectionAngle.append(tail);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return sectionAngle;
|
return sectionAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,11 @@ public:
|
||||||
qreal GetRotationAngle() const;
|
qreal GetRotationAngle() const;
|
||||||
|
|
||||||
QString GetFormulaRadius1 () const;
|
QString GetFormulaRadius1 () const;
|
||||||
QString GetFormulaRadius2 () const;
|
|
||||||
void SetFormulaRadius1 (const QString &formula, qreal value);
|
void SetFormulaRadius1 (const QString &formula, qreal value);
|
||||||
void SetFormulaRadius2 (const QString &formula, qreal value);
|
|
||||||
qreal GetRadius1 () const;
|
qreal GetRadius1 () const;
|
||||||
|
|
||||||
|
QString GetFormulaRadius2 () const;
|
||||||
|
void SetFormulaRadius2 (const QString &formula, qreal value);
|
||||||
qreal GetRadius2 () const;
|
qreal GetRadius2 () const;
|
||||||
|
|
||||||
VPointF GetCenter () const;
|
VPointF GetCenter () const;
|
||||||
|
@ -83,7 +84,7 @@ public:
|
||||||
|
|
||||||
QPointF GetP1() const;
|
QPointF GetP1() const;
|
||||||
QPointF GetP2 () const;
|
QPointF GetP2 () const;
|
||||||
QPointF GetPoint (qreal angle) const;
|
|
||||||
qreal AngleArc() const;
|
qreal AngleArc() const;
|
||||||
QVector<qreal> GetAngles () const;
|
QVector<qreal> GetAngles () const;
|
||||||
QVector<QPointF> GetPoints () const;
|
QVector<QPointF> GetPoints () const;
|
||||||
|
@ -97,6 +98,7 @@ private:
|
||||||
void FindF2(qreal length);
|
void FindF2(qreal length);
|
||||||
|
|
||||||
qreal MaxLength() const;
|
qreal MaxLength() const;
|
||||||
|
QPointF GetPoint (qreal angle) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user