Fixed GetLength and changed the rotation of point

--HG--
branch : feature
This commit is contained in:
Valentina Zhuravska 2016-02-12 22:02:54 +02:00
parent 560a3dc1d1
commit 37eb0e9e21
4 changed files with 51 additions and 63 deletions

View File

@ -146,7 +146,7 @@ extern const QString ColorYellow;
// Hacks for avoiding the linker error "undefined reference to"
#define SPL_ "Spl_"
#define ARC_ "Arc_"
#define EARC_ "EllipticalArc_"
#define EARC_ "ElArc_"
extern const QString line_;
extern const QString angleLine_;

View File

@ -32,6 +32,7 @@
#include "../ifc/ifcdef.h"
#include <QtCore/qmath.h>
#include <QLineF>
#include <QPainterPath>
//---------------------------------------------------------------------------------------------------------------------
/**
@ -124,25 +125,15 @@ VEllipticalArc::~VEllipticalArc()
*/
qreal VEllipticalArc::GetLength() const
{
qreal length = 0;
QVector<qreal> sectionAngle = GetAngles();
for (int i = 0; i < sectionAngle.size()-1; ++i)
qreal length;
QPainterPath elArc;
QVector<QPointF> points = GetPoints();
elArc.moveTo(points.at(0));
for (qint32 i = 1; i < points.count(); ++i)
{
QPointF firstPoint = GetPoint(sectionAngle.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);
elArc.lineTo(points.at(i));
}
length = elArc.length();
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)),
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f1*M_PI/180)));
// rotation of point
QPointF pointRotation;
pointRotation.setX(p1.rx()*qCos(GetRotationAngle()) - p1.ry()*qSin(GetRotationAngle()));
pointRotation.setY(p1.rx()*qSin(GetRotationAngle()) + p1.ry()*qCos(GetRotationAngle()));
QLineF line(GetCenter().toQPointF(), p1);
line.setAngle(line.angle() + 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)),
GetCenter().y () + qFloor((d->radius1 + d->radius2)*sin(d->f2*M_PI/180)));
// rotation of point
QPointF pointRotation;
pointRotation.setX(p2.rx()*qCos(GetRotationAngle()) - p2.ry()*qSin(GetRotationAngle()));
pointRotation.setY(p2.rx()*qSin(GetRotationAngle()) + p2.ry()*qCos(GetRotationAngle()));
QLineF line(GetCenter().toQPointF(), p2);
line.setAngle(line.angle() + GetRotationAngle());
return pointRotation;
return line.p2();
}
//---------------------------------------------------------------------------------------------------------------------
@ -198,13 +187,11 @@ QPointF VEllipticalArc::GetPoint (qreal angle) const
// p - point without rotation
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)));
// rotation of point
QPointF pointRotation;
pointRotation.setX(p.rx()*qCos(GetRotationAngle()) - p.ry()*qSin(GetRotationAngle()));
pointRotation.setY(p.rx()*qSin(GetRotationAngle()) + p.ry()*qCos(GetRotationAngle()));
QLineF line(GetCenter().toQPointF(), p);
line.setAngle(line.angle() + GetRotationAngle());
return pointRotation;
return line.p2();
}
//---------------------------------------------------------------------------------------------------------------------
@ -233,6 +220,7 @@ qreal VEllipticalArc::AngleArc() const
return ang;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetAngles return list of angles needed for drawing arc.
@ -241,34 +229,32 @@ qreal VEllipticalArc::AngleArc() const
QVector<qreal> VEllipticalArc::GetAngles() const
{
QVector<qreal> sectionAngle;
qreal angle = AngleArc();
if (qFuzzyIsNull(angle))
{// Return the array that includes one angle
sectionAngle.append(d->f1);
return sectionAngle;
}
if (angle > 360 || angle < 0)
{// Filter incorect value of angle
QLineF dummy(0,0, 100, 0);
dummy.setAngle(angle);
angle = dummy.angle();
}
const qreal angleInterpolation = 45; //degree
const int sections = qFloor(angle / angleInterpolation);
for (int i = 0; i < sections; ++i)
{
qreal angle = AngleArc();
sectionAngle.append(angleInterpolation);
}
if (qFuzzyIsNull(angle))
{// Return the array that includes one angle
sectionAngle.append(d->f1);
return sectionAngle;
}
if (angle > 360 || angle < 0)
{// Filter incorect value of angle
QLineF dummy(0,0, 100, 0);
dummy.setAngle(angle);
angle = dummy.angle();
}
const qreal angleInterpolation = 45; //degree
const int sections = qFloor(angle / angleInterpolation);
for (int i = 0; i < sections; ++i)
{
sectionAngle.append(angleInterpolation);
}
const qreal tail = angle - sections * angleInterpolation;
if (tail > 0)
{
sectionAngle.append(tail);
}
const qreal tail = angle - sections * angleInterpolation;
if (tail > 0)
{
sectionAngle.append(tail);
}
return sectionAngle;
}

View File

@ -68,10 +68,11 @@ public:
qreal GetRotationAngle() const;
QString GetFormulaRadius1 () const;
QString GetFormulaRadius2 () const;
void SetFormulaRadius1 (const QString &formula, qreal value);
void SetFormulaRadius2 (const QString &formula, qreal value);
qreal GetRadius1 () const;
QString GetFormulaRadius2 () const;
void SetFormulaRadius2 (const QString &formula, qreal value);
qreal GetRadius2 () const;
VPointF GetCenter () const;
@ -83,7 +84,7 @@ public:
QPointF GetP1() const;
QPointF GetP2 () const;
QPointF GetPoint (qreal angle) const;
qreal AngleArc() const;
QVector<qreal> GetAngles () const;
QVector<QPointF> GetPoints () const;
@ -97,6 +98,7 @@ private:
void FindF2(qreal length);
qreal MaxLength() const;
QPointF GetPoint (qreal angle) const;
};
Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE);

View File

@ -9,7 +9,7 @@ SOURCES += \
$$PWD/vspline.cpp \
$$PWD/vsplinepath.cpp \
$$PWD/vsplinepoint.cpp \
$$PWD/vellipticalarc.cpp
$$PWD/vellipticalarc.cpp
win32-msvc*:SOURCES += $$PWD/stable.cpp
@ -29,5 +29,5 @@ HEADERS += \
$$PWD/vsplinepoint.h \
$$PWD/vsplinepoint_p.h \
$$PWD/vgeometrydef.h \
$$PWD/vellipticalarc.h \
$$PWD/vellipticalarc_p.h
$$PWD/vellipticalarc.h \
$$PWD/vellipticalarc_p.h