From c587826a56f7ce0bec6c682a69255d13b863eb44 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 10 Feb 2016 06:59:29 +0200 Subject: [PATCH 01/21] Added VEllipticalArc --HG-- branch : feature --- src/libs/ifc/ifcdef.h | 1 + src/libs/vgeometry/vellipticalarc.cpp | 468 ++++++++++++++++++++++++++ src/libs/vgeometry/vellipticalarc.h | 101 ++++++ src/libs/vgeometry/vellipticalarc_p.h | 85 +++++ src/libs/vgeometry/vgeometry.pri | 63 ++-- src/libs/vgeometry/vgeometrydef.h | 2 +- 6 files changed, 689 insertions(+), 31 deletions(-) create mode 100644 src/libs/vgeometry/vellipticalarc.cpp create mode 100644 src/libs/vgeometry/vellipticalarc.h create mode 100644 src/libs/vgeometry/vellipticalarc_p.h diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index f630b509d..0a073cda2 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -146,6 +146,7 @@ extern const QString ColorYellow; // Hacks for avoiding the linker error "undefined reference to" #define SPL_ "Spl_" #define ARC_ "Arc_" +#define EARC_ "EllipticalArc_" extern const QString line_; extern const QString angleLine_; diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp new file mode 100644 index 000000000..f3e910488 --- /dev/null +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -0,0 +1,468 @@ +/************************************************************************ + ** + ** @file vellipticalarc.cpp + ** @author Valentina Zhuravska + ** @date February 1, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vellipticalarc.h" +#include "vellipticalarc_p.h" +#include "vspline.h" +#include "../ifc/ifcdef.h" +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VEllipticalArc default constructor. + */ +VEllipticalArc::VEllipticalArc() + :VAbstractCurve(GOType::EllipticalArc), d (new VEllipticalArcData) +{} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VEllipticalArc constructor. + * @param center center point. + * @param radius1 arc major radius. + * @param radius2 arc minor radius. + * @param f1 start angle (degree). + * @param f2 end angle (degree). + */ +VEllipticalArc::VEllipticalArc (VPointF center, qreal radius1, qreal radius2, + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, qreal f2, + QString formulaF2, qreal rotationAngle, quint32 idObject, Draw mode) + : VAbstractCurve(GOType::EllipticalArc, idObject, mode), + d (new VEllipticalArcData(center, radius1, radius2, formulaRadius1, formulaRadius2, + f1, formulaF1, f2, formulaF2, rotationAngle)) +{ + EllipticalArcName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc::VEllipticalArc(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) + : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), + d (new VEllipticalArcData(center, radius1, radius2, f1, f2, rotationAngle)) +{ + EllipticalArcName(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc::VEllipticalArc(qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, quint32 idObject, Draw mode) + : VAbstractCurve(GOType::EllipticalArc, idObject, mode), + d (new VEllipticalArcData(formulaLength, center, radius1, radius2, formulaRadius1, formulaRadius2, f1, formulaF1)) +{ + EllipticalArcName(); + FindF2(length); +} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1) + : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), + d (new VEllipticalArcData(center, radius1, radius2, f1)) +{ + EllipticalArcName(); + FindF2(length); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VEllipticalArc copy constructor + * @param arc arc + */ +VEllipticalArc::VEllipticalArc(const VEllipticalArc &arc) + : VAbstractCurve(arc), d (arc.d) +{} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief operator = assignment operator + * @param arc arc + * @return arc + */ +VEllipticalArc &VEllipticalArc::operator =(const VEllipticalArc &arc) +{ + if ( &arc == this ) + { + return *this; + } + VAbstractCurve::operator=(arc); + d = arc.d; + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VEllipticalArc::~VEllipticalArc() +{} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetLength return arc length. + * @return length. + */ +qreal VEllipticalArc::GetLength() const +{ + QPointF firstPoint; + QPointF point2; + QPointF point3; + QPointF lastPoint; + + if (not d->isFlipped) + { + firstPoint = GetP1(); + point2 = GetPoint((2*GetStartAngle() + GetEndAngle())/3); + point3 = GetPoint((GetStartAngle() + 2*GetEndAngle())/3); + lastPoint = GetP2(); + } + 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) + { + length = length * -1; + } + + return length; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetP1 return point associated with start angle. + * @return point. + */ +QPointF VEllipticalArc::GetP1() const +{ + // we ignore the rotation! + 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))); + return p1; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetP2 return point associated with end angle. + * @return point. + */ +QPointF VEllipticalArc::GetP2 () const +{ + // we ignore the rotation! + 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))); + return p2; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetPoint return point associated with angle. + * @return point. + */ +QPointF VEllipticalArc::GetPoint (qreal angle) const +{ + // we ignore the 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))); + return p; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief AngleArc calculate arc angle. + * @return angle in degree. + */ +qreal VEllipticalArc::AngleArc() const +{ + if ((qFuzzyCompare(d->f1+1, 0+1) && qFuzzyCompare(d->f2, 360)) || + (qFuzzyCompare(d->f1, 360) && qFuzzyCompare(d->f2+1, 0+1))) + { + return 360; + } + QLineF l1(0, 0, 100, 100); + l1.setAngle(d->f1); + QLineF l2(0, 0, 100, 100); + l2.setAngle(d->f2); + + qreal ang = l1.angleTo(l2); + + if (d->isFlipped) + { + ang = 360 - ang; + } + + return ang; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetPoints return list of points needed for drawing arc. + * @return list of points + */ +QVector VEllipticalArc::GetPoints() const +{ + QVector points; + QVector sectionAngle; + + QPointF pStart; + d->isFlipped ? pStart = GetP2() : pStart = GetP1(); + + { + qreal angle = AngleArc(); + + if (qFuzzyIsNull(angle)) + { + points.append(pStart); + return points; + } + + 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); + } + } + for (int i = 0; i < sectionAngle.size(); ++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)); + + VSpline spl(VPointF(firstPoint), point2, point3, VPointF(lastPoint), 1.0); + + QVector splPoints = spl.GetPoints(); + + if (not splPoints.isEmpty() && i != sectionAngle.size() - 1) + { + splPoints.removeLast(); + } + points << splPoints; + } + // we ignore the rotation of ellipse. + return points; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief CutArc cut arc into two arcs. + * @param length length first arc. + * @param arc1 first arc. + * @param arc2 second arc. + * @return point cutting + */ +QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const +{ +} + + +//--------------------------------------------------------------------------------------------------------------------- +QPointF VEllipticalArc::CutArc(const qreal &length) const +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief setId keep id arc in data. + * @param id id arc in data. + */ +void VEllipticalArc::setId(const quint32 &id) +{ + VAbstractCurve::setId(id); + setName(EARC_ + QString("%1_%2").arg(d->center.name()).arg(id)); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::EllipticalArcName() +{ + setName(EARC_ + QString("%1").arg(this->GetCenter().name())); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::FindF2(qreal length) +{ + // We need to calculate the second angle, +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VEllipticalArc::MaxLength() const +{ + return M_PI*(d->radius1+d->radius2); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetF1 return start angle. + * @return angle in degree. + */ +QString VEllipticalArc::GetFormulaF1() const +{ + return d->formulaF1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetFormulaF1(const QString &formula, qreal value) +{ + d->formulaF1 = formula; + d->f1 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetF1 return formula for start angle. + * @return string with formula. + */ +qreal VEllipticalArc::GetStartAngle() const +{ + return d->f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetF2 return end angle. + * @return angle in degree. + */ +QString VEllipticalArc::GetFormulaF2() const +{ + return d->formulaF2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetFormulaF2(const QString &formula, qreal value) +{ + d->formulaF2 = formula; + d->f2 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetF2 return formula for end angle. + * @return string with formula. + */ +qreal VEllipticalArc::GetEndAngle() const +{ + return d->f2; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetRadius return arc major radius. + * @return radius. + */ +QString VEllipticalArc::GetFormulaRadius1() const +{ + return d->formulaRadius1; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetRadius return arc minor radius. + * @return radius. + */ +QString VEllipticalArc::GetFormulaRadius2() const +{ + return d->formulaRadius2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetFormulaRadius1(const QString &formula, qreal value) +{ + d->formulaRadius1 = formula; + d->radius1 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetFormulaRadius2(const QString &formula, qreal value) +{ + d->formulaRadius2 = formula; + d->radius2 = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetRadius return formula for major radius. + * @return string with formula. + */ +qreal VEllipticalArc::GetRadius1() const +{ + return d->radius1; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetRadius return formula for minor radius. + * @return string with formula. + */ +qreal VEllipticalArc::GetRadius2() const +{ + return d->radius2; +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetCenter return center point. + * @return center point. + */ +VPointF VEllipticalArc::GetCenter() const +{ + return d->center; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetCenter(const VPointF &value) +{ + d->center = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VEllipticalArc::GetFormulaLength() const +{ + return d->formulaLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VEllipticalArc::SetFormulaLength(const QString &formula, qreal value) +{ + d->formulaLength = formula; + FindF2(value); +} diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h new file mode 100644 index 000000000..27ddde1a9 --- /dev/null +++ b/src/libs/vgeometry/vellipticalarc.h @@ -0,0 +1,101 @@ +/************************************************************************ + ** + ** @file vellipticalarc.h + ** @author Valentina Zhuravska + ** @date February 1, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2013-2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VELLIPTICALARC_H +#define VELLIPTICALARC_H + +#include "vabstractcurve.h" +#include "vpointf.h" +#include + +class VEllipticalArcData; + +class VEllipticalArc : public VAbstractCurve +{ + Q_DECLARE_TR_FUNCTIONS(VEllipticalArc) +public: + VEllipticalArc(); + VEllipticalArc (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, qreal f1, + QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); + + VEllipticalArc (VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); + + VEllipticalArc (qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, + QString formulaRadius1, QString formulaRadius2, qreal f1, + QString formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + + VEllipticalArc (qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1); + + VEllipticalArc(const VEllipticalArc &arc); + + VEllipticalArc& operator= (const VEllipticalArc &arc); + + virtual ~VEllipticalArc() Q_DECL_OVERRIDE; + + QString GetFormulaF1 () const; + void SetFormulaF1 (const QString &formula, qreal value); + virtual qreal GetStartAngle () const Q_DECL_OVERRIDE; + + QString GetFormulaF2 () const; + void SetFormulaF2 (const QString &formula, qreal value); + virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + + QString GetFormulaRadius1 () const; + QString GetFormulaRadius2 () const; + void SetFormulaRadius1 (const QString &formula, qreal value); + void SetFormulaRadius2 (const QString &formula, qreal value); + qreal GetRadius1 () const; + qreal GetRadius2 () const; + + VPointF GetCenter () const; + void SetCenter (const VPointF &value); + + QString GetFormulaLength () const; + void SetFormulaLength (const QString &formula, qreal value); + qreal GetLength () const; + + QPointF GetP1() const; + QPointF GetP2 () const; + QPointF GetPoint (qreal angle) const; + qreal AngleArc() const; + QVector GetPoints () const; + QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; + QPointF CutArc (const qreal &length) const; + virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; +private: + QSharedDataPointer d; + + void EllipticalArcName(); + void FindF2(qreal length); + + qreal MaxLength() const; +}; + +Q_DECLARE_TYPEINFO(VEllipticalArc, Q_MOVABLE_TYPE); + +#endif // VELLIPTICALARC_H diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h new file mode 100644 index 000000000..67b970a39 --- /dev/null +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -0,0 +1,85 @@ +#ifndef VELLIPTICALARC_P +#define VELLIPTICALARC_P + +#include +#include "vpointf.h" + +class VEllipticalArcData : public QSharedData +{ +public: + + VEllipticalArcData () + : f1(0), f2(0), formulaF1(QString()), formulaF2(QString()), + radius1(0), radius2(0), formulaRadius1(QString()), formulaRadius2(QString()), + center(VPointF()), isFlipped(false), formulaLength(), rotationAngle(0) + {} + + VEllipticalArcData (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, + qreal f1, QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle) + : f1(f1), f2(f2), formulaF1(formulaF1), formulaF2(formulaF2), + radius1(radius1), radius2(radius2), formulaRadius1(formulaRadius1), formulaRadius2(formulaRadius2), + center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) + {} + + VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) + : f1(f1), f2(f2), formulaF1(QString("%1").arg(f1)), formulaF2(QString("%1").arg(f2)), + radius1(radius1), radius2(radius2), + formulaRadius1(QString("%1").arg(radius1)), formulaRadius2(QString("%1").arg(radius2)), + center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) + {} + + VEllipticalArcData (QString formulaLength, VPointF center, qreal radius1, qreal radius2, + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1) + : f1(f1), f2(0), formulaF1(formulaF1), formulaF2("0"), radius1(radius1),radius2(radius2), + formulaRadius1(formulaRadius1), formulaRadius2(formulaRadius2), + center(center), isFlipped(false), formulaLength(formulaLength), rotationAngle(0) + {} + + VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1) + : f1(f1), f2(0), formulaF1(QString("%1").arg(f1)), formulaF2("0"), + radius1(radius1), radius2(radius2), + formulaRadius1(QString("%1").arg(radius1)), formulaRadius2(QString("%1").arg(radius2)), + center(center), isFlipped(false), formulaLength(), rotationAngle(0) + {} + + VEllipticalArcData(const VEllipticalArcData &arc) + : QSharedData(arc), f1(arc.f1), f2(arc.f2), formulaF1(arc.formulaF1), formulaF2(arc.formulaF2), + radius1(arc.radius1), radius2(arc.radius2), + formulaRadius1(arc.formulaRadius1), formulaRadius2(arc.formulaRadius2), + center(arc.center), isFlipped(arc.isFlipped), formulaLength(arc.formulaLength), rotationAngle(arc.rotationAngle) + {} + + virtual ~VEllipticalArcData(); + + /** @brief f1 start angle in degree. */ + qreal f1; + /** @brief f2 end angle in degree. */ + qreal f2; + /** @brief formulaF1 formula for start angle. */ + QString formulaF1; + /** @brief formulaF2 formula for end angle. */ + QString formulaF2; + /** @brief radius1 elliptical arc major radius. */ + qreal radius1; + /** @brief radius2 elliptical arc minor radius. */ + qreal radius2; + /** @brief formulaRadius1 formula for elliptical arc major radius. */ + QString formulaRadius1; + /** @brief formulaRadius2 formula for elliptical arc minor radius. */ + QString formulaRadius2; + /** @brief center center point of arc. */ + VPointF center; + bool isFlipped; + QString formulaLength; + /** @brief rotationAngle in degree. */ + qreal rotationAngle; + +private: + VEllipticalArcData &operator=(const VEllipticalArcData &) Q_DECL_EQ_DELETE; +}; + +VEllipticalArcData::~VEllipticalArcData() +{} + +#endif // VELLIPTICALARC_P + diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index c88e4f97d..26fca8fbb 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -1,30 +1,33 @@ -# ADD TO EACH PATH $$PWD VARIABLE!!!!!! -# This need for corect working file translations.pro - -SOURCES += \ - $$PWD/vgobject.cpp \ - $$PWD/vabstractcurve.cpp \ - $$PWD/varc.cpp \ - $$PWD/vpointf.cpp \ - $$PWD/vspline.cpp \ - $$PWD/vsplinepath.cpp \ - $$PWD/vsplinepoint.cpp - -win32-msvc*:SOURCES += $$PWD/stable.cpp - -HEADERS += \ - $$PWD/stable.h \ - $$PWD/vgobject.h \ - $$PWD/vgobject_p.h \ - $$PWD/vabstractcurve.h \ - $$PWD/varc.h \ - $$PWD/varc_p.h \ - $$PWD/vpointf.h \ - $$PWD/vpointf_p.h \ - $$PWD/vspline.h \ - $$PWD/vspline_p.h \ - $$PWD/vsplinepath.h \ - $$PWD/vsplinepath_p.h \ - $$PWD/vsplinepoint.h \ - $$PWD/vsplinepoint_p.h \ - $$PWD/vgeometrydef.h +# ADD TO EACH PATH $$PWD VARIABLE!!!!!! +# This need for corect working file translations.pro + +SOURCES += \ + $$PWD/vgobject.cpp \ + $$PWD/vabstractcurve.cpp \ + $$PWD/varc.cpp \ + $$PWD/vpointf.cpp \ + $$PWD/vspline.cpp \ + $$PWD/vsplinepath.cpp \ + $$PWD/vsplinepoint.cpp \ + $$PWD/vellipticalarc.cpp + +win32-msvc*:SOURCES += $$PWD/stable.cpp + +HEADERS += \ + $$PWD/stable.h \ + $$PWD/vgobject.h \ + $$PWD/vgobject_p.h \ + $$PWD/vabstractcurve.h \ + $$PWD/varc.h \ + $$PWD/varc_p.h \ + $$PWD/vpointf.h \ + $$PWD/vpointf_p.h \ + $$PWD/vspline.h \ + $$PWD/vspline_p.h \ + $$PWD/vsplinepath.h \ + $$PWD/vsplinepath_p.h \ + $$PWD/vsplinepoint.h \ + $$PWD/vsplinepoint_p.h \ + $$PWD/vgeometrydef.h \ + $$PWD/vellipticalarc.h \ + $$PWD/vellipticalarc_p.h diff --git a/src/libs/vgeometry/vgeometrydef.h b/src/libs/vgeometry/vgeometrydef.h index b69e68c7d..9c8840e72 100644 --- a/src/libs/vgeometry/vgeometrydef.h +++ b/src/libs/vgeometry/vgeometrydef.h @@ -32,7 +32,7 @@ #include enum class Draw : char { Calculation, Modeling, Layout }; -enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown }; +enum class GOType : char { Point, Arc, EllipticalArc, Spline, SplinePath, Unknown }; enum class SplinePointPosition : char { FirstPoint, LastPoint }; #endif // VGEOMETRYDEF_H From 894ad4ea6606f3ff627fde41ba54899447ed926d Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 12 Feb 2016 20:17:55 +0200 Subject: [PATCH 02/21] Fixed GetLength method in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 100 +++++++++++++++----------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index f3e910488..1e5e26b09 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -124,27 +124,25 @@ VEllipticalArc::~VEllipticalArc() */ qreal VEllipticalArc::GetLength() const { - QPointF firstPoint; - QPointF point2; - QPointF point3; - QPointF lastPoint; + qreal length = 0; - if (not d->isFlipped) + QVector sectionAngle = GetAngles(); + + for (int i = 0; i < sectionAngle.size()-1; ++i) { - firstPoint = GetP1(); - point2 = GetPoint((2*GetStartAngle() + GetEndAngle())/3); - point3 = GetPoint((GetStartAngle() + 2*GetEndAngle())/3); - lastPoint = GetP2(); + 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); } - 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) { @@ -222,24 +220,19 @@ qreal VEllipticalArc::AngleArc() const //--------------------------------------------------------------------------------------------------------------------- /** - * @brief GetPoints return list of points needed for drawing arc. - * @return list of points + * @brief GetAngles return list of angles needed for drawing arc. + * @return list of angles */ -QVector VEllipticalArc::GetPoints() const +QVector VEllipticalArc::GetAngles() const { - QVector points; QVector sectionAngle; - - QPointF pStart; - d->isFlipped ? pStart = GetP2() : pStart = GetP1(); - { qreal angle = AngleArc(); if (qFuzzyIsNull(angle)) - { - points.append(pStart); - return points; + {// Return the array that includes one angle + sectionAngle.append(d->f1); + return sectionAngle; } if (angle > 360 || angle < 0) @@ -262,20 +255,45 @@ QVector VEllipticalArc::GetPoints() const 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 VEllipticalArc::GetPoints() const +{ + QVector points; + QVector 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) { - 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)); - - VSpline spl(VPointF(firstPoint), point2, point3, VPointF(lastPoint), 1.0); - - QVector splPoints = spl.GetPoints(); - - if (not splPoints.isEmpty() && i != sectionAngle.size() - 1) + points.append(GetP1()); + } + else + { + for (int i = 0; i < sectionAngle.size()-1; ++i) { - splPoints.removeLast(); + 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)); + + VSpline spl(VPointF(firstPoint), point2, point3, VPointF(lastPoint), 1.0); + + QVector splPoints = spl.GetPoints(); + + if (not splPoints.isEmpty() && i != sectionAngle.size() - 1) + { + splPoints.removeLast(); + } + points << splPoints; } points << splPoints; } From 560a3dc1d1a458f361b097070814eeac13c137a0 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 12 Feb 2016 20:19:46 +0200 Subject: [PATCH 03/21] Added rotation of points --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 43 ++++++++++++++++++++------- src/libs/vgeometry/vellipticalarc.h | 3 ++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 1e5e26b09..d382ce390 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -159,10 +159,15 @@ qreal VEllipticalArc::GetLength() const */ QPointF VEllipticalArc::GetP1() const { - // we ignore the rotation! + // p1 - point without rotation 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))); - return p1; + // 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())); + + return pointRotation; } //--------------------------------------------------------------------------------------------------------------------- @@ -172,10 +177,15 @@ QPointF VEllipticalArc::GetP1() const */ QPointF VEllipticalArc::GetP2 () const { - // we ignore the rotation! + // p2 - point without rotation 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))); - return p2; + // 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())); + + return pointRotation; } //--------------------------------------------------------------------------------------------------------------------- @@ -185,10 +195,16 @@ QPointF VEllipticalArc::GetP2 () const */ QPointF VEllipticalArc::GetPoint (qreal angle) const { - // we ignore the rotation! + // 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))); - return p; + 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())); + + return pointRotation; } //--------------------------------------------------------------------------------------------------------------------- @@ -217,7 +233,6 @@ qreal VEllipticalArc::AngleArc() const return ang; } - //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetAngles return list of angles needed for drawing arc. @@ -295,9 +310,7 @@ QVector VEllipticalArc::GetPoints() const } points << splPoints; } - points << splPoints; } - // we ignore the rotation of ellipse. return points; } @@ -422,6 +435,16 @@ QString VEllipticalArc::GetFormulaRadius2() const return d->formulaRadius2; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief GetRotationAngle return rotation angle. + * @return rotationAngle. + */ +qreal VEllipticalArc::GetRotationAngle() const +{ + return d->rotationAngle; +} + //--------------------------------------------------------------------------------------------------------------------- void VEllipticalArc::SetFormulaRadius1(const QString &formula, qreal value) { diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 27ddde1a9..40b314ae9 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -65,6 +65,8 @@ public: void SetFormulaF2 (const QString &formula, qreal value); virtual qreal GetEndAngle () const Q_DECL_OVERRIDE; + qreal GetRotationAngle() const; + QString GetFormulaRadius1 () const; QString GetFormulaRadius2 () const; void SetFormulaRadius1 (const QString &formula, qreal value); @@ -83,6 +85,7 @@ public: QPointF GetP2 () const; QPointF GetPoint (qreal angle) const; qreal AngleArc() const; + QVector GetAngles () const; QVector GetPoints () const; QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; QPointF CutArc (const qreal &length) const; From 37eb0e9e2159b2dd709b4ddbc97e7760672ad04b Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 12 Feb 2016 22:02:54 +0200 Subject: [PATCH 04/21] Fixed GetLength and changed the rotation of point --HG-- branch : feature --- src/libs/ifc/ifcdef.h | 2 +- src/libs/vgeometry/vellipticalarc.cpp | 98 ++++++++++++--------------- src/libs/vgeometry/vellipticalarc.h | 8 ++- src/libs/vgeometry/vgeometry.pri | 6 +- 4 files changed, 51 insertions(+), 63 deletions(-) diff --git a/src/libs/ifc/ifcdef.h b/src/libs/ifc/ifcdef.h index 0a073cda2..c34d2d951 100644 --- a/src/libs/ifc/ifcdef.h +++ b/src/libs/ifc/ifcdef.h @@ -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_; diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index d382ce390..50d53ee72 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -32,6 +32,7 @@ #include "../ifc/ifcdef.h" #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -124,25 +125,15 @@ VEllipticalArc::~VEllipticalArc() */ qreal VEllipticalArc::GetLength() const { - qreal length = 0; - - QVector sectionAngle = GetAngles(); - - for (int i = 0; i < sectionAngle.size()-1; ++i) + qreal length; + QPainterPath elArc; + QVector 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 VEllipticalArc::GetAngles() const { QVector 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; } diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 40b314ae9..f80af80bb 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -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 GetAngles () const; QVector 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); diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 26fca8fbb..e8a8bc1b4 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -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 From 6fc86543ecc0e43b0db34746c518eb692e3630e0 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 19 Feb 2016 11:43:46 +0200 Subject: [PATCH 05/21] Little fixes --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 8 +++++--- src/test/ValentinaTest/tst_varc.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 50d53ee72..99d474342 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -125,13 +125,13 @@ VEllipticalArc::~VEllipticalArc() */ qreal VEllipticalArc::GetLength() const { - qreal length; + qreal length = 0; QPainterPath elArc; QVector points = GetPoints(); elArc.moveTo(points.at(0)); for (qint32 i = 1; i < points.count(); ++i) { - elArc.lineTo(points.at(i)); + elArc.lineTo(points.at(i)); } length = elArc.length(); @@ -344,7 +344,9 @@ void VEllipticalArc::FindF2(qreal length) //--------------------------------------------------------------------------------------------------------------------- qreal VEllipticalArc::MaxLength() const { - return M_PI*(d->radius1+d->radius2); + const qreal h = ((d->radius1-d->radius2)*(d->radius1-d->radius2))/((d->radius1+d->radius2)*(d->radius1+d->radius2)); + const qreal ellipseLength = M_PI*(d->radius1+d->radius2)*(1+3*h/(10+qSqrt(4-3*h))); + return ellipseLength; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/ValentinaTest/tst_varc.cpp b/src/test/ValentinaTest/tst_varc.cpp index 2f56ae3cb..127d45022 100644 --- a/src/test/ValentinaTest/tst_varc.cpp +++ b/src/test/ValentinaTest/tst_varc.cpp @@ -190,19 +190,19 @@ void TST_VArc::TestGetPoints() } { - qreal gSquere = 0.0;// geometry squere + qreal gSquere = 0.0;// geometry square if (qFuzzyCompare(arc.AngleArc(), 360.0)) - {// circle squere + {// circle square gSquere = M_PI * radius * radius; } else - {// sector squere + {// sector square gSquere = (M_PI * radius * radius) / 360.0 * arc.AngleArc(); points.append(center.toQPointF()); } - // calculated squere + // calculated square const qreal cSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); const qreal value = qAbs(gSquere - cSquare); const QString errorMsg = From 9eb385c7a21675b45c9e9c0408e8df1084d7cb99 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 19 Feb 2016 11:45:36 +0200 Subject: [PATCH 06/21] Added tests for VEllipticalArc --HG-- branch : feature --- src/test/ValentinaTest/ValentinaTest.pro | 664 +++++++++--------- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vellipticalarc.cpp | 283 ++++++++ src/test/ValentinaTest/tst_vellipticalarc.h | 47 ++ 4 files changed, 665 insertions(+), 331 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vellipticalarc.cpp create mode 100644 src/test/ValentinaTest/tst_vellipticalarc.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 9d1dd5c04..04210efa9 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -1,331 +1,333 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2015-03-31T17:27:03 -# -#------------------------------------------------- - -QT += testlib gui printsupport xml xmlpatterns - -TARGET = ValentinaTests - -# File with common stuff for whole project -include(../../../common.pri) - -# CONFIG += testcase adds a 'make check' which is great. But by default it also -# adds a 'make install' that installs the test cases, which we do not want. -# Can configure it not to do that with 'no_testcase_installs' -# We use C++11 standard -CONFIG += c++11 testcase no_testcase_installs - -# Use out-of-source builds (shadow builds) -CONFIG -= app_bundle debug_and_release debug_and_release_target - -TEMPLATE = app - -# directory for executable file -DESTDIR = bin - -# Directory for files created moc -MOC_DIR = moc - -# objecs files -OBJECTS_DIR = obj - -DEFINES += SRCDIR=\\\"$$PWD/\\\" - -SOURCES += \ - qttestmainlambda.cpp \ - tst_vposter.cpp \ - tst_vabstractdetail.cpp \ - tst_vspline.cpp \ - abstracttest.cpp \ - tst_nameregexp.cpp \ - tst_vlayoutdetail.cpp \ - tst_varc.cpp \ - stable.cpp \ - tst_measurementregexp.cpp \ - tst_tapecommandline.cpp \ - tst_valentinacommandline.cpp \ - tst_qmutokenparser.cpp \ - tst_vmeasurements.cpp \ - tst_qmuparsererrormsg.cpp \ - tst_vlockguard.cpp \ - tst_misc.cpp \ - tst_vcommandline.cpp \ - tst_tstranslation.cpp \ - tst_vdetail.cpp \ - tst_findpoint.cpp - -HEADERS += \ - tst_vposter.h \ - tst_vabstractdetail.h \ - tst_vspline.h \ - abstracttest.h \ - tst_nameregexp.h \ - tst_vlayoutdetail.h \ - tst_varc.h \ - stable.h \ - tst_measurementregexp.h \ - tst_tapecommandline.h \ - tst_valentinacommandline.h \ - tst_qmutokenparser.h \ - tst_vmeasurements.h \ - tst_qmuparsererrormsg.h \ - tst_vlockguard.h \ - tst_misc.h \ - tst_vcommandline.h \ - tst_tstranslation.h \ - tst_vdetail.h \ - tst_findpoint.h - -# Set using ccache. Function enable_ccache() defined in common.pri. -$$enable_ccache() - -DEFINES += TS_DIR=\\\"$${PWD}/../../../share/translations\\\" - -CONFIG(debug, debug|release){ - # Debug mode - unix { - #Turn on compilers warnings. - *-g++{ - QMAKE_CXXFLAGS += \ - # Key -isystem disable checking errors in system headers. - -isystem "$${OUT_PWD}/$${UI_DIR}" \ - -isystem "$${OUT_PWD}/$${MOC_DIR}" \ - -isystem "$${OUT_PWD}/$${RCC_DIR}" \ - $$GCC_DEBUG_CXXFLAGS # See common.pri for more details. - - noAddressSanitizer{ # For enable run qmake with CONFIG+=noAddressSanitizer - # do nothing - } else { - #gcc’s 4.8.0 Address Sanitizer - #http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/ - QMAKE_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer - QMAKE_CFLAGS += -fsanitize=address -fno-omit-frame-pointer - QMAKE_LFLAGS += -fsanitize=address - } - } - clang*{ - QMAKE_CXXFLAGS += \ - # Key -isystem disable checking errors in system headers. - -isystem "$${OUT_PWD}/$${UI_DIR}" \ - -isystem "$${OUT_PWD}/$${MOC_DIR}" \ - -isystem "$${OUT_PWD}/$${RCC_DIR}" \ - $$CLANG_DEBUG_CXXFLAGS \ # See common.pri for more details. - -Wno-gnu-zero-variadic-macro-arguments\ # See macros QSKIP - } - *-icc-*{ - QMAKE_CXXFLAGS += \ - -isystem "$${OUT_PWD}/$${UI_DIR}" \ - -isystem "$${OUT_PWD}/$${MOC_DIR}" \ - -isystem "$${OUT_PWD}/$${RCC_DIR}" \ - $$ICC_DEBUG_CXXFLAGS - } - } else { - *-g++{ - QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See common.pri for more details. - } - } -}else{ - # Release mode - !win32-msvc*:CONFIG += silent - DEFINES += V_NO_ASSERT - !unix:*-g++{ - QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll - } - - noDebugSymbols{ # For enable run qmake with CONFIG+=noDebugSymbols - # do nothing - } else { - # Turn on debug symbols in release mode on Unix systems. - # On Mac OS X temporarily disabled. Need find way how to strip binary file. - !macx:!win32-msvc*{ - QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3 - QMAKE_CFLAGS_RELEASE += -g -gdwarf-3 - QMAKE_LFLAGS_RELEASE = - } - } -} - -#VTools static library (depend on VWidgets, VMisc, VPatternDB) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vtools/$${DESTDIR}/ -lvtools - -INCLUDEPATH += $$PWD/../../libs/vtools -DEPENDPATH += $$PWD/../../libs/vtools - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a - -#VWidgets static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets - -INCLUDEPATH += $$PWD/../../libs/vwidgets -DEPENDPATH += $$PWD/../../libs/vwidgets - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a - -# VFormat static library (depend on VPatternDB, IFC) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat - -INCLUDEPATH += $$PWD/../../libs/vformat -DEPENDPATH += $$PWD/../../libs/vformat - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/vformat.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/libvformat.a - -#VPatternDB static library (depend on vgeometry, vmisc, VLayout) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb - -INCLUDEPATH += $$PWD/../../libs/vpatterndb -DEPENDPATH += $$PWD/../../libs/vpatterndb - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a - -#VMisc static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vmisc/$${DESTDIR}/ -lvmisc - -INCLUDEPATH += $$PWD/../../libs/vmisc -DEPENDPATH += $$PWD/../../libs/vmisc - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/vmisc.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/libvmisc.a - -# VGeometry static library (depend on ifc) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR} -lvgeometry - -INCLUDEPATH += $$PWD/../../libs/vgeometry -DEPENDPATH += $$PWD/../../libs/vgeometry - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a - -# IFC static library (depend on QMuParser) -unix|win32: LIBS += -L$$OUT_PWD/../../libs/ifc/$${DESTDIR}/ -lifc - -INCLUDEPATH += $$PWD/../../libs/ifc -DEPENDPATH += $$PWD/../../libs/ifc - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/ifc.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/libifc.a - -# VLayout static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout - -INCLUDEPATH += $$PWD/../../libs/vlayout -DEPENDPATH += $$PWD/../../libs/vlayout - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a - -# QMuParser library -win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 -else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 -else:unix: LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser - -INCLUDEPATH += $${PWD}/../../libs/qmuparser -DEPENDPATH += $${PWD}/../../libs/qmuparser - -# Only for adding path to LD_LIBRARY_PATH -# VPropertyExplorer library -win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer -else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer -else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer - -INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer -DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer - -TAPE_TEST_FILES += \ - tst_tape/keiko.vit \ - tst_tape/empty.vit \ - tst_tape/all_measurements_v0.3.0.vit \ - tst_tape/all_measurements_v0.4.0.vst \ - tst_tape/GOST_man_ru_v0.3.0.vst \ - tst_tape/all_measurements_v0.3.3.vit \ - tst_tape/all_measurements_v0.4.2.vst \ - tst_tape/GOST_man_ru_v0.4.2.vst \ - tst_tape/broken1.vit \ - tst_tape/broken2.vit \ - tst_tape/broken3.vit \ - tst_tape/broken4.vit \ - tst_tape/text.vit \ - tst_tape/text.vst - -VALENTINA_TEST_FILES += \ - tst_valentina/empty.val \ - tst_valentina/issue_372.val \ - tst_valentina/wrong_obj_type.val \ - tst_valentina/text.val \ - tst_valentina/glimited_no_m.val \ - tst_valentina/glimited_vit.val \ - tst_valentina/glimited.vit \ - tst_valentina/glimited_vst.val \ - tst_valentina/glimited.vst \ - tst_valentina/issue_256.val \ - tst_valentina/issue_256_wrong_path.val \ - tst_valentina/issue_256_correct.vit \ - tst_valentina/issue_256_wrong.vit \ - tst_valentina/issue_256_correct.vst \ - tst_valentina/issue_256_wrong.vit \ - tst_valentina/wrong_formula.val - -COLLECTION_FILES += \ - $${PWD}/../../app/share/tables/standard/GOST_man_ru.vst \ - $${PWD}/../../app/share/collection/bra.val \ - $${PWD}/../../app/share/collection/bra.vit \ - $${PWD}/../../app/share/collection/jacketМ1_52-176.val \ - $${PWD}/../../app/share/collection/jacketМ2_40-146.val \ - $${PWD}/../../app/share/collection/jacketМ3_40-146.val \ - $${PWD}/../../app/share/collection/jacketМ4_40-146.val \ - $${PWD}/../../app/share/collection/jacketМ5_30-110.val \ - $${PWD}/../../app/share/collection/jacketМ6_30-110.val \ - $${PWD}/../../app/share/collection/pantsМ1_52-176.val \ - $${PWD}/../../app/share/collection/pantsМ2_40-146.val \ - $${PWD}/../../app/share/collection/pantsМ7.val \ - $${PWD}/../../app/share/collection/TShirt_test.val \ - $${PWD}/../../app/share/collection/TestDart.val \ - $${PWD}/../../app/share/collection/patrón_blusa.val \ - $${PWD}/../../app/share/collection/blusa.vit \ - $${PWD}/../../app/share/collection/PajamaTopWrap2.val \ - $${PWD}/../../app/share/collection/Susan.vit \ - $${PWD}/../../app/share/collection/Moulage_0.5_armhole_neckline.val \ - $${PWD}/../../app/share/collection/0.7_Armhole_adjustment_0.10.val \ - $${PWD}/../../app/share/collection/my_calculated_measurements_for_val.vit \ - $${PWD}/../../app/share/collection/Keiko_skirt.val \ - $${PWD}/../../app/share/collection/keiko.vit \ - $${PWD}/../../app/share/collection/medidas_eli2015.vit \ - $${PWD}/../../app/share/collection/pantalon_base_Eli.val \ - $${PWD}/../../app/share/collection/Razmernye_priznaki_dlya_zhenskogo_zhaketa.vit \ - $${PWD}/../../app/share/collection/IMK_Zhaketa_poluprilegayuschego_silueta.val - - -# Compilation will fail without this files after we added them to this section. -OTHER_FILES += \ - $$TAPE_TEST_FILES \ - $$VALENTINA_TEST_FILES \ - $$COLLECTION_FILES - -for(DIR, TAPE_TEST_FILES) { - #add these absolute paths to a variable which - #ends up as 'mkcommands = path1 path2 path3 ...' - tape_path += $${PWD}/$$DIR -} - -copyToDestdir($$tape_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_tape)) - -for(DIR, VALENTINA_TEST_FILES) { - #add these absolute paths to a variable which - #ends up as 'mkcommands = path1 path2 path3 ...' - valentina_path += $${PWD}/$$DIR -} - -copyToDestdir($$valentina_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina)) - -for(DIR, COLLECTION_FILES) { - #add these absolute paths to a variable which - #ends up as 'mkcommands = path1 path2 path3 ...' - collection_path += $$DIR -} - -copyToDestdir($$collection_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina_collection)) +#------------------------------------------------- +# +# Project created by QtCreator 2015-03-31T17:27:03 +# +#------------------------------------------------- + +QT += testlib gui printsupport xml xmlpatterns + +TARGET = ValentinaTests + +# File with common stuff for whole project +include(../../../common.pri) + +# CONFIG += testcase adds a 'make check' which is great. But by default it also +# adds a 'make install' that installs the test cases, which we do not want. +# Can configure it not to do that with 'no_testcase_installs' +# We use C++11 standard +CONFIG += c++11 testcase no_testcase_installs + +# Use out-of-source builds (shadow builds) +CONFIG -= app_bundle debug_and_release debug_and_release_target + +TEMPLATE = app + +# directory for executable file +DESTDIR = bin + +# Directory for files created moc +MOC_DIR = moc + +# objecs files +OBJECTS_DIR = obj + +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +SOURCES += \ + qttestmainlambda.cpp \ + tst_vposter.cpp \ + tst_vabstractdetail.cpp \ + tst_vspline.cpp \ + abstracttest.cpp \ + tst_nameregexp.cpp \ + tst_vlayoutdetail.cpp \ + tst_varc.cpp \ + stable.cpp \ + tst_measurementregexp.cpp \ + tst_tapecommandline.cpp \ + tst_valentinacommandline.cpp \ + tst_qmutokenparser.cpp \ + tst_vmeasurements.cpp \ + tst_qmuparsererrormsg.cpp \ + tst_vlockguard.cpp \ + tst_misc.cpp \ + tst_vcommandline.cpp \ + tst_tstranslation.cpp \ + tst_vdetail.cpp \ + tst_findpoint.cpp \ + tst_vellipticalarc.cpp + +HEADERS += \ + tst_vposter.h \ + tst_vabstractdetail.h \ + tst_vspline.h \ + abstracttest.h \ + tst_nameregexp.h \ + tst_vlayoutdetail.h \ + tst_varc.h \ + stable.h \ + tst_measurementregexp.h \ + tst_tapecommandline.h \ + tst_valentinacommandline.h \ + tst_qmutokenparser.h \ + tst_vmeasurements.h \ + tst_qmuparsererrormsg.h \ + tst_vlockguard.h \ + tst_misc.h \ + tst_vcommandline.h \ + tst_tstranslation.h \ + tst_vdetail.h \ + tst_findpoint.h \ + tst_vellipticalarc.h + +# Set using ccache. Function enable_ccache() defined in common.pri. +$$enable_ccache() + +DEFINES += TS_DIR=\\\"$${PWD}/../../../share/translations\\\" + +CONFIG(debug, debug|release){ + # Debug mode + unix { + #Turn on compilers warnings. + *-g++{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${UI_DIR}" \ + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + -isystem "$${OUT_PWD}/$${RCC_DIR}" \ + $$GCC_DEBUG_CXXFLAGS # See common.pri for more details. + + noAddressSanitizer{ # For enable run qmake with CONFIG+=noAddressSanitizer + # do nothing + } else { + #gcc’s 4.8.0 Address Sanitizer + #http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/ + QMAKE_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer + QMAKE_CFLAGS += -fsanitize=address -fno-omit-frame-pointer + QMAKE_LFLAGS += -fsanitize=address + } + } + clang*{ + QMAKE_CXXFLAGS += \ + # Key -isystem disable checking errors in system headers. + -isystem "$${OUT_PWD}/$${UI_DIR}" \ + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + -isystem "$${OUT_PWD}/$${RCC_DIR}" \ + $$CLANG_DEBUG_CXXFLAGS \ # See common.pri for more details. + -Wno-gnu-zero-variadic-macro-arguments\ # See macros QSKIP + } + *-icc-*{ + QMAKE_CXXFLAGS += \ + -isystem "$${OUT_PWD}/$${UI_DIR}" \ + -isystem "$${OUT_PWD}/$${MOC_DIR}" \ + -isystem "$${OUT_PWD}/$${RCC_DIR}" \ + $$ICC_DEBUG_CXXFLAGS + } + } else { + *-g++{ + QMAKE_CXXFLAGS += $$GCC_DEBUG_CXXFLAGS # See common.pri for more details. + } + } +}else{ + # Release mode + !win32-msvc*:CONFIG += silent + DEFINES += V_NO_ASSERT + !unix:*-g++{ + QMAKE_CXXFLAGS += -fno-omit-frame-pointer # Need for exchndl.dll + } + + noDebugSymbols{ # For enable run qmake with CONFIG+=noDebugSymbols + # do nothing + } else { + # Turn on debug symbols in release mode on Unix systems. + # On Mac OS X temporarily disabled. Need find way how to strip binary file. + !macx:!win32-msvc*{ + QMAKE_CXXFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_CFLAGS_RELEASE += -g -gdwarf-3 + QMAKE_LFLAGS_RELEASE = + } + } +} + +#VTools static library (depend on VWidgets, VMisc, VPatternDB) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vtools/$${DESTDIR}/ -lvtools + +INCLUDEPATH += $$PWD/../../libs/vtools +DEPENDPATH += $$PWD/../../libs/vtools + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/vtools.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vtools/$${DESTDIR}/libvtools.a + +#VWidgets static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/ -lvwidgets + +INCLUDEPATH += $$PWD/../../libs/vwidgets +DEPENDPATH += $$PWD/../../libs/vwidgets + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/vwidgets.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vwidgets/$${DESTDIR}/libvwidgets.a + +# VFormat static library (depend on VPatternDB, IFC) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vformat/$${DESTDIR}/ -lvformat + +INCLUDEPATH += $$PWD/../../libs/vformat +DEPENDPATH += $$PWD/../../libs/vformat + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/vformat.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vformat/$${DESTDIR}/libvformat.a + +#VPatternDB static library (depend on vgeometry, vmisc, VLayout) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb + +INCLUDEPATH += $$PWD/../../libs/vpatterndb +DEPENDPATH += $$PWD/../../libs/vpatterndb + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a + +#VMisc static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vmisc/$${DESTDIR}/ -lvmisc + +INCLUDEPATH += $$PWD/../../libs/vmisc +DEPENDPATH += $$PWD/../../libs/vmisc + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/vmisc.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/libvmisc.a + +# VGeometry static library (depend on ifc) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR} -lvgeometry + +INCLUDEPATH += $$PWD/../../libs/vgeometry +DEPENDPATH += $$PWD/../../libs/vgeometry + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a + +# IFC static library (depend on QMuParser) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/ifc/$${DESTDIR}/ -lifc + +INCLUDEPATH += $$PWD/../../libs/ifc +DEPENDPATH += $$PWD/../../libs/ifc + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/ifc.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/libifc.a + +# VLayout static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a + +# QMuParser library +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:unix: LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser + +INCLUDEPATH += $${PWD}/../../libs/qmuparser +DEPENDPATH += $${PWD}/../../libs/qmuparser + +# Only for adding path to LD_LIBRARY_PATH +# VPropertyExplorer library +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:unix: LIBS += -L$${OUT_PWD}/../../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer + +INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer +DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer + +TAPE_TEST_FILES += \ + tst_tape/keiko.vit \ + tst_tape/empty.vit \ + tst_tape/all_measurements_v0.3.0.vit \ + tst_tape/all_measurements_v0.4.0.vst \ + tst_tape/GOST_man_ru_v0.3.0.vst \ + tst_tape/all_measurements_v0.3.3.vit \ + tst_tape/all_measurements_v0.4.2.vst \ + tst_tape/GOST_man_ru_v0.4.2.vst \ + tst_tape/broken1.vit \ + tst_tape/broken2.vit \ + tst_tape/broken3.vit \ + tst_tape/broken4.vit \ + tst_tape/text.vit \ + tst_tape/text.vst + +VALENTINA_TEST_FILES += \ + tst_valentina/empty.val \ + tst_valentina/issue_372.val \ + tst_valentina/wrong_obj_type.val \ + tst_valentina/text.val \ + tst_valentina/glimited_no_m.val \ + tst_valentina/glimited_vit.val \ + tst_valentina/glimited.vit \ + tst_valentina/glimited_vst.val \ + tst_valentina/glimited.vst \ + tst_valentina/issue_256.val \ + tst_valentina/issue_256_wrong_path.val \ + tst_valentina/issue_256_correct.vit \ + tst_valentina/issue_256_wrong.vit \ + tst_valentina/issue_256_correct.vst \ + tst_valentina/issue_256_wrong.vit \ + tst_valentina/wrong_formula.val + +COLLECTION_FILES += \ + $${PWD}/../../app/share/tables/standard/GOST_man_ru.vst \ + $${PWD}/../../app/share/collection/bra.val \ + $${PWD}/../../app/share/collection/bra.vit \ + $${PWD}/../../app/share/collection/jacketМ1_52-176.val \ + $${PWD}/../../app/share/collection/jacketМ2_40-146.val \ + $${PWD}/../../app/share/collection/jacketМ3_40-146.val \ + $${PWD}/../../app/share/collection/jacketМ4_40-146.val \ + $${PWD}/../../app/share/collection/jacketМ5_30-110.val \ + $${PWD}/../../app/share/collection/jacketМ6_30-110.val \ + $${PWD}/../../app/share/collection/pantsМ1_52-176.val \ + $${PWD}/../../app/share/collection/pantsМ2_40-146.val \ + $${PWD}/../../app/share/collection/pantsМ7.val \ + $${PWD}/../../app/share/collection/TShirt_test.val \ + $${PWD}/../../app/share/collection/TestDart.val \ + $${PWD}/../../app/share/collection/patrón_blusa.val \ + $${PWD}/../../app/share/collection/blusa.vit \ + $${PWD}/../../app/share/collection/PajamaTopWrap2.val \ + $${PWD}/../../app/share/collection/Susan.vit \ + $${PWD}/../../app/share/collection/Moulage_0.5_armhole_neckline.val \ + $${PWD}/../../app/share/collection/0.7_Armhole_adjustment_0.10.val \ + $${PWD}/../../app/share/collection/my_calculated_measurements_for_val.vit \ + $${PWD}/../../app/share/collection/Keiko_skirt.val \ + $${PWD}/../../app/share/collection/keiko.vit \ + $${PWD}/../../app/share/collection/medidas_eli2015.vit \ + $${PWD}/../../app/share/collection/pantalon_base_Eli.val \ + $${PWD}/../../app/share/collection/Razmernye_priznaki_dlya_zhenskogo_zhaketa.vit \ + $${PWD}/../../app/share/collection/IMK_Zhaketa_poluprilegayuschego_silueta.val + + +# Compilation will fail without this files after we added them to this section. +OTHER_FILES += \ + $$TAPE_TEST_FILES \ + $$VALENTINA_TEST_FILES \ + $$COLLECTION_FILES + +for(DIR, TAPE_TEST_FILES) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + tape_path += $${PWD}/$$DIR +} + +copyToDestdir($$tape_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_tape)) + +for(DIR, VALENTINA_TEST_FILES) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + valentina_path += $${PWD}/$$DIR +} + +copyToDestdir($$valentina_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina)) + +for(DIR, COLLECTION_FILES) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + collection_path += $$DIR +} + +copyToDestdir($$collection_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina_collection)) diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index bad3060f0..b1a4f4e1d 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -34,6 +34,7 @@ #include "tst_nameregexp.h" #include "tst_vlayoutdetail.h" #include "tst_varc.h" +#include "tst_vellipticalarc.h" #include "tst_measurementregexp.h" #include "tst_tapecommandline.h" #include "tst_valentinacommandline.h" @@ -68,6 +69,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_NameRegExp()); ASSERT_TEST(new TST_VLayoutDetail()); ASSERT_TEST(new TST_VArc()); + ASSERT_TEST(new TST_VEllipticalArc()); ASSERT_TEST(new TST_MeasurementRegExp()); ASSERT_TEST(new TST_TapeCommandLine()); ASSERT_TEST(new TST_ValentinaCommandLine()); diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp new file mode 100644 index 000000000..6ec4e2e37 --- /dev/null +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -0,0 +1,283 @@ +/************************************************************************ + ** + ** @file tst_vellipticalarc.cpp + ** @author Valentina Zhuravska + ** @date 12 2, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_vellipticalarc.h" +#include "../vgeometry/vellipticalarc.h" +#include "../vlayout/vabstractdetail.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_VEllipticalArc::TST_VEllipticalArc(QObject *parent) : QObject(parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::CompareTwoWays() +{ + const VPointF center; + const qreal radius1 = 100; + const qreal radius2 = 200; + const qreal f1 = 0; + const qreal f2 = 90; + const qreal rotationAngle = 0; + + const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); + const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/4; + + VEllipticalArc arc1(center, radius1, radius2, f1, f2, rotationAngle); + VEllipticalArc arc2(length, center, radius1, radius2, f1); + + const qreal eps = length*0.5/100; // computing error + const QString errorMsg = + QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); + QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); + //QVERIFY2(arc2.GetLength() - length <= eps, qUtf8Printable(errorMsg)); + //QVERIFY2(arc1.GetLength() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); + + // compare angles + //QVERIFY2(arc1.GetEndAngle() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); + //QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); + //QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::NegativeArc() +{ + const VPointF center; + const qreal radius1 = 100; + const qreal radius2 = 200; + const qreal f1 = 1; + const qreal f2 = 181; + + const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); + const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; + VEllipticalArc arc(-length, center, radius1, radius2, f1); + + const qreal eps = 1; // computing error + const QString errorMsg = + QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); + + //QVERIFY2(qAbs(arc.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); + //QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); +} + +// cppcheck-suppress unusedFunction +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestGetPoints_data() +{ + QTest::addColumn("radius1"); + QTest::addColumn("radius2"); + QTest::addColumn("startAngle"); + QTest::addColumn("endAngle"); + QTest::addColumn("rotationAngle"); + + QTest::newRow("Full circle: radiuses 10, 20") << 10.0 << 20.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 150, 200") << 150.0 << 200.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 90000, 80000") << 90000.0 << 80000.0 << 0.0 << 360.0 << 0.0; + + QTest::newRow("Arc less than 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 10.5 << 0.0; + QTest::newRow("Arc less than 45 degree, radiuses 150, 50") << 150.0 << 50.0 << 0.0 << 10.5 << 0.0; + QTest::newRow("Arc less than 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 10.5 << 0.0; + QTest::newRow("Arc less than 45 degree, radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 10.5 << 0.0; + QTest::newRow("Arc less than 45 degree, radiuses 90000, 10000") << 90000.0 << 10000.0 << 0.0 << 10.5 << 0.0; + + QTest::newRow("Arc 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 150, 15") << 150.0 << 15.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 1500, 150") << 1500.0 << 150.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 50000, 50000") << 50000.0 << 50000.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 45.0 << 0.0; + + QTest::newRow("Arc less than 90 degree, radiuses 100, 400") << 100.0 << 400.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000") << 1500.0 << 50000.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 75.0 << 0.0; + + QTest::newRow("Arc 90 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 90.0 << 0.0; + + QTest::newRow("Arc less than 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 110.6 << 0.0; + QTest::newRow("Arc less than 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 110.6 << 0.0; + QTest::newRow("Arc less than 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 110.6 << 0.0; + QTest::newRow("Arc less than 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 110.6 << 0.0; + QTest::newRow("Arc less than 135 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 110.6 << 0.0; + + QTest::newRow("Arc 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 135.0 << 0.0; + QTest::newRow("Arc 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 135.0 << 0.0; + QTest::newRow("Arc 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 135.0 << 0.0; + QTest::newRow("Arc 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 135.0 << 0.0; + QTest::newRow("Arc 135 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 135.0 << 0.0; + + QTest::newRow("Arc less than 180 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 160.7 << 0.0; + QTest::newRow("Arc less than 180 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 160.7 << 0.0; + QTest::newRow("Arc less than 180 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 160.7 << 0.0; + QTest::newRow("Arc less than 180 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 160.7 << 0.0; + QTest::newRow("Arc less than 180 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 160.7 << 0.0; + + QTest::newRow("Arc 180 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 180.0 << 0.0; + QTest::newRow("Arc 180 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 180.0 << 0.0; + QTest::newRow("Arc 180 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 180.0 << 0.0; + QTest::newRow("Arc 180 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 180.0 << 0.0; + QTest::newRow("Arc 180 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 180.0 << 0.0; + + QTest::newRow("Arc less than 270 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 150.3 << 0.0; + QTest::newRow("Arc less than 270 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 150.3 << 0.0; + QTest::newRow("Arc less than 270 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 150.3 << 0.0; + QTest::newRow("Arc less than 270 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 150.3 << 0.0; + QTest::newRow("Arc less than 270 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 150.3 << 0.0; + + QTest::newRow("Arc 270 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 270.0 << 0.0; + QTest::newRow("Arc 270 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 270.0 << 0.0; + QTest::newRow("Arc 270 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 270.0 << 0.0; + QTest::newRow("Arc 270 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 270.0 << 0.0; + QTest::newRow("Arc 270 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 270.0 << 0.0; + + QTest::newRow("Arc less than 360 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 340.0 << 0.0; + QTest::newRow("Arc less than 360 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 340.0 << 0.0; + QTest::newRow("Arc less than 360 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 340.0 << 0.0; + QTest::newRow("Arc less than 360 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 340.0 << 0.0; + QTest::newRow("Arc less than 360 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 340.0 << 0.0; + + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 150, 400") << 150.0 << 400.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 90.0 << 135.0 << 0.0; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::TestGetPoints() +{ + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(qreal, rotationAngle); + + const VPointF center; + VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); + + QVector points = arc.GetPoints(); + { + qreal eps = 0.5; + const QString errorMsg = QString("Broken the first rule, part 1. Any point must satisfy the equation of ellipse."); + for (int i=0; i < points.size(); ++i) + { + QPointF p = points.at(i); + const qreal equationRes = p.rx()*p.rx()/(radius1*radius1) + p.ry()*p.ry()/(radius2*radius2); + const qreal diff = qAbs(equationRes - 1); + QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); + } + } + { + const qreal c = qSqrt(qAbs(radius2*radius2 - radius1*radius1)); + // distance from the center to the focus + + QPointF focus1 = center.toQPointF(); + QPointF focus2 = center.toQPointF(); + + if (radius1 < radius2) + { + focus1.setY(focus1.ry() + c); + QLineF line(center.toQPointF(), focus1); + line.setAngle(line.angle() + rotationAngle); + focus1 = line.p2(); + + focus2.setY(focus2.ry() - c); + line.setP2(focus2); + line.setAngle(line.angle() + rotationAngle); + focus2 = line.p2(); + } + else + { + focus1.setX(focus1.rx() + c); + QLineF line(center.toQPointF(), focus1); + line.setAngle(line.angle() + rotationAngle); + focus1 = line.p2(); + + focus2.setX(focus2.rx() - c); + line.setP2(focus2); + line.setAngle(line.angle() + rotationAngle); + focus2 = line.p2(); + } + + QPointF ellipsePoint(center.x() + radius1, center.y()); + QLineF line(center.toQPointF(), ellipsePoint); + line.setAngle(line.angle() + rotationAngle); + ellipsePoint = line.p2(); + + const QLineF distance1(focus1, ellipsePoint); + const QLineF distance2(focus2, ellipsePoint); + + const qreal distance = distance1.length() + distance2.length(); + const qreal eps = distance * 0.5/ 100; // computing error 0.5 % from origin distance + for (int i=0; i < points.size(); ++i) + { + const QLineF rLine1(focus1, points.at(i)); + const QLineF rLine2(focus2, points.at(i)); + const qreal resultingDistance = rLine1.length()+rLine2.length(); + const qreal diff = qAbs(resultingDistance - distance); + const QString errorMsg = QString("Broken the first rule, part 2. Distance from the any point to the focus1 plus" + " distance from this point to the focus2 should be the same. Problem with point '%1'." + " The disired distance is '%2', but resulting distance is '%3'. Difference is '%4' and it" + " biggest than eps ('%5')").arg(i).arg(distance).arg(resultingDistance).arg(diff).arg(eps); + QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); + } + } + { + if (qFuzzyCompare(arc.AngleArc(), 360.0)) + {// calculated full ellipse square + const qreal ellipseSquare = M_PI * radius1 * radius2; + const qreal epsSquare = ellipseSquare * 0.24 / 100; // computing error 0.24 % from origin squere + const qreal arcSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); + const qreal diffSquare = qAbs(ellipseSquare - arcSquare); + const QString errorMsg1 = QString("Broken the second rule. Interpolation has too big computing error. " + "Difference ='%1' bigger than eps = '%2'.").arg(diffSquare).arg(epsSquare); + QVERIFY2(diffSquare <= epsSquare, qUtf8Printable(errorMsg1)); + + // calculated full ellipse length + const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); + const qreal ellipseLength = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h))); + const qreal epsLength = ellipseLength*0.5/100; // computing error + VEllipticalArc arc(center, radius1, radius2, 0, 360, 0); + const qreal arcLength = arc.GetLength(); + const qreal diffLength = qAbs(arcLength - ellipseLength); + const QString errorMsg2 = QString("Difference between real and computing lengthes " + "(diff = '%1') bigger than eps = '%2'.").arg(diffLength).arg(epsLength); + QVERIFY2(diffLength <= epsLength, qUtf8Printable(errorMsg2)); + } + } +} diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h new file mode 100644 index 000000000..21a0a408f --- /dev/null +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file tst_vellipticalarc.h + ** @author Valentina Zhuravska + ** @date 12 2, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_VELLIPTICALARC_H +#define TST_VELLIPTICALARC_H + +#include + +class TST_VEllipticalArc : public QObject +{ + Q_OBJECT +public: + explicit TST_VEllipticalArc(QObject *parent = 0); + +private slots: + void CompareTwoWays(); + void NegativeArc(); + void TestGetPoints_data(); + void TestGetPoints(); +}; + +#endif // TST_VELLIPTICALARC_H From 03086c946ea194b71ddb1464d10d73658b5c35ec Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 19 Feb 2016 11:47:22 +0200 Subject: [PATCH 07/21] Fixed GetPoint function in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 55 ++++++++++++++++++--------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 99d474342..221ab0946 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -150,14 +150,7 @@ qreal VEllipticalArc::GetLength() const */ QPointF VEllipticalArc::GetP1() const { - // p1 - point without rotation - 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 - QLineF line(GetCenter().toQPointF(), p1); - line.setAngle(line.angle() + GetRotationAngle()); - - return line.p2(); + return GetPoint(d->f1); } //--------------------------------------------------------------------------------------------------------------------- @@ -167,14 +160,7 @@ QPointF VEllipticalArc::GetP1() const */ QPointF VEllipticalArc::GetP2 () const { - // p2 - point without rotation - 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 - QLineF line(GetCenter().toQPointF(), p2); - line.setAngle(line.angle() + GetRotationAngle()); - - return line.p2(); + return GetPoint(d->f2); } //--------------------------------------------------------------------------------------------------------------------- @@ -184,9 +170,42 @@ QPointF VEllipticalArc::GetP2 () const */ QPointF VEllipticalArc::GetPoint (qreal angle) const { + if (angle > 360 || angle < 0) + {// Filter incorect value of angle + QLineF dummy(0,0, 100, 0); + dummy.setAngle(angle); + angle = dummy.angle(); + } + // 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))); + qreal x = qAbs((d->radius1 * d->radius2)/ + (qSqrt(d->radius2*d->radius2+d->radius1*d->radius1*qTan(M_PI*angle/180)*qTan(M_PI*angle/180)))); + qreal y = qAbs(qTan(M_PI*angle/180) * x); + + if (angle > 90 && angle <= 180) + { + x = -x; + } + else if (angle > 180 && angle < 270) + { + x = -x; + y = -y; + } + else if (angle > 270) + { + y = -y; + } + else if (angle == 90) + { + x = 0; + y = d->radius2; + } + else if (angle == 270) + { + x = 0; + y = -d->radius2; + } + QPointF p ( GetCenter().x () + x, GetCenter().y () + y); // rotation of point QLineF line(GetCenter().toQPointF(), p); line.setAngle(line.angle() + GetRotationAngle()); From da2c6d32420d05d076ab1bc748f4c3c2776ceb26 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 19 Feb 2016 11:47:42 +0200 Subject: [PATCH 08/21] Fixed GetPoints function in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 221ab0946..a89276dbb 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -288,9 +288,6 @@ QVector VEllipticalArc::GetPoints() const QVector points; QVector 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) { @@ -298,14 +295,20 @@ QVector VEllipticalArc::GetPoints() const } else { - for (int i = 0; i < sectionAngle.size()-1; ++i) + qreal currentAngle; + d->isFlipped ? currentAngle = GetEndAngle() : currentAngle = GetStartAngle(); + for (int i = 0; i < sectionAngle.size(); ++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)); + QPointF startPoint = GetPoint(currentAngle); + QPointF ellipsePoint2 = GetPoint(currentAngle + sectionAngle.at(i)/3); + QPointF ellipsePoint3 = GetPoint(currentAngle + 2*sectionAngle.at(i)/3); + QPointF lastPoint = GetPoint(currentAngle + sectionAngle.at(i)); + // four points that are on ellipse - VSpline spl(VPointF(firstPoint), point2, point3, VPointF(lastPoint), 1.0); + QPointF bezierPoint1 = ( -5*startPoint + 18*ellipsePoint2 -9*ellipsePoint3 + 2*lastPoint )/6; + QPointF bezierPoint2 = ( 2*startPoint - 9*ellipsePoint2 + 18*ellipsePoint3 - 5*lastPoint )/6; + + VSpline spl(VPointF(startPoint), bezierPoint1, bezierPoint2, VPointF(lastPoint), 1.0); QVector splPoints = spl.GetPoints(); @@ -314,6 +317,7 @@ QVector VEllipticalArc::GetPoints() const splPoints.removeLast(); } points << splPoints; + currentAngle += sectionAngle.at(i); } } return points; From e1837d1b0381ce7857fddb0119ebb2f6567489c0 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 24 Feb 2016 17:31:44 +0200 Subject: [PATCH 09/21] Little optimization: change parent = 0 to parent = nullptr --HG-- branch : feature --- src/test/ValentinaTest/abstracttest.h | 2 +- src/test/ValentinaTest/tst_measurementregexp.h | 2 +- src/test/ValentinaTest/tst_nameregexp.h | 2 +- src/test/ValentinaTest/tst_qmutokenparser.h | 2 +- src/test/ValentinaTest/tst_tapecommandline.h | 2 +- src/test/ValentinaTest/tst_tstranslation.h | 2 +- src/test/ValentinaTest/tst_vabstractdetail.h | 2 +- src/test/ValentinaTest/tst_valentinacommandline.h | 2 +- src/test/ValentinaTest/tst_varc.h | 2 +- src/test/ValentinaTest/tst_vellipticalarc.h | 5 ++++- src/test/ValentinaTest/tst_vlayoutdetail.h | 2 +- src/test/ValentinaTest/tst_vposter.h | 2 +- src/test/ValentinaTest/tst_vspline.h | 2 +- 13 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/test/ValentinaTest/abstracttest.h b/src/test/ValentinaTest/abstracttest.h index 1932c7347..750e8a153 100644 --- a/src/test/ValentinaTest/abstracttest.h +++ b/src/test/ValentinaTest/abstracttest.h @@ -46,7 +46,7 @@ class AbstractTest : public QObject { Q_OBJECT public: - explicit AbstractTest(QObject *parent = 0); + explicit AbstractTest(QObject *parent = nullptr); protected: void Comparison(const QVector &ekv, const QVector &ekvOrig) const; diff --git a/src/test/ValentinaTest/tst_measurementregexp.h b/src/test/ValentinaTest/tst_measurementregexp.h index f9004585e..322a6e9d9 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.h +++ b/src/test/ValentinaTest/tst_measurementregexp.h @@ -40,7 +40,7 @@ class TST_MeasurementRegExp : public AbstractTest { Q_OBJECT public: - explicit TST_MeasurementRegExp(QObject *parent = 0); + explicit TST_MeasurementRegExp(QObject *parent = nullptr); virtual ~TST_MeasurementRegExp() Q_DECL_OVERRIDE; private slots: diff --git a/src/test/ValentinaTest/tst_nameregexp.h b/src/test/ValentinaTest/tst_nameregexp.h index fc20cc349..12e863bea 100644 --- a/src/test/ValentinaTest/tst_nameregexp.h +++ b/src/test/ValentinaTest/tst_nameregexp.h @@ -35,7 +35,7 @@ class TST_NameRegExp : public QObject { Q_OBJECT public: - explicit TST_NameRegExp(QObject *parent = 0); + explicit TST_NameRegExp(QObject *parent = nullptr); signals: diff --git a/src/test/ValentinaTest/tst_qmutokenparser.h b/src/test/ValentinaTest/tst_qmutokenparser.h index 1431594d3..22930d27d 100644 --- a/src/test/ValentinaTest/tst_qmutokenparser.h +++ b/src/test/ValentinaTest/tst_qmutokenparser.h @@ -36,7 +36,7 @@ class TST_QmuTokenParser : public QObject Q_OBJECT public: Q_DISABLE_COPY(TST_QmuTokenParser) - explicit TST_QmuTokenParser(QObject *parent = 0); + explicit TST_QmuTokenParser(QObject *parent = nullptr); private slots: void IsSingle_data(); diff --git a/src/test/ValentinaTest/tst_tapecommandline.h b/src/test/ValentinaTest/tst_tapecommandline.h index a1ab5b18f..0206497e4 100644 --- a/src/test/ValentinaTest/tst_tapecommandline.h +++ b/src/test/ValentinaTest/tst_tapecommandline.h @@ -35,7 +35,7 @@ class TST_TapeCommandLine : public AbstractTest { Q_OBJECT public: - explicit TST_TapeCommandLine(QObject *parent = 0); + explicit TST_TapeCommandLine(QObject *parent = nullptr); private slots: void init(); diff --git a/src/test/ValentinaTest/tst_tstranslation.h b/src/test/ValentinaTest/tst_tstranslation.h index 3bac4e1e3..fb7fa45e3 100644 --- a/src/test/ValentinaTest/tst_tstranslation.h +++ b/src/test/ValentinaTest/tst_tstranslation.h @@ -38,7 +38,7 @@ class TST_TSTranslation : public QObject { Q_OBJECT public: - explicit TST_TSTranslation(QObject *parent = 0); + explicit TST_TSTranslation(QObject *parent = nullptr); private slots: void CheckEnglishLocalization(); diff --git a/src/test/ValentinaTest/tst_vabstractdetail.h b/src/test/ValentinaTest/tst_vabstractdetail.h index fc8759e92..ea45ab650 100644 --- a/src/test/ValentinaTest/tst_vabstractdetail.h +++ b/src/test/ValentinaTest/tst_vabstractdetail.h @@ -35,7 +35,7 @@ class TST_VAbstractDetail : public AbstractTest { Q_OBJECT public: - explicit TST_VAbstractDetail(QObject *parent = 0); + explicit TST_VAbstractDetail(QObject *parent = nullptr); signals: diff --git a/src/test/ValentinaTest/tst_valentinacommandline.h b/src/test/ValentinaTest/tst_valentinacommandline.h index eb3459436..92c3db54a 100644 --- a/src/test/ValentinaTest/tst_valentinacommandline.h +++ b/src/test/ValentinaTest/tst_valentinacommandline.h @@ -35,7 +35,7 @@ class TST_ValentinaCommandLine : public AbstractTest { Q_OBJECT public: - explicit TST_ValentinaCommandLine(QObject *parent = 0); + explicit TST_ValentinaCommandLine(QObject *parent = nullptr); private slots: void init(); diff --git a/src/test/ValentinaTest/tst_varc.h b/src/test/ValentinaTest/tst_varc.h index de4ce7eb7..997533627 100644 --- a/src/test/ValentinaTest/tst_varc.h +++ b/src/test/ValentinaTest/tst_varc.h @@ -35,7 +35,7 @@ class TST_VArc : public QObject { Q_OBJECT public: - explicit TST_VArc(QObject *parent = 0); + explicit TST_VArc(QObject *parent = nullptr); private slots: void CompareTwoWays(); diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h index 21a0a408f..7a9e67c4b 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.h +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -35,13 +35,16 @@ class TST_VEllipticalArc : public QObject { Q_OBJECT public: - explicit TST_VEllipticalArc(QObject *parent = 0); + explicit TST_VEllipticalArc(QObject *parent = nullptr); private slots: void CompareTwoWays(); void NegativeArc(); void TestGetPoints_data(); void TestGetPoints(); + +private: + Q_DISABLE_COPY(TST_VEllipticalArc) }; #endif // TST_VELLIPTICALARC_H diff --git a/src/test/ValentinaTest/tst_vlayoutdetail.h b/src/test/ValentinaTest/tst_vlayoutdetail.h index 2b0f08509..e67988ccf 100644 --- a/src/test/ValentinaTest/tst_vlayoutdetail.h +++ b/src/test/ValentinaTest/tst_vlayoutdetail.h @@ -35,7 +35,7 @@ class TST_VLayoutDetail : public AbstractTest { Q_OBJECT public: - explicit TST_VLayoutDetail(QObject *parent = 0); + explicit TST_VLayoutDetail(QObject *parent = nullptr); private slots: void RemoveDublicates() const; diff --git a/src/test/ValentinaTest/tst_vposter.h b/src/test/ValentinaTest/tst_vposter.h index 6fd218d1f..bb403da84 100644 --- a/src/test/ValentinaTest/tst_vposter.h +++ b/src/test/ValentinaTest/tst_vposter.h @@ -38,7 +38,7 @@ class TST_VPoster : public QObject Q_OBJECT public: - explicit TST_VPoster(QObject *parent = 0); + explicit TST_VPoster(QObject *parent = nullptr); signals: diff --git a/src/test/ValentinaTest/tst_vspline.h b/src/test/ValentinaTest/tst_vspline.h index efcf8b2f4..6891b6675 100644 --- a/src/test/ValentinaTest/tst_vspline.h +++ b/src/test/ValentinaTest/tst_vspline.h @@ -35,7 +35,7 @@ class TST_VSpline : public AbstractTest { Q_OBJECT public: - explicit TST_VSpline(QObject *parent = 0); + explicit TST_VSpline(QObject *parent = nullptr); signals: From 06637f2103185c8368ce0da812e48ca7052cba52 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 24 Feb 2016 17:34:03 +0200 Subject: [PATCH 10/21] Added FindF2 in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 39 ++++++++++++++++++- src/test/ValentinaTest/tst_vellipticalarc.cpp | 17 ++++---- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index a89276dbb..a2d206c8b 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -361,7 +361,44 @@ void VEllipticalArc::EllipticalArcName() //--------------------------------------------------------------------------------------------------------------------- void VEllipticalArc::FindF2(qreal length) { - // We need to calculate the second angle, + qreal gap = 180; + if (length < 0) + { + //length = qAbs(length); + d->isFlipped = true; + gap = -gap; + } + while (length > MaxLength()) + { + //length = length - MaxLength(); + } + + // We need to calculate the second angle + // first approximation of angle between start and end angles + + qreal endAngle = GetStartAngle() + gap; + d->f2 = endAngle; // we need to set the end anngle, because we want to use GetLength() + + qreal lenBez = GetLength(); // first approximation of length + + qreal eps = 0.001 * qAbs(length); + + while (qAbs(lenBez - length) > eps) + { + gap = gap/2; + if (lenBez > length) + { // we selected too big end angle + endAngle = endAngle - qAbs(gap); + } + else + { // we selected too little end angle + endAngle = endAngle + qAbs(gap); + } + d->f2 = endAngle; + lenBez = GetLength(); + } + d->formulaF2 = QString("%1").arg(d->f2); + d->formulaLength = QString("%1").arg(lenBez); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 6ec4e2e37..22c429aaf 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -57,13 +57,13 @@ void TST_VEllipticalArc::CompareTwoWays() const QString errorMsg = QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); - //QVERIFY2(arc2.GetLength() - length <= eps, qUtf8Printable(errorMsg)); - //QVERIFY2(arc1.GetLength() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc2.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= eps, qUtf8Printable(errorMsg)); // compare angles - //QVERIFY2(arc1.GetEndAngle() - arc2.GetEndAngle() <= eps, qUtf8Printable(errorMsg)); - //QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); - //QVERIFY2(arc1.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - arc2.GetEndAngle()) <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc1.GetEndAngle() - f2) <= eps, qUtf8Printable(errorMsg)); } //--------------------------------------------------------------------------------------------------------------------- @@ -78,14 +78,15 @@ void TST_VEllipticalArc::NegativeArc() const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; - VEllipticalArc arc(-length, center, radius1, radius2, f1); + qreal l = -length; + VEllipticalArc arc(l, center, radius1, radius2, f1); const qreal eps = 1; // computing error const QString errorMsg = QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); - //QVERIFY2(qAbs(arc.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); - //QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(qAbs(arc.GetLength() + length) <= eps, qUtf8Printable(errorMsg)); + QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); } // cppcheck-suppress unusedFunction From 389504b548f513bb9ef603512cb922e44fb1bb40 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Wed, 24 Feb 2016 17:34:33 +0200 Subject: [PATCH 11/21] Fixed GetPoints in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 48 +++++++++++---------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index a2d206c8b..2d026f07e 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -288,37 +288,29 @@ QVector VEllipticalArc::GetPoints() const QVector points; QVector sectionAngle = GetAngles(); - // if angle1 == angle2 and we have just one point of arc - if(sectionAngle.size() == 1) + qreal currentAngle; + d->isFlipped ? currentAngle = GetEndAngle() : currentAngle = GetStartAngle(); + for (int i = 0; i < sectionAngle.size(); ++i) { - points.append(GetP1()); - } - else - { - qreal currentAngle; - d->isFlipped ? currentAngle = GetEndAngle() : currentAngle = GetStartAngle(); - for (int i = 0; i < sectionAngle.size(); ++i) + QPointF startPoint = GetPoint(currentAngle); + QPointF ellipsePoint2 = GetPoint(currentAngle + sectionAngle.at(i)/3); + QPointF ellipsePoint3 = GetPoint(currentAngle + 2*sectionAngle.at(i)/3); + QPointF lastPoint = GetPoint(currentAngle + sectionAngle.at(i)); + // four points that are on ellipse + + QPointF bezierPoint1 = ( -5*startPoint + 18*ellipsePoint2 -9*ellipsePoint3 + 2*lastPoint )/6; + QPointF bezierPoint2 = ( 2*startPoint - 9*ellipsePoint2 + 18*ellipsePoint3 - 5*lastPoint )/6; + + VSpline spl(VPointF(startPoint), bezierPoint1, bezierPoint2, VPointF(lastPoint), 1.0); + + QVector splPoints = spl.GetPoints(); + + if (not splPoints.isEmpty() && i != sectionAngle.size() - 1) { - QPointF startPoint = GetPoint(currentAngle); - QPointF ellipsePoint2 = GetPoint(currentAngle + sectionAngle.at(i)/3); - QPointF ellipsePoint3 = GetPoint(currentAngle + 2*sectionAngle.at(i)/3); - QPointF lastPoint = GetPoint(currentAngle + sectionAngle.at(i)); - // four points that are on ellipse - - QPointF bezierPoint1 = ( -5*startPoint + 18*ellipsePoint2 -9*ellipsePoint3 + 2*lastPoint )/6; - QPointF bezierPoint2 = ( 2*startPoint - 9*ellipsePoint2 + 18*ellipsePoint3 - 5*lastPoint )/6; - - VSpline spl(VPointF(startPoint), bezierPoint1, bezierPoint2, VPointF(lastPoint), 1.0); - - QVector splPoints = spl.GetPoints(); - - if (not splPoints.isEmpty() && i != sectionAngle.size() - 1) - { - splPoints.removeLast(); - } - points << splPoints; - currentAngle += sectionAngle.at(i); + splPoints.removeLast(); } + points << splPoints; + currentAngle += sectionAngle.at(i); } return points; } From bea2a32e8526f27c1bbbb42a60489414c9694298 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Thu, 25 Feb 2016 02:18:52 +0200 Subject: [PATCH 12/21] Divide one big test into several little tests in TST_VEllipticalArc --HG-- branch : feature --- src/test/ValentinaTest/tst_vellipticalarc.cpp | 263 +++++++++++------- src/test/ValentinaTest/tst_vellipticalarc.h | 11 +- 2 files changed, 177 insertions(+), 97 deletions(-) diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 22c429aaf..a30a2ae01 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -91,7 +91,31 @@ void TST_VEllipticalArc::NegativeArc() // cppcheck-suppress unusedFunction //--------------------------------------------------------------------------------------------------------------------- -void TST_VEllipticalArc::TestGetPoints_data() +void TST_VEllipticalArc::TestGetPoints1_data() +{ + TestData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestGetPoints2_data() +{ + TestData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestGetPoints3_data() +{ + TestData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestGetPoints4_data() +{ + TestData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VEllipticalArc::TestData() { QTest::addColumn("radius1"); QTest::addColumn("radius2"); @@ -100,39 +124,39 @@ void TST_VEllipticalArc::TestGetPoints_data() QTest::addColumn("rotationAngle"); QTest::newRow("Full circle: radiuses 10, 20") << 10.0 << 20.0 << 0.0 << 360.0 << 0.0; - QTest::newRow("Full circle: radiuses 150, 200") << 150.0 << 200.0 << 0.0 << 360.0 << 0.0; - QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 150, 200") << 150.0 << 200.0 << 0.0 << 360.0 << 30.0; + QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 50.0; QTest::newRow("Full circle: radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 360.0 << 0.0; - QTest::newRow("Full circle: radiuses 90000, 80000") << 90000.0 << 80000.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 90000, 80000") << 90000.0 << 80000.0 << 0.0 << 360.0 << 90.0; QTest::newRow("Arc less than 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc less than 45 degree, radiuses 150, 50") << 150.0 << 50.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc less than 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc less than 45 degree, radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 10.5 << 0.0; + QTest::newRow("Arc less than 45 degree, radiuses 150, 50") << 150.0 << 50.0 << 0.0 << 10.5 << 180.0; + QTest::newRow("Arc less than 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 10.5 << 90.0; + QTest::newRow("Arc less than 45 degree, radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 10.5 << 40.0; QTest::newRow("Arc less than 45 degree, radiuses 90000, 10000") << 90000.0 << 10000.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 45.0 << 0.0; - QTest::newRow("Arc 45 degree, radiuses 150, 15") << 150.0 << 15.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 45.0 << 45.0; + QTest::newRow("Arc 45 degree, radiuses 150, 15") << 150.0 << 15.0 << 0.0 << 45.0 << 30.0; QTest::newRow("Arc 45 degree, radiuses 1500, 150") << 1500.0 << 150.0 << 0.0 << 45.0 << 0.0; QTest::newRow("Arc 45 degree, radiuses 50000, 50000") << 50000.0 << 50000.0 << 0.0 << 45.0 << 0.0; - QTest::newRow("Arc 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 45.0 << 270.0; - QTest::newRow("Arc less than 90 degree, radiuses 100, 400") << 100.0 << 400.0 << 0.0 << 75.0 << 0.0; - QTest::newRow("Arc less than 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 75.0 << 0.0; - QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000") << 1500.0 << 50000.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 100, 400") << 100.0 << 400.0 << 0.0 << 75.0 << 50.0; + QTest::newRow("Arc less than 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 75.0 << 90.0; + QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000") << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 75.0 << 0.0; - QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; - QTest::newRow("Arc 90 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 90.0 << 30.0; QTest::newRow("Arc 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 90.0 << 0.0; - QTest::newRow("Arc 90 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 90.0 << 0.0; - QTest::newRow("Arc 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 90.0 << 0.0; - QTest::newRow("Arc 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 90.0 << 0.0; + QTest::newRow("Arc 90 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 90.0 << 70.0; + QTest::newRow("Arc 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 90.0 << 30.0; + QTest::newRow("Arc 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 90.0 << 235.0; - QTest::newRow("Arc less than 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 110.6 << 0.0; - QTest::newRow("Arc less than 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 110.6 << 0.0; - QTest::newRow("Arc less than 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 110.6 << 0.0; - QTest::newRow("Arc less than 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 110.6 << 0.0; + QTest::newRow("Arc less than 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 110.6 << 60.0; + QTest::newRow("Arc less than 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 110.6 << 300.0; + QTest::newRow("Arc less than 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 110.6 << 360.0; + QTest::newRow("Arc less than 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 110.6 << 290.0; QTest::newRow("Arc less than 135 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 110.6 << 0.0; QTest::newRow("Arc 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 135.0 << 0.0; @@ -180,8 +204,9 @@ void TST_VEllipticalArc::TestGetPoints_data() //--------------------------------------------------------------------------------------------------------------------- // cppcheck-suppress unusedFunction -void TST_VEllipticalArc::TestGetPoints() +void TST_VEllipticalArc::TestGetPoints1() { + //Any point must satisfy the equation of ellipse QFETCH(qreal, radius1); QFETCH(qreal, radius2); QFETCH(qreal, startAngle); @@ -194,7 +219,7 @@ void TST_VEllipticalArc::TestGetPoints() QVector points = arc.GetPoints(); { qreal eps = 0.5; - const QString errorMsg = QString("Broken the first rule, part 1. Any point must satisfy the equation of ellipse."); + const QString errorMsg = QString("Broken the first rule. Any point must satisfy the equation of ellipse."); for (int i=0; i < points.size(); ++i) { QPointF p = points.at(i); @@ -203,82 +228,130 @@ void TST_VEllipticalArc::TestGetPoints() QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); } } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::TestGetPoints2() +{ + // Distance from the any point to the focus1 plus distance from this point to the focus2 should be the same. + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(qreal, rotationAngle); + + const VPointF center; + VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); + QVector points = arc.GetPoints(); + + const qreal c = qSqrt(qAbs(radius2*radius2 - radius1*radius1)); + // distance from the center to the focus + + QPointF focus1 = center.toQPointF(); + QPointF focus2 = center.toQPointF(); + + if (radius1 < radius2) { - const qreal c = qSqrt(qAbs(radius2*radius2 - radius1*radius1)); - // distance from the center to the focus - - QPointF focus1 = center.toQPointF(); - QPointF focus2 = center.toQPointF(); - - if (radius1 < radius2) - { - focus1.setY(focus1.ry() + c); - QLineF line(center.toQPointF(), focus1); - line.setAngle(line.angle() + rotationAngle); - focus1 = line.p2(); - - focus2.setY(focus2.ry() - c); - line.setP2(focus2); - line.setAngle(line.angle() + rotationAngle); - focus2 = line.p2(); - } - else - { - focus1.setX(focus1.rx() + c); - QLineF line(center.toQPointF(), focus1); - line.setAngle(line.angle() + rotationAngle); - focus1 = line.p2(); - - focus2.setX(focus2.rx() - c); - line.setP2(focus2); - line.setAngle(line.angle() + rotationAngle); - focus2 = line.p2(); - } - - QPointF ellipsePoint(center.x() + radius1, center.y()); - QLineF line(center.toQPointF(), ellipsePoint); + focus1.setY(focus1.ry() + c); + QLineF line(center.toQPointF(), focus1); line.setAngle(line.angle() + rotationAngle); - ellipsePoint = line.p2(); + focus1 = line.p2(); - const QLineF distance1(focus1, ellipsePoint); - const QLineF distance2(focus2, ellipsePoint); - - const qreal distance = distance1.length() + distance2.length(); - const qreal eps = distance * 0.5/ 100; // computing error 0.5 % from origin distance - for (int i=0; i < points.size(); ++i) - { - const QLineF rLine1(focus1, points.at(i)); - const QLineF rLine2(focus2, points.at(i)); - const qreal resultingDistance = rLine1.length()+rLine2.length(); - const qreal diff = qAbs(resultingDistance - distance); - const QString errorMsg = QString("Broken the first rule, part 2. Distance from the any point to the focus1 plus" - " distance from this point to the focus2 should be the same. Problem with point '%1'." - " The disired distance is '%2', but resulting distance is '%3'. Difference is '%4' and it" - " biggest than eps ('%5')").arg(i).arg(distance).arg(resultingDistance).arg(diff).arg(eps); - QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); - } + focus2.setY(focus2.ry() - c); + line.setP2(focus2); + line.setAngle(line.angle() + rotationAngle); + focus2 = line.p2(); } + else { - if (qFuzzyCompare(arc.AngleArc(), 360.0)) - {// calculated full ellipse square - const qreal ellipseSquare = M_PI * radius1 * radius2; - const qreal epsSquare = ellipseSquare * 0.24 / 100; // computing error 0.24 % from origin squere - const qreal arcSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); - const qreal diffSquare = qAbs(ellipseSquare - arcSquare); - const QString errorMsg1 = QString("Broken the second rule. Interpolation has too big computing error. " - "Difference ='%1' bigger than eps = '%2'.").arg(diffSquare).arg(epsSquare); - QVERIFY2(diffSquare <= epsSquare, qUtf8Printable(errorMsg1)); + focus1.setX(focus1.rx() + c); + QLineF line(center.toQPointF(), focus1); + line.setAngle(line.angle() + rotationAngle); + focus1 = line.p2(); - // calculated full ellipse length - const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); - const qreal ellipseLength = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h))); - const qreal epsLength = ellipseLength*0.5/100; // computing error - VEllipticalArc arc(center, radius1, radius2, 0, 360, 0); - const qreal arcLength = arc.GetLength(); - const qreal diffLength = qAbs(arcLength - ellipseLength); - const QString errorMsg2 = QString("Difference between real and computing lengthes " - "(diff = '%1') bigger than eps = '%2'.").arg(diffLength).arg(epsLength); - QVERIFY2(diffLength <= epsLength, qUtf8Printable(errorMsg2)); - } + focus2.setX(focus2.rx() - c); + line.setP2(focus2); + line.setAngle(line.angle() + rotationAngle); + focus2 = line.p2(); + } + + QPointF ellipsePoint(center.x() + radius1, center.y()); + QLineF line(center.toQPointF(), ellipsePoint); + line.setAngle(line.angle() + rotationAngle); + ellipsePoint = line.p2(); + + const QLineF distance1(focus1, ellipsePoint); + const QLineF distance2(focus2, ellipsePoint); + + const qreal distance = distance1.length() + distance2.length(); + const qreal eps = distance * 0.5/ 100; // computing error 0.5 % from origin distance + for (int i=0; i < points.size(); ++i) + { + const QLineF rLine1(focus1, points.at(i)); + const QLineF rLine2(focus2, points.at(i)); + const qreal resultingDistance = rLine1.length()+rLine2.length(); + const qreal diff = qAbs(resultingDistance - distance); + const QString errorMsg = QString("Broken the first rule, part 2. Distance from the any point to the focus1" + " plus distance from this point to the focus2 should be the same. Problem" + " with point '%1'. The disired distance is '%2', but resulting distance" + " is '%3'. Difference is '%4' and it biggest than eps " + "('%5')").arg(i).arg(distance).arg(resultingDistance).arg(diff).arg(eps); + QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::TestGetPoints3() +{ + // Compare full ellipse square with square of VAbstractDetail + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(qreal, rotationAngle); + + const VPointF center; + VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); + QVector points = arc.GetPoints(); + + if (qFuzzyCompare(arc.AngleArc(), 360.0)) + {// calculated full ellipse square + const qreal ellipseSquare = M_PI * radius1 * radius2; + const qreal epsSquare = ellipseSquare * 0.24 / 100; // computing error 0.24 % from origin squere + const qreal arcSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); + const qreal diffSquare = qAbs(ellipseSquare - arcSquare); + const QString errorMsg1 = QString("Broken the second rule. Interpolation has too big computing error. " + "Difference ='%1' bigger than eps = '%2'.").arg(diffSquare).arg(epsSquare); + QVERIFY2(diffSquare <= epsSquare, qUtf8Printable(errorMsg1)); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_VEllipticalArc::TestGetPoints4() +{ + // Compare real full ellipse length with calculated + QFETCH(qreal, radius1); + QFETCH(qreal, radius2); + QFETCH(qreal, startAngle); + QFETCH(qreal, endAngle); + QFETCH(qreal, rotationAngle); + + const VPointF center; + VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); + + if (qFuzzyCompare(arc.AngleArc(), 360.0)) + {// calculated full ellipse length + const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); + const qreal ellipseLength = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h))); + const qreal epsLength = ellipseLength*0.5/100; // computing error + VEllipticalArc arc(center, radius1, radius2, 0, 360, 0); + const qreal arcLength = arc.GetLength(); + const qreal diffLength = qAbs(arcLength - ellipseLength); + const QString errorMsg2 = QString("Difference between real and computing lengthes " + "(diff = '%1') bigger than eps = '%2'.").arg(diffLength).arg(epsLength); + QVERIFY2(diffLength <= epsLength, qUtf8Printable(errorMsg2)); } } diff --git a/src/test/ValentinaTest/tst_vellipticalarc.h b/src/test/ValentinaTest/tst_vellipticalarc.h index 7a9e67c4b..179227f91 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.h +++ b/src/test/ValentinaTest/tst_vellipticalarc.h @@ -40,11 +40,18 @@ public: private slots: void CompareTwoWays(); void NegativeArc(); - void TestGetPoints_data(); - void TestGetPoints(); + void TestGetPoints1_data(); + void TestGetPoints2_data(); + void TestGetPoints3_data(); + void TestGetPoints4_data(); + void TestGetPoints1(); + void TestGetPoints2(); + void TestGetPoints3(); + void TestGetPoints4(); private: Q_DISABLE_COPY(TST_VEllipticalArc) + void TestData(); }; #endif // TST_VELLIPTICALARC_H From 22a3e9d1a0f15592b5409a4d37ecc8b282fd7f9b Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 26 Feb 2016 21:27:55 +0200 Subject: [PATCH 13/21] Little fixes in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/varc.cpp | 2 +- src/libs/vgeometry/vellipticalarc.cpp | 4 ++-- src/test/ValentinaTest/tst_vellipticalarc.cpp | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index fc87a77d1..1c52f2ca1 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -283,7 +283,7 @@ QPointF VArc::CutArc(const qreal &length, VArc &arc1, VArc &arc2) const len = length; } - qreal n = (len*180)/(M_PI*d->radius); + qreal n = (len*180)/(M_PI*d->radius); // n - is angle in degrees QLineF line(GetCenter().toQPointF(), GetP1()); line.setAngle(line.angle()+n); diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 2d026f07e..68313b5f9 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -356,13 +356,12 @@ void VEllipticalArc::FindF2(qreal length) qreal gap = 180; if (length < 0) { - //length = qAbs(length); d->isFlipped = true; gap = -gap; } while (length > MaxLength()) { - //length = length - MaxLength(); + length = length - MaxLength(); } // We need to calculate the second angle @@ -386,6 +385,7 @@ void VEllipticalArc::FindF2(qreal length) { // we selected too little end angle endAngle = endAngle + qAbs(gap); } + // we need to set d->f2, because we use it when we calculate GetLength d->f2 = endAngle; lenBez = GetLength(); } diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index a30a2ae01..1169ec52a 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -197,9 +197,12 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 90.0 << 135.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 150, 400") << 150.0 << 400.0 << 90.0 << 135.0 << 0.0; - QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 90.0 << 135.0 << 0.0; - QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 90.0 << 135.0 << 0.0; - QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 1500, 800") + << 1500.0 << 800.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 50000, 5000") + << 50000.0 << 5000.0 << 90.0 << 135.0 << 0.0; + QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 90000, 50000") + << 90000.0 << 50000.0 << 90.0 << 135.0 << 0.0; } //--------------------------------------------------------------------------------------------------------------------- From cafd3ee583300c477489d639f395e9c1ffbb6de0 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Fri, 26 Feb 2016 21:30:20 +0200 Subject: [PATCH 14/21] Added CutArc in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 41 ++++++++++++++++--- src/libs/vgeometry/vellipticalarc.h | 11 ++--- src/libs/vgeometry/vellipticalarc_p.h | 12 +++--- src/test/ValentinaTest/tst_vellipticalarc.cpp | 5 ++- 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 68313b5f9..29669e78c 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -53,7 +53,7 @@ VEllipticalArc::VEllipticalArc() */ VEllipticalArc::VEllipticalArc (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, qreal f2, - QString formulaF2, qreal rotationAngle, quint32 idObject, Draw mode) + QString formulaF2, qreal rotationAngle, quint32 idObject, Draw mode) : VAbstractCurve(GOType::EllipticalArc, idObject, mode), d (new VEllipticalArcData(center, radius1, radius2, formulaRadius1, formulaRadius2, f1, formulaF1, f2, formulaF2, rotationAngle)) @@ -71,18 +71,21 @@ VEllipticalArc::VEllipticalArc(VPointF center, qreal radius1, qreal radius2, qre //--------------------------------------------------------------------------------------------------------------------- VEllipticalArc::VEllipticalArc(qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, quint32 idObject, Draw mode) + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, qreal rotationAngle, + quint32 idObject, Draw mode) : VAbstractCurve(GOType::EllipticalArc, idObject, mode), - d (new VEllipticalArcData(formulaLength, center, radius1, radius2, formulaRadius1, formulaRadius2, f1, formulaF1)) + d (new VEllipticalArcData(formulaLength, center, radius1, radius2, formulaRadius1, formulaRadius2, + f1, formulaF1, rotationAngle)) { EllipticalArcName(); FindF2(length); } //--------------------------------------------------------------------------------------------------------------------- -VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1) +VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1, + qreal rotationAngle) : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), - d (new VEllipticalArcData(center, radius1, radius2, f1)) + d (new VEllipticalArcData(center, radius1, radius2, f1, rotationAngle)) { EllipticalArcName(); FindF2(length); @@ -325,12 +328,40 @@ QVector VEllipticalArc::GetPoints() const */ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const { + //Always need return two arcs, so we must correct wrong length. + qreal len = 0; + if (length < this->GetLength()*0.02) + { + len = this->GetLength()*0.02; + } + else if ( length > this->GetLength()*0.98) + { + len = this->GetLength()*0.98; + } + else + { + len = length; + } + + // the first arc has given length and startAngle just like in the origin arc + arc1 = VEllipticalArc (len, QString().setNum(length), d->center, d->radius1, d->radius2, + d->formulaRadius1, d->formulaRadius2, d->f1, d->formulaF1, d->rotationAngle, + getIdObject(), getMode()); + // the second arc has startAngle just like endAngle of the first arc + // and it has endAngle just like endAngle of the origin arc + arc2 = VEllipticalArc (d->center, d->radius1, d->radius2, d->formulaRadius1, d->formulaRadius2, + arc1.GetEndAngle(), arc1.GetFormulaF2(), d->f2, d->formulaF2, d->rotationAngle, + getIdObject(), getMode()); + return arc1.GetP1(); } //--------------------------------------------------------------------------------------------------------------------- QPointF VEllipticalArc::CutArc(const qreal &length) const { + VEllipticalArc arc1; + VEllipticalArc arc2; + return this->CutArc(length, arc1, arc2); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index f80af80bb..45a8d01cd 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -40,16 +40,17 @@ class VEllipticalArc : public VAbstractCurve Q_DECLARE_TR_FUNCTIONS(VEllipticalArc) public: VEllipticalArc(); - VEllipticalArc (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, qreal f1, - QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); + VEllipticalArc (VPointF center, qreal radius1, qreal radius2, QString formulaRadius1, QString formulaRadius2, + qreal f1, QString formulaF1, qreal f2, QString formulaF2, qreal rotationAngle, + quint32 idObject = 0, Draw mode = Draw::Calculation); VEllipticalArc (VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle); VEllipticalArc (qreal length, QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, - QString formulaF1, quint32 idObject = 0, Draw mode = Draw::Calculation); + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, + qreal rotationAngle, quint32 idObject = 0, Draw mode = Draw::Calculation); - VEllipticalArc (qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1); + VEllipticalArc (qreal length, VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle); VEllipticalArc(const VEllipticalArc &arc); diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index 67b970a39..a31c88879 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -29,24 +29,26 @@ public: {} VEllipticalArcData (QString formulaLength, VPointF center, qreal radius1, qreal radius2, - QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1) + QString formulaRadius1, QString formulaRadius2, qreal f1, QString formulaF1, + qreal rotationAngle) : f1(f1), f2(0), formulaF1(formulaF1), formulaF2("0"), radius1(radius1),radius2(radius2), formulaRadius1(formulaRadius1), formulaRadius2(formulaRadius2), - center(center), isFlipped(false), formulaLength(formulaLength), rotationAngle(0) + center(center), isFlipped(false), formulaLength(formulaLength), rotationAngle(rotationAngle) {} - VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1) + VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle) : f1(f1), f2(0), formulaF1(QString("%1").arg(f1)), formulaF2("0"), radius1(radius1), radius2(radius2), formulaRadius1(QString("%1").arg(radius1)), formulaRadius2(QString("%1").arg(radius2)), - center(center), isFlipped(false), formulaLength(), rotationAngle(0) + center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) {} VEllipticalArcData(const VEllipticalArcData &arc) : QSharedData(arc), f1(arc.f1), f2(arc.f2), formulaF1(arc.formulaF1), formulaF2(arc.formulaF2), radius1(arc.radius1), radius2(arc.radius2), formulaRadius1(arc.formulaRadius1), formulaRadius2(arc.formulaRadius2), - center(arc.center), isFlipped(arc.isFlipped), formulaLength(arc.formulaLength), rotationAngle(arc.rotationAngle) + center(arc.center), isFlipped(arc.isFlipped), formulaLength(arc.formulaLength), + rotationAngle(arc.rotationAngle) {} virtual ~VEllipticalArcData(); diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 1169ec52a..eb2a96858 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -51,7 +51,7 @@ void TST_VEllipticalArc::CompareTwoWays() const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/4; VEllipticalArc arc1(center, radius1, radius2, f1, f2, rotationAngle); - VEllipticalArc arc2(length, center, radius1, radius2, f1); + VEllipticalArc arc2(length, center, radius1, radius2, f1, rotationAngle); const qreal eps = length*0.5/100; // computing error const QString errorMsg = @@ -75,11 +75,12 @@ void TST_VEllipticalArc::NegativeArc() const qreal radius2 = 200; const qreal f1 = 1; const qreal f2 = 181; + const qreal rotationAngle = 0; const qreal h = ((radius1-radius2)*(radius1-radius2))/((radius1+radius2)*(radius1+radius2)); const qreal length = M_PI*(radius1+radius2)*(1+3*h/(10+qSqrt(4-3*h)))/2; qreal l = -length; - VEllipticalArc arc(l, center, radius1, radius2, f1); + VEllipticalArc arc(l, center, radius1, radius2, f1, rotationAngle); const qreal eps = 1; // computing error const QString errorMsg = From 3d628d815b046b0a301bbd52ba82461d45f588fc Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sat, 27 Feb 2016 16:53:17 +0200 Subject: [PATCH 15/21] Fixed merge conflicts --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 26 +++++++++++++++++------- src/libs/vgeometry/vellipticalarc.h | 4 ++-- src/libs/vgeometry/vgeometry.pri | 8 ++++---- src/test/ValentinaTest/ValentinaTest.pro | 6 ++++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 29669e78c..2f8fbdf35 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -58,7 +58,7 @@ VEllipticalArc::VEllipticalArc (VPointF center, qreal radius1, qreal radius2, d (new VEllipticalArcData(center, radius1, radius2, formulaRadius1, formulaRadius2, f1, formulaF1, f2, formulaF2, rotationAngle)) { - EllipticalArcName(); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- @@ -66,7 +66,7 @@ VEllipticalArc::VEllipticalArc(VPointF center, qreal radius1, qreal radius2, qre : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), d (new VEllipticalArcData(center, radius1, radius2, f1, f2, rotationAngle)) { - EllipticalArcName(); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- @@ -77,7 +77,7 @@ VEllipticalArc::VEllipticalArc(qreal length, QString formulaLength, VPointF cent d (new VEllipticalArcData(formulaLength, center, radius1, radius2, formulaRadius1, formulaRadius2, f1, formulaF1, rotationAngle)) { - EllipticalArcName(); + CreateName(); FindF2(length); } @@ -87,7 +87,7 @@ VEllipticalArc::VEllipticalArc(qreal length, VPointF center, qreal radius1, qrea : VAbstractCurve(GOType::EllipticalArc, NULL_ID, Draw::Calculation), d (new VEllipticalArcData(center, radius1, radius2, f1, rotationAngle)) { - EllipticalArcName(); + CreateName(); FindF2(length); } @@ -372,13 +372,25 @@ QPointF VEllipticalArc::CutArc(const qreal &length) const void VEllipticalArc::setId(const quint32 &id) { VAbstractCurve::setId(id); - setName(EARC_ + QString("%1_%2").arg(d->center.name()).arg(id)); + CreateName(); } //--------------------------------------------------------------------------------------------------------------------- -void VEllipticalArc::EllipticalArcName() +void VEllipticalArc::CreateName() { - setName(EARC_ + QString("%1").arg(this->GetCenter().name())); + QString name = EARC_ + QString("%1").arg(this->GetCenter().name()); + + if (VAbstractCurve::id() != NULL_ID) + { + name += QString("_%1").arg(VAbstractCurve::id()); + } + + if (GetDuplicate() > 0) + { + name += QString("_%1").arg(GetDuplicate()); + } + + setName(name); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/vellipticalarc.h b/src/libs/vgeometry/vellipticalarc.h index 45a8d01cd..44a3f2cd1 100644 --- a/src/libs/vgeometry/vellipticalarc.h +++ b/src/libs/vgeometry/vellipticalarc.h @@ -92,10 +92,10 @@ public: QPointF CutArc (const qreal &length, VEllipticalArc &arc1, VEllipticalArc &arc2) const; QPointF CutArc (const qreal &length) const; virtual void setId(const quint32 &id) Q_DECL_OVERRIDE; +protected: + virtual void CreateName() Q_DECL_OVERRIDE; private: QSharedDataPointer d; - - void EllipticalArcName(); void FindF2(qreal length); qreal MaxLength() const; diff --git a/src/libs/vgeometry/vgeometry.pri b/src/libs/vgeometry/vgeometry.pri index 2283a411e..1c80d0ed3 100644 --- a/src/libs/vgeometry/vgeometry.pri +++ b/src/libs/vgeometry/vgeometry.pri @@ -8,7 +8,7 @@ SOURCES += \ $$PWD/vpointf.cpp \ $$PWD/vspline.cpp \ $$PWD/vsplinepath.cpp \ - $$PWD/vsplinepoint.cpp \ + $$PWD/vsplinepoint.cpp \ $$PWD/vellipticalarc.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp @@ -29,6 +29,6 @@ HEADERS += \ $$PWD/vsplinepoint.h \ $$PWD/vsplinepoint_p.h \ $$PWD/vgeometrydef.h \ - $$PWD/vellipticalarc.h \ - $$PWD/vellipticalarc_p.h - $$PWD/vabstractcurve_p.h + $$PWD/vellipticalarc.h \ + $$PWD/vellipticalarc_p.h \ + $$PWD/vabstractcurve_p.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index cba46d81f..52a187aa9 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -54,7 +54,8 @@ SOURCES += \ tst_vcommandline.cpp \ tst_tstranslation.cpp \ tst_vdetail.cpp \ - tst_findpoint.cpp + tst_findpoint.cpp \ + tst_vellipticalarc.cpp HEADERS += \ tst_vposter.h \ @@ -76,7 +77,8 @@ HEADERS += \ tst_vcommandline.h \ tst_tstranslation.h \ tst_vdetail.h \ - tst_findpoint.h + tst_findpoint.h \ + tst_vellipticalarc.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() From 91f5300b0f91a5776484650684ed33150501f239 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 16:16:34 +0200 Subject: [PATCH 16/21] Little fixes for VEllipticalArc tests --HG-- branch : feature --- src/test/ValentinaTest/tst_vellipticalarc.cpp | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index eb2a96858..41da95713 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -125,39 +125,47 @@ void TST_VEllipticalArc::TestData() QTest::addColumn("rotationAngle"); QTest::newRow("Full circle: radiuses 10, 20") << 10.0 << 20.0 << 0.0 << 360.0 << 0.0; - QTest::newRow("Full circle: radiuses 150, 200") << 150.0 << 200.0 << 0.0 << 360.0 << 30.0; - QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 50.0; + QTest::newRow("Full circle: radiuses 150, 200") << 150.0 << 200.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 150, 200, rotation 30") << 150.0 << 200.0 << 0.0 << 360.0 << 30.0; + QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 0.0; + QTest::newRow("Full circle: radiuses 1500, 1000, rotation 50") << 1500.0 << 1000.0 << 0.0 << 360.0 << 50.0; QTest::newRow("Full circle: radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 360.0 << 0.0; - QTest::newRow("Full circle: radiuses 90000, 80000") << 90000.0 << 80000.0 << 0.0 << 360.0 << 90.0; + QTest::newRow("Full circle: radiuses 90000, 80000, rotation 90") << 90000.0 << 80000.0 << 0.0 << 360.0 << 90.0; QTest::newRow("Arc less than 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc less than 45 degree, radiuses 150, 50") << 150.0 << 50.0 << 0.0 << 10.5 << 180.0; - QTest::newRow("Arc less than 45 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 10.5 << 90.0; - QTest::newRow("Arc less than 45 degree, radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 10.5 << 40.0; + QTest::newRow("Arc less than 45 degree, radiuses 150, 50, rotation 180") << 150.0 << 50.0 << 0.0 << 10.5 << 180.0; + QTest::newRow("Arc less than 45 degree, radiuses 1500, 800, rotation 90") << 1500.0 << 800.0 << 0.0 << 10.5 << 90.0; + QTest::newRow("Arc less than 45 degree, radiuses 50000, 10000, rotation 40") + << 50000.0 << 10000.0 << 0.0 << 10.5 << 40.0; QTest::newRow("Arc less than 45 degree, radiuses 90000, 10000") << 90000.0 << 10000.0 << 0.0 << 10.5 << 0.0; - QTest::newRow("Arc 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 45.0 << 45.0; - QTest::newRow("Arc 45 degree, radiuses 150, 15") << 150.0 << 15.0 << 0.0 << 45.0 << 30.0; + QTest::newRow("Arc 45 degree, radiuses 100, 50, rotation 45") << 100.0 << 50.0 << 0.0 << 45.0 << 45.0; + QTest::newRow("Arc 45 degree, radiuses 150, 15, rotation 30") << 150.0 << 15.0 << 0.0 << 45.0 << 30.0; QTest::newRow("Arc 45 degree, radiuses 1500, 150") << 1500.0 << 150.0 << 0.0 << 45.0 << 0.0; QTest::newRow("Arc 45 degree, radiuses 50000, 50000") << 50000.0 << 50000.0 << 0.0 << 45.0 << 0.0; - QTest::newRow("Arc 45 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 45.0 << 270.0; + QTest::newRow("Arc 45 degree, radiuses 90000, 50000, rotation 270") << 90000.0 << 50000.0 << 0.0 << 45.0 << 270.0; - QTest::newRow("Arc less than 90 degree, radiuses 100, 400") << 100.0 << 400.0 << 0.0 << 75.0 << 50.0; - QTest::newRow("Arc less than 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 75.0 << 90.0; - QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000") << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; + QTest::newRow("Arc less than 90 degree, radiuses 100, 400, rotation 50") << 100.0 << 400.0 << 0.0 << 75.0 << 50.0; + QTest::newRow("Arc less than 90 degree, radiuses 150, 400, rotation 90") << 150.0 << 400.0 << 0.0 << 75.0 << 90.0; + QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000, rotation 180") + << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 75.0 << 0.0; - QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; + QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000, rotation 30") + << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; - QTest::newRow("Arc 90 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 90.0 << 30.0; + QTest::newRow("Arc 90 degree, radiuses 100, 50, rotation 30") << 100.0 << 50.0 << 0.0 << 90.0 << 30.0; QTest::newRow("Arc 90 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 90.0 << 0.0; - QTest::newRow("Arc 90 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 90.0 << 70.0; - QTest::newRow("Arc 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 90.0 << 30.0; - QTest::newRow("Arc 90 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 90.0 << 235.0; + QTest::newRow("Arc 90 degree, radiuses 1500, 800, rotation 70") << 1500.0 << 800.0 << 0.0 << 90.0 << 70.0; + QTest::newRow("Arc 90 degree, radiuses 50000, 5000, rotation 30") << 50000.0 << 5000.0 << 0.0 << 90.0 << 30.0; + QTest::newRow("Arc 90 degree, radiuses 90000, 50000, rotation 235") << 90000.0 << 50000.0 << 0.0 << 90.0 << 235.0; - QTest::newRow("Arc less than 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 110.6 << 60.0; - QTest::newRow("Arc less than 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 110.6 << 300.0; - QTest::newRow("Arc less than 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 110.6 << 360.0; - QTest::newRow("Arc less than 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 110.6 << 290.0; + QTest::newRow("Arc less than 135 degree, radiuses 100, 50, rotation 60") << 100.0 << 50.0 << 0.0 << 110.6 << 60.0; + QTest::newRow("Arc less than 135 degree, radiuses 150, 400, rotation 300") + << 150.0 << 400.0 << 0.0 << 110.6 << 300.0; + QTest::newRow("Arc less than 135 degree, radiuses 1500, 800, rotation 360") + << 1500.0 << 800.0 << 0.0 << 110.6 << 360.0; + QTest::newRow("Arc less than 135 degree, radiuses 50000, 5000, rotation 290") + << 50000.0 << 5000.0 << 0.0 << 110.6 << 290.0; QTest::newRow("Arc less than 135 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 110.6 << 0.0; QTest::newRow("Arc 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 135.0 << 0.0; @@ -221,14 +229,17 @@ void TST_VEllipticalArc::TestGetPoints1() VEllipticalArc arc(center, radius1, radius2, startAngle, endAngle, rotationAngle); QVector points = arc.GetPoints(); - { - qreal eps = 0.5; - const QString errorMsg = QString("Broken the first rule. Any point must satisfy the equation of ellipse."); + if (rotationAngle == 0.0) + { // equation of ellipse will be different when rotation angle isn't 0 so we can't use this test in this case + qreal eps = 0.05; + for (int i=0; i < points.size(); ++i) { QPointF p = points.at(i); const qreal equationRes = p.rx()*p.rx()/(radius1*radius1) + p.ry()*p.ry()/(radius2*radius2); const qreal diff = qAbs(equationRes - 1); + const QString errorMsg = QString("Broken the first rule. Any point must satisfy the equation of ellipse." + "diff = '%1' > eps = '%2'").arg(diff).arg(eps); QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); } } @@ -289,7 +300,7 @@ void TST_VEllipticalArc::TestGetPoints2() const QLineF distance2(focus2, ellipsePoint); const qreal distance = distance1.length() + distance2.length(); - const qreal eps = distance * 0.5/ 100; // computing error 0.5 % from origin distance + const qreal eps = distance * 0.5 / 100; // computing error 0.5 % from origin distance for (int i=0; i < points.size(); ++i) { const QLineF rLine1(focus1, points.at(i)); From e1981a56c5dc1efa07784087eee6809e5241cdc6 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 17:51:27 +0200 Subject: [PATCH 17/21] Fixed tests for VEllipticalArc --HG-- branch : feature --- src/test/ValentinaTest/tst_vellipticalarc.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 41da95713..282173b84 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -129,7 +129,6 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Full circle: radiuses 150, 200, rotation 30") << 150.0 << 200.0 << 0.0 << 360.0 << 30.0; QTest::newRow("Full circle: radiuses 1500, 1000") << 1500.0 << 1000.0 << 0.0 << 360.0 << 0.0; QTest::newRow("Full circle: radiuses 1500, 1000, rotation 50") << 1500.0 << 1000.0 << 0.0 << 360.0 << 50.0; - QTest::newRow("Full circle: radiuses 50000, 10000") << 50000.0 << 10000.0 << 0.0 << 360.0 << 0.0; QTest::newRow("Full circle: radiuses 90000, 80000, rotation 90") << 90000.0 << 80000.0 << 0.0 << 360.0 << 90.0; QTest::newRow("Arc less than 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 10.5 << 0.0; @@ -141,7 +140,7 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc 45 degree, radiuses 100, 50, rotation 45") << 100.0 << 50.0 << 0.0 << 45.0 << 45.0; QTest::newRow("Arc 45 degree, radiuses 150, 15, rotation 30") << 150.0 << 15.0 << 0.0 << 45.0 << 30.0; - QTest::newRow("Arc 45 degree, radiuses 1500, 150") << 1500.0 << 150.0 << 0.0 << 45.0 << 0.0; + QTest::newRow("Arc 45 degree, radiuses 1500, 150, rotation 45") << 1500.0 << 150.0 << 0.0 << 45.0 << 45.0; QTest::newRow("Arc 45 degree, radiuses 50000, 50000") << 50000.0 << 50000.0 << 0.0 << 45.0 << 0.0; QTest::newRow("Arc 45 degree, radiuses 90000, 50000, rotation 270") << 90000.0 << 50000.0 << 0.0 << 45.0 << 270.0; @@ -149,7 +148,8 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc less than 90 degree, radiuses 150, 400, rotation 90") << 150.0 << 400.0 << 0.0 << 75.0 << 90.0; QTest::newRow("Arc less than 90 degree, radiuses 1500, 50000, rotation 180") << 1500.0 << 50000.0 << 0.0 << 75.0 << 180.0; - QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 75.0 << 0.0; + QTest::newRow("Arc less than 90 degree, radiuses 50000, 5000, rotation 30") + << 50000.0 << 5000.0 << 0.0 << 75.0 << 30.0; QTest::newRow("Arc less than 90 degree, radiuses 90000, 50000, rotation 30") << 90000.0 << 50000.0 << 0.0 << 75.0 << 30.0; @@ -171,37 +171,40 @@ void TST_VEllipticalArc::TestData() QTest::newRow("Arc 135 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 135.0 << 0.0; QTest::newRow("Arc 135 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 135.0 << 0.0; QTest::newRow("Arc 135 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 135.0 << 0.0; - QTest::newRow("Arc 135 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 135.0 << 0.0; + QTest::newRow("Arc 135 degree, radiuses 50000, 5000, rotation 20") << 50000.0 << 5000.0 << 0.0 << 135.0 << 20.0; QTest::newRow("Arc 135 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 135.0 << 0.0; QTest::newRow("Arc less than 180 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc less than 180 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc less than 180 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 160.7 << 0.0; - QTest::newRow("Arc less than 180 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 160.7 << 0.0; + QTest::newRow("Arc less than 180 degree, radiuses 50000, 5000, rotation 270") + << 50000.0 << 5000.0 << 0.0 << 160.7 << 270.0; QTest::newRow("Arc less than 180 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 160.7 << 0.0; QTest::newRow("Arc 180 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 180.0 << 0.0; QTest::newRow("Arc 180 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 180.0 << 0.0; QTest::newRow("Arc 180 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 180.0 << 0.0; - QTest::newRow("Arc 180 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 180.0 << 0.0; + QTest::newRow("Arc 180 degree, radiuses 50000, 5000, rotation 60") << 50000.0 << 5000.0 << 0.0 << 180.0 << 60.0; QTest::newRow("Arc 180 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 180.0 << 0.0; QTest::newRow("Arc less than 270 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc less than 270 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc less than 270 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 150.3 << 0.0; - QTest::newRow("Arc less than 270 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 150.3 << 0.0; + QTest::newRow("Arc less than 270 degree, radiuses 50000, 5000, rotation 20") + << 50000.0 << 5000.0 << 0.0 << 150.3 << 20.0; QTest::newRow("Arc less than 270 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 150.3 << 0.0; QTest::newRow("Arc 270 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 270.0 << 0.0; QTest::newRow("Arc 270 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 270.0 << 0.0; QTest::newRow("Arc 270 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 270.0 << 0.0; - QTest::newRow("Arc 270 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 270.0 << 0.0; + QTest::newRow("Arc 270 degree, radiuses 50000, 5000, rotation 90") << 50000.0 << 5000.0 << 0.0 << 270.0 << 90.0; QTest::newRow("Arc 270 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 270.0 << 0.0; QTest::newRow("Arc less than 360 degree, radiuses 100, 50") << 100.0 << 50.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc less than 360 degree, radiuses 150, 400") << 150.0 << 400.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc less than 360 degree, radiuses 1500, 800") << 1500.0 << 800.0 << 0.0 << 340.0 << 0.0; - QTest::newRow("Arc less than 360 degree, radiuses 50000, 5000") << 50000.0 << 5000.0 << 0.0 << 340.0 << 0.0; + QTest::newRow("Arc less than 360 degree, radiuses 50000, 5000, rotation 30") + << 50000.0 << 5000.0 << 0.0 << 340.0 << 30.0; QTest::newRow("Arc less than 360 degree, radiuses 90000, 50000") << 90000.0 << 50000.0 << 0.0 << 340.0 << 0.0; QTest::newRow("Arc start 90 degree, angle 45 degree, radiuses 100, 50") << 100.0 << 50.0 << 90.0 << 135.0 << 0.0; @@ -300,7 +303,7 @@ void TST_VEllipticalArc::TestGetPoints2() const QLineF distance2(focus2, ellipsePoint); const qreal distance = distance1.length() + distance2.length(); - const qreal eps = distance * 0.5 / 100; // computing error 0.5 % from origin distance + const qreal eps = distance * 1.1 / 100; // computing error 1.1 % from origin distance for (int i=0; i < points.size(); ++i) { const QLineF rLine1(focus1, points.at(i)); @@ -334,7 +337,7 @@ void TST_VEllipticalArc::TestGetPoints3() if (qFuzzyCompare(arc.AngleArc(), 360.0)) {// calculated full ellipse square const qreal ellipseSquare = M_PI * radius1 * radius2; - const qreal epsSquare = ellipseSquare * 0.24 / 100; // computing error 0.24 % from origin squere + const qreal epsSquare = ellipseSquare * 0.5 / 100; // computing error 0.5 % from origin squere const qreal arcSquare = qAbs(VAbstractDetail::SumTrapezoids(points)/2.0); const qreal diffSquare = qAbs(ellipseSquare - arcSquare); const QString errorMsg1 = QString("Broken the second rule. Interpolation has too big computing error. " From 088f0a6987079c5b457694d2559c23760131f9f7 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 21:20:33 +0200 Subject: [PATCH 18/21] Changed QString("%1").arg() to QString().number() in VEllipticalArc --HG-- branch : feature --- src/libs/vgeometry/vellipticalarc.cpp | 4 ++-- src/libs/vgeometry/vellipticalarc_p.h | 13 ++++++++----- src/libs/vgeometry/vgeometry.pro | 2 ++ src/test/ValentinaTest/tst_vellipticalarc.cpp | 10 +++++----- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 2f8fbdf35..8db3ad1a6 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -223,8 +223,8 @@ QPointF VEllipticalArc::GetPoint (qreal angle) const */ qreal VEllipticalArc::AngleArc() const { - if ((qFuzzyCompare(d->f1+1, 0+1) && qFuzzyCompare(d->f2, 360)) || - (qFuzzyCompare(d->f1, 360) && qFuzzyCompare(d->f2+1, 0+1))) + if ((qFuzzyIsNull(d->f1) && qFuzzyCompare(d->f2, 360)) || + (qFuzzyCompare(d->f1, 360) && qFuzzyIsNull(d->f2))) { return 360; } diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index a31c88879..325c5ac8f 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -2,6 +2,7 @@ #define VELLIPTICALARC_P #include +#include <../vmisc/vabstractapplication.h> #include "vpointf.h" class VEllipticalArcData : public QSharedData @@ -22,9 +23,10 @@ public: {} VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) - : f1(f1), f2(f2), formulaF1(QString("%1").arg(f1)), formulaF2(QString("%1").arg(f2)), - radius1(radius1), radius2(radius2), - formulaRadius1(QString("%1").arg(radius1)), formulaRadius2(QString("%1").arg(radius2)), + : f1(f1), f2(f2), formulaF1(QString().number(qApp->fromPixel(f1))), + formulaF2(QString().number(qApp->fromPixel(f2))), radius1(radius1), radius2(radius2), + formulaRadius1(QString().number(qApp->fromPixel(radius1))), + formulaRadius2(QString().number(qApp->fromPixel(radius2))), center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) {} @@ -37,9 +39,10 @@ public: {} VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle) - : f1(f1), f2(0), formulaF1(QString("%1").arg(f1)), formulaF2("0"), + : f1(f1), f2(0), formulaF1(QString().number(qApp->fromPixel(f1))), formulaF2("0"), radius1(radius1), radius2(radius2), - formulaRadius1(QString("%1").arg(radius1)), formulaRadius2(QString("%1").arg(radius2)), + formulaRadius1(QString().number(qApp->fromPixel(radius1))), + formulaRadius2(QString().number(qApp->fromPixel(radius2))), center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) {} diff --git a/src/libs/vgeometry/vgeometry.pro b/src/libs/vgeometry/vgeometry.pro index 61861480f..327e1d802 100644 --- a/src/libs/vgeometry/vgeometry.pro +++ b/src/libs/vgeometry/vgeometry.pro @@ -7,6 +7,8 @@ # File with common stuff for whole project include(../../../common.pri) +QT += widgets + # Name of library TARGET = vgeometry diff --git a/src/test/ValentinaTest/tst_vellipticalarc.cpp b/src/test/ValentinaTest/tst_vellipticalarc.cpp index 282173b84..84fb24133 100644 --- a/src/test/ValentinaTest/tst_vellipticalarc.cpp +++ b/src/test/ValentinaTest/tst_vellipticalarc.cpp @@ -55,7 +55,7 @@ void TST_VEllipticalArc::CompareTwoWays() const qreal eps = length*0.5/100; // computing error const QString errorMsg = - QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); + QString("Difference between real and computing lengthes bigger than eps = %1.").number(eps); QVERIFY2(qAbs(arc1.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc2.GetLength() - length) <= eps, qUtf8Printable(errorMsg)); QVERIFY2(qAbs(arc1.GetLength() - arc2.GetLength()) <= eps, qUtf8Printable(errorMsg)); @@ -84,7 +84,7 @@ void TST_VEllipticalArc::NegativeArc() const qreal eps = 1; // computing error const QString errorMsg = - QString("Difference between real and computing lengthes bigger than eps = %1.").arg(eps); + QString("Difference between real and computing lengthes bigger than eps = %1.").number(eps); QVERIFY2(qAbs(arc.GetLength() + length) <= eps, qUtf8Printable(errorMsg)); QVERIFY2(arc.GetEndAngle() - f2 <= eps, qUtf8Printable(errorMsg)); @@ -242,7 +242,7 @@ void TST_VEllipticalArc::TestGetPoints1() const qreal equationRes = p.rx()*p.rx()/(radius1*radius1) + p.ry()*p.ry()/(radius2*radius2); const qreal diff = qAbs(equationRes - 1); const QString errorMsg = QString("Broken the first rule. Any point must satisfy the equation of ellipse." - "diff = '%1' > eps = '%2'").arg(diff).arg(eps); + "diff = '%1' > eps = '%2'").number(diff).number(eps); QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); } } @@ -313,8 +313,8 @@ void TST_VEllipticalArc::TestGetPoints2() const QString errorMsg = QString("Broken the first rule, part 2. Distance from the any point to the focus1" " plus distance from this point to the focus2 should be the same. Problem" " with point '%1'. The disired distance is '%2', but resulting distance" - " is '%3'. Difference is '%4' and it biggest than eps " - "('%5')").arg(i).arg(distance).arg(resultingDistance).arg(diff).arg(eps); + " is '%3'. Difference is '%4' and it biggest than eps '%5')").number(i) + .number(distance).number(resultingDistance).number(diff).number(eps); QVERIFY2( diff <= eps, qUtf8Printable(errorMsg)); } } From e8bf8a80e39626b993da1eb21a2d14916777d503 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 21:24:56 +0200 Subject: [PATCH 19/21] Changed QString("%1").arg() to QString().number() in VArc --HG-- branch : feature --- src/libs/vgeometry/varc.cpp | 2 +- src/libs/vgeometry/varc_p.h | 11 +++++++---- src/libs/vgeometry/vellipticalarc.cpp | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 7014cf795..c26b2de72 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -354,7 +354,7 @@ void VArc::FindF2(qreal length) startAngle.setAngle(d->f1 + arcAngle);// We use QLineF just because it is easy way correct angle value d->f2 = startAngle.angle(); - d->formulaF2 = QString("%1").arg(d->f2); + d->formulaF2 = QString().number(qApp->fromPixel(d->f2)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/varc_p.h b/src/libs/vgeometry/varc_p.h index b11f1399c..841349ff1 100644 --- a/src/libs/vgeometry/varc_p.h +++ b/src/libs/vgeometry/varc_p.h @@ -31,6 +31,7 @@ #include #include "vgeometrydef.h" +#include <../vmisc/vabstractapplication.h> #include "vpointf.h" #ifdef Q_CC_GNU @@ -54,8 +55,10 @@ public: {} VArcData(VPointF center, qreal radius, qreal f1, qreal f2) - : f1(f1), formulaF1(QString("%1").arg(f1)), f2(f2), formulaF2(QString("%1").arg(f2)), radius(radius), - formulaRadius(QString("%1").arg(radius)), center(center), isFlipped(false), formulaLength() + : f1(f1), formulaF1(QString().number(qApp->fromPixel(f1))), + f2(f2), formulaF2(QString().number(qApp->fromPixel(f2))), + radius(radius), formulaRadius(QString().number(qApp->fromPixel(radius))), + center(center), isFlipped(false), formulaLength() {} VArcData (QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1 ) @@ -64,8 +67,8 @@ public: {} VArcData(VPointF center, qreal radius, qreal f1) - : f1(f1), formulaF1(QString("%1").arg(f1)), f2(0), formulaF2("0"), radius(radius), - formulaRadius(QString("%1").arg(radius)), center(center), isFlipped(false), formulaLength() + : f1(f1), formulaF1(QString().number(qApp->fromPixel(f1))), f2(0), formulaF2("0"), radius(radius), + formulaRadius(QString().number(qApp->fromPixel(radius))), center(center), isFlipped(false), formulaLength() {} VArcData(const VArcData &arc) diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 8db3ad1a6..c6c2528c0 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -432,8 +432,8 @@ void VEllipticalArc::FindF2(qreal length) d->f2 = endAngle; lenBez = GetLength(); } - d->formulaF2 = QString("%1").arg(d->f2); - d->formulaLength = QString("%1").arg(lenBez); + d->formulaF2 = QString().number(qApp->fromPixel(d->f2)); + d->formulaLength = QString().number(qApp->fromPixel(lenBez)); } //--------------------------------------------------------------------------------------------------------------------- From 771a72711ce415939aa28016ec19b0b5693b1c63 Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 21:37:30 +0200 Subject: [PATCH 20/21] We don't need to use qApp->fromPixel for angles --HG-- branch : feature --- src/libs/vgeometry/varc.cpp | 2 +- src/libs/vgeometry/varc_p.h | 8 ++++---- src/libs/vgeometry/vellipticalarc.cpp | 2 +- src/libs/vgeometry/vellipticalarc_p.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index c26b2de72..10ef8393a 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -354,7 +354,7 @@ void VArc::FindF2(qreal length) startAngle.setAngle(d->f1 + arcAngle);// We use QLineF just because it is easy way correct angle value d->f2 = startAngle.angle(); - d->formulaF2 = QString().number(qApp->fromPixel(d->f2)); + d->formulaF2 = QString().number(d->f2); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vgeometry/varc_p.h b/src/libs/vgeometry/varc_p.h index 841349ff1..b97205b75 100644 --- a/src/libs/vgeometry/varc_p.h +++ b/src/libs/vgeometry/varc_p.h @@ -55,19 +55,19 @@ public: {} VArcData(VPointF center, qreal radius, qreal f1, qreal f2) - : f1(f1), formulaF1(QString().number(qApp->fromPixel(f1))), - f2(f2), formulaF2(QString().number(qApp->fromPixel(f2))), + : f1(f1), formulaF1(QString().number(f1)), + f2(f2), formulaF2(QString().number(f2)), radius(radius), formulaRadius(QString().number(qApp->fromPixel(radius))), center(center), isFlipped(false), formulaLength() {} - VArcData (QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1 ) + VArcData (QString formulaLength, VPointF center, qreal radius, QString formulaRadius, qreal f1, QString formulaF1) : f1(f1), formulaF1(formulaF1), f2(0), formulaF2("0"), radius(radius), formulaRadius(formulaRadius), center(center), isFlipped(false), formulaLength(formulaLength) {} VArcData(VPointF center, qreal radius, qreal f1) - : f1(f1), formulaF1(QString().number(qApp->fromPixel(f1))), f2(0), formulaF2("0"), radius(radius), + : f1(f1), formulaF1(QString().number(f1)), f2(0), formulaF2("0"), radius(radius), formulaRadius(QString().number(qApp->fromPixel(radius))), center(center), isFlipped(false), formulaLength() {} diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index c6c2528c0..9a3e8a946 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -432,7 +432,7 @@ void VEllipticalArc::FindF2(qreal length) d->f2 = endAngle; lenBez = GetLength(); } - d->formulaF2 = QString().number(qApp->fromPixel(d->f2)); + d->formulaF2 = QString().number(d->f2); d->formulaLength = QString().number(qApp->fromPixel(lenBez)); } diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index 325c5ac8f..5d2398b5a 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -23,8 +23,8 @@ public: {} VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal f2, qreal rotationAngle) - : f1(f1), f2(f2), formulaF1(QString().number(qApp->fromPixel(f1))), - formulaF2(QString().number(qApp->fromPixel(f2))), radius1(radius1), radius2(radius2), + : f1(f1), f2(f2), formulaF1(QString().number(f1)), + formulaF2(QString().number(f2)), radius1(radius1), radius2(radius2), formulaRadius1(QString().number(qApp->fromPixel(radius1))), formulaRadius2(QString().number(qApp->fromPixel(radius2))), center(center), isFlipped(false), formulaLength(), rotationAngle(rotationAngle) @@ -39,7 +39,7 @@ public: {} VEllipticalArcData(VPointF center, qreal radius1, qreal radius2, qreal f1, qreal rotationAngle) - : f1(f1), f2(0), formulaF1(QString().number(qApp->fromPixel(f1))), formulaF2("0"), + : f1(f1), f2(0), formulaF1(QString().number(f1)), formulaF2("0"), radius1(radius1), radius2(radius2), formulaRadius1(QString().number(qApp->fromPixel(radius1))), formulaRadius2(QString().number(qApp->fromPixel(radius2))), From 564da52eb113e32e6fe2cff84d49a2634ff678fb Mon Sep 17 00:00:00 2001 From: Valentina Zhuravska Date: Sun, 28 Feb 2016 21:43:23 +0200 Subject: [PATCH 21/21] Changed <../vmisc/vabstractapplication.h> to "../vmisc/vabstractapplication.h" --HG-- branch : feature --- src/libs/vgeometry/varc_p.h | 2 +- src/libs/vgeometry/vellipticalarc_p.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/vgeometry/varc_p.h b/src/libs/vgeometry/varc_p.h index b97205b75..70c3b6393 100644 --- a/src/libs/vgeometry/varc_p.h +++ b/src/libs/vgeometry/varc_p.h @@ -31,7 +31,7 @@ #include #include "vgeometrydef.h" -#include <../vmisc/vabstractapplication.h> +#include "../vmisc/vabstractapplication.h" #include "vpointf.h" #ifdef Q_CC_GNU diff --git a/src/libs/vgeometry/vellipticalarc_p.h b/src/libs/vgeometry/vellipticalarc_p.h index 5d2398b5a..d1515ece0 100644 --- a/src/libs/vgeometry/vellipticalarc_p.h +++ b/src/libs/vgeometry/vellipticalarc_p.h @@ -2,7 +2,7 @@ #define VELLIPTICALARC_P #include -#include <../vmisc/vabstractapplication.h> +#include "../vmisc/vabstractapplication.h" #include "vpointf.h" class VEllipticalArcData : public QSharedData