From e3acc16a761bea0a5d6e4ac77db93e2d687e79bd Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 2 Apr 2016 20:47:04 +0300 Subject: [PATCH] Resolved issue #444. Length along Path seems not valid. --HG-- branch : develop --- ChangeLog.txt | 1 + src/libs/vgeometry/vabstractcubicbezier.cpp | 19 +++++++++++--- .../vgeometry/vabstractcubicbezierpath.cpp | 26 ++++++++++++++----- src/libs/vgeometry/varc.cpp | 20 +++++++++++--- src/libs/vgeometry/vellipticalarc.cpp | 20 +++++++++++--- 5 files changed, 68 insertions(+), 18 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 5eb0bd41f..567c4cfa2 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- [#444] Length along Path seems not valid. - Added new curve path segment variables. - Toggle ScrollHandDrag mode by clicking a middle mouse button. - Added horizontal scrolling by pressiong Shift + mouse wheel. diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 75b1f5434..6a167bc1e 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -74,13 +74,24 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF & QPointF &spl2p3) const { //Always need return two splines, so we must correct wrong length. - if (length < GetLength()*0.02) + const qreal minLength = ToPixel(1, Unit::Mm); + const qreal fullLength = GetLength(); + + if (fullLength <= minLength) { - length = GetLength()*0.02; + spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF(); + return QPointF(); } - else if ( length > GetLength()*0.98) + + const qreal maxLength = fullLength - minLength; + + if (length < minLength) { - length = GetLength()*0.98; + length = minLength; + } + else if (length > maxLength) + { + length = maxLength; } const qreal parT = GetParmT(length); diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 2de85f056..96d26b543 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -156,28 +156,42 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32 } //Always need return two spline paths, so we must correct wrong length. + const qreal minLength = ToPixel(1, Unit::Mm); qreal fullLength = GetLength(); - if (length < fullLength * 0.02) + + if (fullLength <= minLength) { - length = fullLength * 0.02; + p1 = p2 = -1; + spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF(); + return QPointF(); } - else if ( length > fullLength * 0.98) + + const qreal maxLength = fullLength - minLength; + + if (length < minLength) { - length = fullLength * 0.98; + length = minLength; + } + else if (length > maxLength) + { + length = maxLength; } fullLength = 0; for (qint32 i = 1; i <= CountSubSpl(); ++i) { const VSpline spl = GetSpline(i); - fullLength += spl.GetLength(); + const qreal splLength = spl.GetLength(); + fullLength += splLength; if (fullLength > length) { p1 = i-1; p2 = i; - return spl.CutSpline(length - (fullLength - spl.GetLength()), spl1p2, spl1p3, spl2p2, spl2p3); + return spl.CutSpline(length - (fullLength - splLength), spl1p2, spl1p3, spl2p2, spl2p3); } } + p1 = p2 = -1; + spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF(); return QPointF(); } diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index b807b3f61..5b351f9bf 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -270,13 +270,25 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const { //Always need return two arcs, so we must correct wrong length. qreal len = 0; - if (length < this->GetLength()*0.02) + const qreal minLength = ToPixel(1, Unit::Mm); + const qreal fullLength = GetLength(); + + if (fullLength <= minLength) { - len = this->GetLength()*0.02; + arc1 = VArc(); + arc2 = VArc(); + return QPointF(); } - else if ( length > this->GetLength()*0.98) + + const qreal maxLength = fullLength - minLength; + + if (length < minLength) { - len = this->GetLength()*0.98; + len = minLength; + } + else if (length > maxLength) + { + len = maxLength; } else { diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 853e94ad4..cd2327b88 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -322,13 +322,25 @@ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllip { //Always need return two arcs, so we must correct wrong length. qreal len = 0; - if (length < this->GetLength()*0.02) + const qreal minLength = ToPixel(1, Unit::Mm); + const qreal fullLength = GetLength(); + + if (fullLength <= minLength) { - len = this->GetLength()*0.02; + arc1 = VEllipticalArc(); + arc2 = VEllipticalArc(); + return QPointF(); } - else if ( length > this->GetLength()*0.98) + + const qreal maxLength = fullLength - minLength; + + if (length < minLength) { - len = this->GetLength()*0.98; + len = minLength; + } + else if (length > maxLength) + { + len = maxLength; } else {