Incorrect behavior of empty arc and elliptical arc. Closes #129

This commit is contained in:
Roman Telezhynskyi 2021-05-31 12:07:28 +03:00
parent 18c804c962
commit 3ae13febd3
8 changed files with 83 additions and 2 deletions

View File

@ -1,3 +1,6 @@
# Valentina 0.7.48 (unreleased)
- [smart-pattern/valentina#129] Incorrect behavior of empty arc and elliptical arc.
# Version 0.7.47 May 13, 2021
- [smart-pattern/valentina#118] Incorrect seam allowance.
- [smart-pattern/valentina#119] Improve tool Point of intersection curves.

View File

@ -263,6 +263,11 @@ QPointF VArc::GetP2 () const
*/
QVector<QPointF> VArc::GetPoints() const
{
if (qFuzzyIsNull(GetRadius()))
{
return {GetCenter().toQPointF()};
}
QVector<QPointF> points;
QVector<qreal> sectionAngle;

View File

@ -493,12 +493,23 @@ qreal VEllipticalArc::MaxLength() const
//---------------------------------------------------------------------------------------------------------------------
QPointF VEllipticalArc::GetP(qreal angle) const
{
if (qFuzzyIsNull(GetRadius1()) && qFuzzyIsNull(GetRadius2()))
{
return GetCenter().toQPointF();
}
QLineF line(0, 0, 100, 0);
line.setAngle(angle);
const qreal a = line.p2().x() / GetRadius1();
const qreal b = line.p2().y() / GetRadius2();
const qreal a = not qFuzzyIsNull(GetRadius1()) ? line.p2().x() / GetRadius1() : 0;
const qreal b = not qFuzzyIsNull(GetRadius2()) ? line.p2().y() / GetRadius2() : 0;
const qreal k = qSqrt(a*a + b*b);
if (qFuzzyIsNull(k))
{
return GetCenter().toQPointF();
}
QPointF p(line.p2().x() / k, line.p2().y() / k);
QLineF line2(QPointF(), p);
@ -565,6 +576,13 @@ void VEllipticalArc::SetFormulaRadius1(const QString &formula, qreal value)
d->radius1 = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::SetRadius1(qreal value)
{
d->formulaRadius1 = QString::number(value);
d->radius1 = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::SetFormulaRadius2(const QString &formula, qreal value)
{
@ -572,6 +590,13 @@ void VEllipticalArc::SetFormulaRadius2(const QString &formula, qreal value)
d->radius2 = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::SetRadius2(qreal value)
{
d->formulaRadius2 = QString::number(value);
d->radius2 = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::SetFormulaRotationAngle(const QString &formula, qreal value)
{
@ -579,6 +604,13 @@ void VEllipticalArc::SetFormulaRotationAngle(const QString &formula, qreal value
d->rotationAngle = value;
}
//---------------------------------------------------------------------------------------------------------------------
void VEllipticalArc::SetRotationAngle(qreal value)
{
d->formulaRotationAngle = QString::number(value);
d->rotationAngle = value;
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief GetRadius1 return elliptical arc major radius.

View File

@ -75,14 +75,17 @@ public:
QString GetFormulaRotationAngle () const;
void SetFormulaRotationAngle (const QString &formula, qreal value);
void SetRotationAngle(qreal value);
qreal GetRotationAngle() const;
QString GetFormulaRadius1 () const;
void SetFormulaRadius1 (const QString &formula, qreal value);
void SetRadius1 (qreal value);
qreal GetRadius1 () const;
QString GetFormulaRadius2 () const;
void SetFormulaRadius2 (const QString &formula, qreal value);
void SetRadius2 (qreal value);
qreal GetRadius2 () const;
virtual qreal GetLength () const override;

View File

@ -456,3 +456,12 @@ void TST_VArc::TestCurveIntersectAxis()
Comparison(intersectionPoint, crosPoint, accuracyPointOnLine);
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VArc::EmptyArc()
{
VArc empty;
Comparison(empty.GetPoints(), {QPointF()});
QCOMPARE(empty.GetLength(), 0);
}

View File

@ -50,6 +50,7 @@ private slots:
void TestCutArc();
void TestCurveIntersectAxis_data();
void TestCurveIntersectAxis();
void EmptyArc();
};
#endif // TST_VARC_H

View File

@ -577,3 +577,29 @@ void TST_VEllipticalArc::TestFlip()
QCOMPARE(elArc.GetRadius1(), res.GetRadius1());
QCOMPARE(elArc.GetRadius2(), res.GetRadius2());
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VEllipticalArc::EmptyArc_data()
{
QTest::addColumn<qreal>("radius1");
QTest::addColumn<qreal>("radius2");
QTest::addColumn<qreal>("length");
QTest::newRow("Empty elArc") << 0. << 0. << 0.;
QTest::newRow("Radius1 correct") << 50. << 0. << 50.*4;
QTest::newRow("Radius2 correct") << 0. << 30. << 30.*4;
}
//---------------------------------------------------------------------------------------------------------------------
void TST_VEllipticalArc::EmptyArc()
{
QFETCH(qreal, radius1);
QFETCH(qreal, radius2);
QFETCH(qreal, length);
VEllipticalArc empty;
empty.SetRadius1(radius1);
empty.SetRadius2(radius2);
QCOMPARE(empty.GetLength(), length);
}

View File

@ -55,6 +55,8 @@ private slots:
void TestRotation();
void TestFlip_data();
void TestFlip();
void EmptyArc_data();
void EmptyArc();
private:
Q_DISABLE_COPY(TST_VEllipticalArc)