Fixed issue #957. Unable to cut an arc with negative length.
--HG-- branch : release
This commit is contained in:
parent
ca567ce981
commit
2eb2dbe462
|
@ -17,6 +17,7 @@
|
||||||
- [#954] Valentina produces empty rotation operation.
|
- [#954] Valentina produces empty rotation operation.
|
||||||
- [#955] Valentina corrupts file.
|
- [#955] Valentina corrupts file.
|
||||||
- [#956] Setting pattern unit doesn't change combobox value in Tape app.
|
- [#956] Setting pattern unit doesn't change combobox value in Tape app.
|
||||||
|
- [#957] Unable to cut an arc with negative length.
|
||||||
|
|
||||||
# Version 0.6.1 October 23, 2018
|
# Version 0.6.1 October 23, 2018
|
||||||
- [#885] Regression. Broken support for multi size measurements.
|
- [#885] Regression. Broken support for multi size measurements.
|
||||||
|
|
23
src/app/share/collection/bugs/Issue_#957.val
Normal file
23
src/app/share/collection/bugs/Issue_#957.val
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<pattern>
|
||||||
|
<!--Pattern created with Valentina v0.6.2.0 (https://valentinaproject.bitbucket.io/).-->
|
||||||
|
<version>0.7.12</version>
|
||||||
|
<unit>cm</unit>
|
||||||
|
<description/>
|
||||||
|
<notes/>
|
||||||
|
<measurements/>
|
||||||
|
<increments/>
|
||||||
|
<previewCalculations/>
|
||||||
|
<draw name="Pattern piece 1">
|
||||||
|
<calculation>
|
||||||
|
<point id="1" mx="0.132292" my="0.264583" name="А" showLabel="true" type="single" x="5.00423" y="9.10502"/>
|
||||||
|
<arc aScale="0.5" angle1="45" center="1" color="black" id="2" length="-10" penStyle="hair" radius="10" type="arcWithLength"/>
|
||||||
|
<point arc="2" id="3" length="6" mx="0.132292" my="0.264583" name="А1" showLabel="true" type="cutArc"/>
|
||||||
|
<arc aScale="0" angle1="135" center="1" color="black" id="4" length="10" penStyle="hair" radius="10" type="arcWithLength"/>
|
||||||
|
<point arc="4" id="5" length="-7" mx="0.132292" my="0.241842" name="А2" showLabel="true" type="cutArc"/>
|
||||||
|
</calculation>
|
||||||
|
<modeling/>
|
||||||
|
<details/>
|
||||||
|
<groups/>
|
||||||
|
</draw>
|
||||||
|
</pattern>
|
|
@ -232,8 +232,7 @@ QVector<QPointF> VArc::GetPoints() const
|
||||||
QVector<QPointF> points;
|
QVector<QPointF> points;
|
||||||
QVector<qreal> sectionAngle;
|
QVector<qreal> sectionAngle;
|
||||||
|
|
||||||
QPointF pStart;
|
QPointF pStart = IsFlipped() ? GetP2() : GetP1();
|
||||||
IsFlipped() ? pStart = GetP2() : pStart = GetP1();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
qreal angle = AngleArc();
|
qreal angle = AngleArc();
|
||||||
|
@ -304,53 +303,56 @@ QVector<QPointF> VArc::GetPoints() const
|
||||||
* @param arc2 second arc.
|
* @param arc2 second arc.
|
||||||
* @return point cutting
|
* @return point cutting
|
||||||
*/
|
*/
|
||||||
QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const
|
QPointF VArc::CutArc(qreal length, VArc &arc1, VArc &arc2) const
|
||||||
{
|
{
|
||||||
//Always need return two arcs, so we must correct wrong length.
|
//Always need return two arcs, so we must correct wrong length.
|
||||||
qreal len = 0;
|
|
||||||
const qreal minLength = ToPixel(1, Unit::Mm);
|
|
||||||
const qreal fullLength = GetLength();
|
const qreal fullLength = GetLength();
|
||||||
|
|
||||||
if (fullLength <= minLength)
|
if (qAbs(fullLength) < ToPixel(2, Unit::Mm))
|
||||||
{
|
{
|
||||||
arc1 = VArc();
|
arc1 = VArc();
|
||||||
arc2 = VArc();
|
arc2 = VArc();
|
||||||
return QPointF();
|
return QPointF();
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal maxLength = fullLength - minLength;
|
QLineF line(static_cast<QPointF>(GetCenter()), GetP1());
|
||||||
|
|
||||||
if (length < minLength)
|
if (not IsFlipped())
|
||||||
{
|
{
|
||||||
len = minLength;
|
if (length < 0)
|
||||||
|
{
|
||||||
|
length = fullLength + length;
|
||||||
}
|
}
|
||||||
else if (length > maxLength)
|
length = qBound(ToPixel(1, Unit::Mm), length, fullLength - ToPixel(1, Unit::Mm));
|
||||||
{
|
|
||||||
len = maxLength;
|
line.setAngle(line.angle() + qRadiansToDegrees(length/d->radius));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
len = length;
|
if (length > 0)
|
||||||
|
{
|
||||||
|
length = fullLength + length;
|
||||||
}
|
}
|
||||||
|
length = qBound(fullLength + ToPixel(1, Unit::Mm), length, ToPixel(-1, Unit::Mm));
|
||||||
|
|
||||||
qreal n = qRadiansToDegrees(len/d->radius); // n - is angle in degrees
|
line.setAngle(line.angle() - qRadiansToDegrees(qAbs(length)/d->radius));
|
||||||
|
}
|
||||||
QLineF line(static_cast<QPointF>(GetCenter()), GetP1());
|
|
||||||
line.setAngle(line.angle()+n);
|
|
||||||
|
|
||||||
arc1 = VArc (GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(),
|
arc1 = VArc (GetCenter(), d->radius, d->formulaRadius, GetStartAngle(), GetFormulaF1(), line.angle(),
|
||||||
QString().setNum(line.angle()), getIdObject(), getMode());
|
QString().setNum(line.angle()), getIdObject(), getMode());
|
||||||
arc1.SetApproximationScale(GetApproximationScale());
|
arc1.SetApproximationScale(GetApproximationScale());
|
||||||
|
arc1.SetFlipped(IsFlipped());
|
||||||
|
|
||||||
arc2 = VArc (GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(),
|
arc2 = VArc (GetCenter(), d->radius, d->formulaRadius, line.angle(), QString().setNum(line.angle()), GetEndAngle(),
|
||||||
GetFormulaF2(), getIdObject(), getMode());
|
GetFormulaF2(), getIdObject(), getMode());
|
||||||
arc2.SetApproximationScale(GetApproximationScale());
|
arc2.SetApproximationScale(GetApproximationScale());
|
||||||
|
arc2.SetFlipped(IsFlipped());
|
||||||
return line.p2();
|
return line.p2();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QPointF VArc::CutArc(const qreal &length) const
|
QPointF VArc::CutArc(qreal length) const
|
||||||
{
|
{
|
||||||
VArc arc1;
|
VArc arc1;
|
||||||
VArc arc2;
|
VArc arc2;
|
||||||
|
|
|
@ -83,8 +83,8 @@ public:
|
||||||
|
|
||||||
virtual QVector<QPointF> GetPoints () const override;
|
virtual QVector<QPointF> GetPoints () const override;
|
||||||
|
|
||||||
QPointF CutArc (const qreal &length, VArc &arc1, VArc &arc2) const;
|
QPointF CutArc (qreal length, VArc &arc1, VArc &arc2) const;
|
||||||
QPointF CutArc (const qreal &length) const;
|
QPointF CutArc (qreal length) const;
|
||||||
protected:
|
protected:
|
||||||
virtual void CreateName() override;
|
virtual void CreateName() override;
|
||||||
virtual void FindF2(qreal length) override;
|
virtual void FindF2(qreal length) override;
|
||||||
|
|
|
@ -318,3 +318,81 @@ void TST_VArc::TestFlip()
|
||||||
QCOMPARE(originArc.GetRadius(), res.GetRadius());
|
QCOMPARE(originArc.GetRadius(), res.GetRadius());
|
||||||
QCOMPARE(originArc.AngleArc(), res.AngleArc());
|
QCOMPARE(originArc.AngleArc(), res.AngleArc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VArc::TestCutArc_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QPointF>("center");
|
||||||
|
QTest::addColumn<qreal>("radius");
|
||||||
|
QTest::addColumn<qreal>("startAngle");
|
||||||
|
QTest::addColumn<qreal>("length");
|
||||||
|
QTest::addColumn<qreal>("cutLength");
|
||||||
|
QTest::addColumn<QPointF>("cutPoint");
|
||||||
|
|
||||||
|
QPointF center (189.13625196850393, 344.1267401574803);
|
||||||
|
qreal radius = ToPixel(10, Unit::Cm);
|
||||||
|
qreal startAngle = 45.0;
|
||||||
|
qreal length = ToPixel(-10, Unit::Cm);
|
||||||
|
qreal cutLength = ToPixel(6, Unit::Cm);
|
||||||
|
QPointF cutPoint(539.3657292513009, 202.04366960088566);
|
||||||
|
|
||||||
|
// See file <root>/src/app/share/collection/bugs/Issue_#957.val
|
||||||
|
QTest::newRow("Arc -10 cm length, cut length 6 cm") << center << radius << startAngle << length << cutLength
|
||||||
|
<< cutPoint;
|
||||||
|
|
||||||
|
cutLength = ToPixel(-4, Unit::Cm);
|
||||||
|
|
||||||
|
// Opposite case
|
||||||
|
QTest::newRow("Arc -10 cm length, cut length -4 cm") << center << radius << startAngle << length << cutLength
|
||||||
|
<< cutPoint;
|
||||||
|
|
||||||
|
startAngle = 135;
|
||||||
|
length = ToPixel(10, Unit::Cm);
|
||||||
|
cutLength = ToPixel(-7, Unit::Cm);
|
||||||
|
cutPoint = QPointF(-145.1588983496871, 167.78888781060192);
|
||||||
|
|
||||||
|
// See file <root>/src/app/share/collection/bugs/Issue_#957.val
|
||||||
|
QTest::newRow("Arc 10 cm length, cut length -7 cm") << center << radius << startAngle << length << cutLength
|
||||||
|
<< cutPoint;
|
||||||
|
|
||||||
|
// Opposite case
|
||||||
|
cutLength = ToPixel(3, Unit::Cm);
|
||||||
|
QTest::newRow("Arc 10 cm length, cut length 3 cm") << center << radius << startAngle << length << cutLength
|
||||||
|
<< cutPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void TST_VArc::TestCutArc()
|
||||||
|
{
|
||||||
|
QFETCH(QPointF, center);
|
||||||
|
QFETCH(qreal, radius);
|
||||||
|
QFETCH(qreal, startAngle);
|
||||||
|
QFETCH(qreal, length);
|
||||||
|
QFETCH(qreal, cutLength);
|
||||||
|
QFETCH(QPointF, cutPoint);
|
||||||
|
|
||||||
|
VArc arc (length, VPointF(center), radius, startAngle);
|
||||||
|
arc.SetApproximationScale(0.5);
|
||||||
|
|
||||||
|
VArc arc1;
|
||||||
|
VArc arc2;
|
||||||
|
QPointF point = arc.CutArc(cutLength, arc1, arc2);
|
||||||
|
|
||||||
|
QCOMPARE(point, cutPoint);
|
||||||
|
|
||||||
|
QCOMPARE(arc1.IsFlipped(), arc.IsFlipped());
|
||||||
|
QCOMPARE(arc2.IsFlipped(), arc.IsFlipped());
|
||||||
|
|
||||||
|
QCOMPARE(arc1.GetApproximationScale(), arc.GetApproximationScale());
|
||||||
|
QCOMPARE(arc2.GetApproximationScale(), arc.GetApproximationScale());
|
||||||
|
|
||||||
|
QCOMPARE(arc1.GetStartAngle(), arc.GetStartAngle());
|
||||||
|
QCOMPARE(arc2.GetEndAngle(), arc.GetEndAngle());
|
||||||
|
|
||||||
|
QVERIFY(VFuzzyComparePossibleNulls(arc1.GetEndAngle(), arc2.GetStartAngle()));
|
||||||
|
|
||||||
|
QCOMPARE(arc1.GetLength() + arc2.GetLength(), arc.GetLength());
|
||||||
|
|
||||||
|
qreal segmentsLength = VAbstractCurve::PathLength(arc1.GetPoints()) + VAbstractCurve::PathLength(arc2.GetPoints());
|
||||||
|
QVERIFY(qAbs(segmentsLength - VAbstractCurve::PathLength(arc.GetPoints())) <= accuracyPointOnLine);
|
||||||
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ private slots:
|
||||||
void TestRotation();
|
void TestRotation();
|
||||||
void TestFlip_data();
|
void TestFlip_data();
|
||||||
void TestFlip();
|
void TestFlip();
|
||||||
|
void TestCutArc_data();
|
||||||
|
void TestCutArc();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TST_VARC_H
|
#endif // TST_VARC_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user