Fixed GetLength method in VEllipticalArc
--HG-- branch : feature
This commit is contained in:
parent
c587826a56
commit
894ad4ea66
|
@ -124,27 +124,25 @@ VEllipticalArc::~VEllipticalArc()
|
||||||
*/
|
*/
|
||||||
qreal VEllipticalArc::GetLength() const
|
qreal VEllipticalArc::GetLength() const
|
||||||
{
|
{
|
||||||
QPointF firstPoint;
|
qreal length = 0;
|
||||||
QPointF point2;
|
|
||||||
QPointF point3;
|
|
||||||
QPointF lastPoint;
|
|
||||||
|
|
||||||
if (not d->isFlipped)
|
QVector<qreal> sectionAngle = GetAngles();
|
||||||
|
|
||||||
|
for (int i = 0; i < sectionAngle.size()-1; ++i)
|
||||||
{
|
{
|
||||||
firstPoint = GetP1();
|
QPointF firstPoint = GetPoint(sectionAngle.at(i));
|
||||||
point2 = GetPoint((2*GetStartAngle() + GetEndAngle())/3);
|
QPointF point2 = GetPoint((2*sectionAngle.at(i) + sectionAngle.at(i+1))/3);
|
||||||
point3 = GetPoint((GetStartAngle() + 2*GetEndAngle())/3);
|
QPointF point3 = GetPoint((sectionAngle.at(i) + 2*sectionAngle.at(i+1))/3);
|
||||||
lastPoint = GetP2();
|
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);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
firstPoint = GetP2();
|
|
||||||
point2 = GetPoint((2*GetEndAngle() + GetStartAngle())/3);
|
|
||||||
point3 = GetPoint((GetEndAngle() + 2*GetStartAngle())/3);
|
|
||||||
lastPoint = GetP1();
|
|
||||||
}
|
|
||||||
VSpline spl(VPointF(firstPoint), point2, point3, VPointF(lastPoint), 1.0);
|
|
||||||
qreal length = spl.GetLength();
|
|
||||||
|
|
||||||
if (d->isFlipped)
|
if (d->isFlipped)
|
||||||
{
|
{
|
||||||
|
@ -222,24 +220,19 @@ qreal VEllipticalArc::AngleArc() const
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief GetPoints return list of points needed for drawing arc.
|
* @brief GetAngles return list of angles needed for drawing arc.
|
||||||
* @return list of points
|
* @return list of angles
|
||||||
*/
|
*/
|
||||||
QVector<QPointF> VEllipticalArc::GetPoints() const
|
QVector<qreal> VEllipticalArc::GetAngles() const
|
||||||
{
|
{
|
||||||
QVector<QPointF> points;
|
|
||||||
QVector<qreal> sectionAngle;
|
QVector<qreal> sectionAngle;
|
||||||
|
|
||||||
QPointF pStart;
|
|
||||||
d->isFlipped ? pStart = GetP2() : pStart = GetP1();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
qreal angle = AngleArc();
|
qreal angle = AngleArc();
|
||||||
|
|
||||||
if (qFuzzyIsNull(angle))
|
if (qFuzzyIsNull(angle))
|
||||||
{
|
{// Return the array that includes one angle
|
||||||
points.append(pStart);
|
sectionAngle.append(d->f1);
|
||||||
return points;
|
return sectionAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (angle > 360 || angle < 0)
|
if (angle > 360 || angle < 0)
|
||||||
|
@ -262,7 +255,30 @@ QVector<QPointF> VEllipticalArc::GetPoints() const
|
||||||
sectionAngle.append(tail);
|
sectionAngle.append(tail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < sectionAngle.size(); ++i)
|
return sectionAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief GetPoints return list of points needed for drawing arc.
|
||||||
|
* @return list of points
|
||||||
|
*/
|
||||||
|
QVector<QPointF> VEllipticalArc::GetPoints() const
|
||||||
|
{
|
||||||
|
QVector<QPointF> points;
|
||||||
|
QVector<qreal> sectionAngle = GetAngles();
|
||||||
|
|
||||||
|
QPointF pStart;
|
||||||
|
d->isFlipped ? pStart = GetP2() : pStart = GetP1();
|
||||||
|
|
||||||
|
// if angle1 == angle2 and we have just one point of arc
|
||||||
|
if(sectionAngle.size() == 1)
|
||||||
|
{
|
||||||
|
points.append(GetP1());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < sectionAngle.size()-1; ++i)
|
||||||
{
|
{
|
||||||
QPointF firstPoint = GetPoint(sectionAngle.at(i));
|
QPointF firstPoint = GetPoint(sectionAngle.at(i));
|
||||||
QPointF point2 = GetPoint((2*sectionAngle.at(i) + sectionAngle.at(i+1))/3);
|
QPointF point2 = GetPoint((2*sectionAngle.at(i) + sectionAngle.at(i+1))/3);
|
||||||
|
@ -279,6 +295,8 @@ QVector<QPointF> VEllipticalArc::GetPoints() const
|
||||||
}
|
}
|
||||||
points << splPoints;
|
points << splPoints;
|
||||||
}
|
}
|
||||||
|
points << splPoints;
|
||||||
|
}
|
||||||
// we ignore the rotation of ellipse.
|
// we ignore the rotation of ellipse.
|
||||||
return points;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user