More tools should show a warning if cannot find a result.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-06-07 14:37:43 +03:00
parent cc6c178b17
commit e244d002cc
19 changed files with 162 additions and 101 deletions

View File

@ -133,7 +133,16 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis
const qreal angle = CheckFormula(initData.id, initData.formulaAngle, initData.data); const qreal angle = CheckFormula(initData.id, initData.formulaAngle, initData.data);
const QSharedPointer<VAbstractCurve> curve = initData.data->GeometricObject<VAbstractCurve>(initData.curveId); const QSharedPointer<VAbstractCurve> curve = initData.data->GeometricObject<VAbstractCurve>(initData.curveId);
const QPointF fPoint = FindPoint(static_cast<QPointF>(*basePoint), angle, curve->GetPoints()); QPointF fPoint;
const bool success = FindPoint(static_cast<QPointF>(*basePoint), angle, curve->GetPoints(), &fPoint);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. There is no intersection with curve '%2' and axis through "
"point '%3' with angle %4°")
.arg(initData.name, curve->name(), basePoint->name()).arg(angle);
}
const qreal segLength = curve->GetLengthByPoint(fPoint); const qreal segLength = curve->GetLengthByPoint(fPoint);
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
@ -176,9 +185,11 @@ VToolCurveIntersectAxis *VToolCurveIntersectAxis::Create(VToolCurveIntersectAxis
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, bool VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle, const QVector<QPointF> &curvePoints,
const QVector<QPointF> &curvePoints) QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QRectF rec = QRectF(0, 0, INT_MAX, INT_MAX); QRectF rec = QRectF(0, 0, INT_MAX, INT_MAX);
rec.translate(-INT_MAX/2.0, -INT_MAX/2.0); rec.translate(-INT_MAX/2.0, -INT_MAX/2.0);
@ -189,7 +200,8 @@ QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle,
{ {
if (points.size() == 1) if (points.size() == 1)
{ {
return points.at(0); *intersectionPoint = points.at(0);
return true;
} }
QMap<qreal, int> forward; QMap<qreal, int> forward;
@ -216,15 +228,17 @@ QPointF VToolCurveIntersectAxis::FindPoint(const QPointF &point, qreal angle,
// Closest point is not always want we need. First return point in forward direction if exists. // Closest point is not always want we need. First return point in forward direction if exists.
if (not forward.isEmpty()) if (not forward.isEmpty())
{ {
return points.at(forward.first()); *intersectionPoint = points.at(forward.first());
return true;
} }
else if (not backward.isEmpty()) else if (not backward.isEmpty())
{ {
return points.at(backward.first()); *intersectionPoint = points.at(backward.first());
return true;
} }
} }
return QPointF(); return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -71,7 +71,8 @@ public:
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);
static VToolCurveIntersectAxis *Create(VToolCurveIntersectAxisInitData &initData); static VToolCurveIntersectAxis *Create(VToolCurveIntersectAxisInitData &initData);
static QPointF FindPoint(const QPointF &point, qreal angle, const QVector<QPointF> &curvePoints); static bool FindPoint(const QPointF &point, qreal angle, const QVector<QPointF> &curvePoints,
QPointF *intersectionPoint);
static const QString ToolType; static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -124,7 +124,15 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisIni
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId); const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QLineF line(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint)); QLineF line(static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint));
QPointF fPoint = FindPoint(axis, line); QPointF fPoint;
const bool success = FindPoint(axis, line, &fPoint);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. Line (%2;%3) doesn't have intersection with axis through "
"point '%4' and angle %5°")
.arg(initData.name, firstPoint->name(), secondPoint->name(), basePoint->name()).arg(axis.angle());
}
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel); p->SetShowLabel(initData.showLabel);
@ -164,8 +172,10 @@ VToolLineIntersectAxis *VToolLineIntersectAxis::Create(VToolLineIntersectAxisIni
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line) bool VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line, QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QPointF fPoint; QPointF fPoint;
QLineF::IntersectType intersect = axis.intersect(line, &fPoint); QLineF::IntersectType intersect = axis.intersect(line, &fPoint);
if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection) if (intersect == QLineF::UnboundedIntersection || intersect == QLineF::BoundedIntersection)
@ -173,16 +183,17 @@ QPointF VToolLineIntersectAxis::FindPoint(const QLineF &axis, const QLineF &line
if(VFuzzyComparePossibleNulls(axis.angle(), line.angle()) if(VFuzzyComparePossibleNulls(axis.angle(), line.angle())
|| VFuzzyComparePossibleNulls(qAbs(axis.angle() - line.angle()), 180)) || VFuzzyComparePossibleNulls(qAbs(axis.angle() - line.angle()), 180))
{ {
return QPointF(); return false;
} }
else else
{ {
return fPoint; *intersectionPoint = fPoint;
return true;
} }
} }
else else
{ {
return QPointF(); return false;
} }
} }

View File

@ -73,7 +73,7 @@ public:
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);
static VToolLineIntersectAxis *Create(VToolLineIntersectAxisInitData &initData); static VToolLineIntersectAxis *Create(VToolLineIntersectAxisInitData &initData);
static QPointF FindPoint(const QLineF &axis, const QLineF &line); static bool FindPoint(const QLineF &axis, const QLineF &line, QPointF *intersectionPoint);
static const QString ToolType; static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}

View File

@ -112,8 +112,15 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA
const VArc arc = *initData.data->GeometricObject<VArc>(initData.arcId); const VArc arc = *initData.data->GeometricObject<VArc>(initData.arcId);
const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId); const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId);
const QPointF point = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(tPoint), &arc, QPointF point;
initData.crossPoint); const bool success = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(tPoint), &arc,
initData.crossPoint, &point);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. Tangent to arc '%2' from point '%3' cannot be found")
.arg(initData.name, arc.name(), tPoint.name());
}
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel); p->SetShowLabel(initData.showLabel);
@ -146,8 +153,11 @@ VToolPointFromArcAndTangent *VToolPointFromArcAndTangent::Create(VToolPointFromA
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType) bool VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType,
QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QPointF p1, p2; QPointF p1, p2;
const QPointF center = static_cast<QPointF>(arc->GetCenter()); const QPointF center = static_cast<QPointF>(arc->GetCenter());
const qreal radius = arc->GetRadius(); const qreal radius = arc->GetRadius();
@ -180,26 +190,14 @@ QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc
switch(localRes) switch(localRes)
{ {
case 2: case 2:
if (pType == CrossCirclesPoint::FirstPoint) *intersectionPoint = (pType == CrossCirclesPoint::FirstPoint ? p1 : p2);
{ return true;
return p1;
}
else
{
return p2;
}
case 1: case 1:
if (flagP1) *intersectionPoint = (flagP1 ? p1 : p2);
{ return true;
return p1;
}
else
{
return p2;
}
case 0: case 0:
default: default:
return QPointF(); return false;
} }
break; break;
@ -207,18 +205,19 @@ QPointF VToolPointFromArcAndTangent::FindPoint(const QPointF &p, const VArc *arc
case 1: case 1:
if (arc->IsIntersectLine(r1Arc)) if (arc->IsIntersectLine(r1Arc))
{ {
return p1; *intersectionPoint = p1;
return true;
} }
else else
{ {
return QPointF(); return false;
} }
case 3: case 3:
case 0: case 0:
default: default:
break; break;
} }
return QPointF(); return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -66,7 +66,7 @@ public:
static VToolPointFromArcAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, static VToolPointFromArcAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);
static VToolPointFromArcAndTangent *Create(VToolPointFromArcAndTangentInitData initData); static VToolPointFromArcAndTangent *Create(VToolPointFromArcAndTangentInitData initData);
static QPointF FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType); static bool FindPoint(const QPointF &p, const VArc *arc, const CrossCirclesPoint pType, QPointF *intersectionPoint);
static const QString ToolType; static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::PointFromArcAndTangent) }; enum { Type = UserType + static_cast<int>(Tool::PointFromArcAndTangent) };

View File

@ -117,9 +117,16 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPoin
const VPointF cPoint = *initData.data->GeometricObject<VPointF>(initData.circleCenterId); const VPointF cPoint = *initData.data->GeometricObject<VPointF>(initData.circleCenterId);
const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId); const VPointF tPoint = *initData.data->GeometricObject<VPointF>(initData.tangentPointId);
const QPointF point = VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(tPoint), QPointF point;
const bool success = VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(tPoint),
static_cast<QPointF>(cPoint), radius, static_cast<QPointF>(cPoint), radius,
initData.crossPoint); initData.crossPoint, &point);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. Tangent to circle with center '%2' and radius '%3' from "
"point '%4' cannot be found")
.arg(initData.name, cPoint.name()).arg(radius).arg(tPoint.name());
}
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel); p->SetShowLabel(initData.showLabel);
@ -152,29 +159,26 @@ VToolPointFromCircleAndTangent *VToolPointFromCircleAndTangent::Create(VToolPoin
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QPointF VToolPointFromCircleAndTangent::FindPoint(const QPointF &p, const QPointF &center, qreal radius, bool VToolPointFromCircleAndTangent::FindPoint(const QPointF &p, const QPointF &center, qreal radius,
const CrossCirclesPoint crossPoint) const CrossCirclesPoint crossPoint, QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QPointF p1, p2; QPointF p1, p2;
const int res = VGObject::ContactPoints (p, center, radius, p1, p2); const int res = VGObject::ContactPoints (p, center, radius, p1, p2);
switch(res) switch(res)
{ {
case 2: case 2:
if (crossPoint == CrossCirclesPoint::FirstPoint) *intersectionPoint = (crossPoint == CrossCirclesPoint::FirstPoint ? p1 : p2);
{ return true;
return p1;
}
else
{
return p2;
}
case 1: case 1:
return p1; *intersectionPoint = p1;
return true;
case 3: case 3:
case 0: case 0:
default: default:
return QPointF(); return false;
} }
} }

View File

@ -69,7 +69,8 @@ public:
static VToolPointFromCircleAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, static VToolPointFromCircleAndTangent *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);
static VToolPointFromCircleAndTangent *Create(VToolPointFromCircleAndTangentInitData &initData); static VToolPointFromCircleAndTangent *Create(VToolPointFromCircleAndTangentInitData &initData);
static QPointF FindPoint(const QPointF &p, const QPointF &center, qreal radius, const CrossCirclesPoint crossPoint); static bool FindPoint(const QPointF &p, const QPointF &center, qreal radius, const CrossCirclesPoint crossPoint,
QPointF *intersectionPoint);
static const QString ToolType; static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::PointFromCircleAndTangent) }; enum { Type = UserType + static_cast<int>(Tool::PointFromCircleAndTangent) };

View File

@ -100,19 +100,23 @@ void VToolPointOfContact::setDialog()
* @param center center arc point. * @param center center arc point.
* @param firstPoint first line point. * @param firstPoint first line point.
* @param secondPoint second line point. * @param secondPoint second line point.
* @return point intersection. * @param intersectionPoint point of intersection.
* @return true if intersection exists.
*/ */
QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint, bool VToolPointOfContact::FindPoint(qreal radius, const QPointF &center, const QPointF &firstPoint,
const QPointF &secondPoint) const QPointF &secondPoint, QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QPointF p1, p2; QPointF p1, p2;
qint32 res = VGObject::LineIntersectCircle(center, radius, QLineF(firstPoint, secondPoint), p1, p2); qint32 res = VGObject::LineIntersectCircle(center, radius, QLineF(firstPoint, secondPoint), p1, p2);
switch (res) switch (res)
{ {
case 0: case 0:
return QPointF(); return false;
case 1: case 1:
return p1; *intersectionPoint = p1;
return true;
case 2: case 2:
{ {
const bool flagP1 = VGObject::IsPointOnLineSegment (p1, firstPoint, secondPoint); const bool flagP1 = VGObject::IsPointOnLineSegment (p1, firstPoint, secondPoint);
@ -123,22 +127,26 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &cente
// We don't have options for choosing correct point. Use closest to segment first point. // We don't have options for choosing correct point. Use closest to segment first point.
if (QLineF(firstPoint, p1).length() <= QLineF(firstPoint, p2).length()) if (QLineF(firstPoint, p1).length() <= QLineF(firstPoint, p2).length())
{ {
return p1; *intersectionPoint = p1;
return true;
} }
else else
{ {
return p2; *intersectionPoint = p2;
return true;
} }
} }
else else
{ // In this case we have one real and one theoretical intersection. { // In this case we have one real and one theoretical intersection.
if (flagP1) if (flagP1)
{ {
return p1; *intersectionPoint = p1;
return true;
} }
else else
{ {
return p2; *intersectionPoint = p2;
return true;
} }
} }
} }
@ -146,7 +154,7 @@ QPointF VToolPointOfContact::FindPoint(const qreal &radius, const QPointF &cente
qDebug() << "Unxpected value" << res; qDebug() << "Unxpected value" << res;
break; break;
} }
return QPointF(); return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -197,8 +205,17 @@ VToolPointOfContact* VToolPointOfContact::Create(VToolPointOfContactInitData &in
const qreal result = CheckFormula(initData.id, initData.radius, initData.data); const qreal result = CheckFormula(initData.id, initData.radius, initData.data);
QPointF fPoint = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast<QPointF>(*centerP), QPointF fPoint;
static_cast<QPointF>(*firstP), static_cast<QPointF>(*secondP)); const bool success = VToolPointOfContact::FindPoint(qApp->toPixel(result), static_cast<QPointF>(*centerP),
static_cast<QPointF>(*firstP), static_cast<QPointF>(*secondP),
&fPoint);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. Circle with center '%2' and radius '%3' doesn't have "
"intersection with line (%4;%5)")
.arg(initData.name, centerP->name()).arg(result).arg(firstP->name(), secondP->name());
}
VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(fPoint, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel); p->SetShowLabel(initData.showLabel);

View File

@ -69,8 +69,8 @@ class VToolPointOfContact : public VToolSinglePoint
Q_OBJECT Q_OBJECT
public: public:
virtual void setDialog() Q_DECL_OVERRIDE; virtual void setDialog() Q_DECL_OVERRIDE;
static QPointF FindPoint(const qreal &radius, const QPointF &center, const QPointF &firstPoint, static bool FindPoint(qreal radius, const QPointF &center, const QPointF &firstPoint,
const QPointF &secondPoint); const QPointF &secondPoint, QPointF *intersectionPoint);
static VToolPointOfContact* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, static VToolPointOfContact* Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene,
VAbstractPattern *doc, VContainer *data); VAbstractPattern *doc, VContainer *data);
static VToolPointOfContact* Create(VToolPointOfContactInitData &initData); static VToolPointOfContact* Create(VToolPointOfContactInitData &initData);

View File

@ -126,7 +126,7 @@ VToolTriangle* VToolTriangle::Create(QSharedPointer<DialogTool> dialog, VMainGra
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief Create help create tool. * @brief Create helps to create the tool.
* @param initData init data. * @param initData init data.
* @return the created tool * @return the created tool
*/ */
@ -137,8 +137,15 @@ VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData)
const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId); const QSharedPointer<VPointF> firstPoint = initData.data->GeometricObject<VPointF>(initData.firstPointId);
const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId); const QSharedPointer<VPointF> secondPoint = initData.data->GeometricObject<VPointF>(initData.secondPointId);
QPointF point = FindPoint(static_cast<QPointF>(*axisP1), static_cast<QPointF>(*axisP2), QPointF point;
static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint)); const bool success = FindPoint(static_cast<QPointF>(*axisP1), static_cast<QPointF>(*axisP2),
static_cast<QPointF>(*firstPoint), static_cast<QPointF>(*secondPoint), &point);
if (not success)
{
qWarning() << tr("Error calculating point '%1'. Point of intersection cannot be finded")
.arg(initData.name);
}
VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my); VPointF *p = new VPointF(point, initData.name, initData.mx, initData.my);
p->SetShowLabel(initData.showLabel); p->SetShowLabel(initData.showLabel);
@ -179,11 +186,14 @@ VToolTriangle* VToolTriangle::Create(VToolTriangleInitData initData)
* @param axisP2 second axis point. * @param axisP2 second axis point.
* @param firstPoint first triangle point, what lies on the hypotenuse. * @param firstPoint first triangle point, what lies on the hypotenuse.
* @param secondPoint second triangle point, what lies on the hypotenuse. * @param secondPoint second triangle point, what lies on the hypotenuse.
* @return point intersection two foots right triangle. * @param intersectionPoint point intersection two foots right triangle
* @return true if the intersection exists.
*/ */
QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, bool VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint,
const QPointF &secondPoint) const QPointF &secondPoint, QPointF *intersectionPoint)
{ {
SCASSERT(intersectionPoint != nullptr)
QLineF axis(axisP1, axisP2); QLineF axis(axisP1, axisP2);
QLineF hypotenuse(firstPoint, secondPoint); QLineF hypotenuse(firstPoint, secondPoint);
@ -191,12 +201,12 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c
QLineF::IntersectType intersect = axis.intersect(hypotenuse, &startPoint); QLineF::IntersectType intersect = axis.intersect(hypotenuse, &startPoint);
if (intersect != QLineF::UnboundedIntersection && intersect != QLineF::BoundedIntersection) if (intersect != QLineF::UnboundedIntersection && intersect != QLineF::BoundedIntersection)
{ {
return QPointF(); return false;
} }
if (VFuzzyComparePossibleNulls(axis.angle(), hypotenuse.angle()) if (VFuzzyComparePossibleNulls(axis.angle(), hypotenuse.angle())
|| VFuzzyComparePossibleNulls(qAbs(axis.angle() - hypotenuse.angle()), 180)) || VFuzzyComparePossibleNulls(qAbs(axis.angle() - hypotenuse.angle()), 180))
{ {
return QPointF(); return false;
} }
qreal step = 1; qreal step = 1;
@ -214,10 +224,11 @@ QPointF VToolTriangle::FindPoint(const QPointF &axisP1, const QPointF &axisP2, c
qint64 b = qFloor(QLineF(line.p2(), secondPoint).length()); qint64 b = qFloor(QLineF(line.p2(), secondPoint).length());
if (c*c <= (a*a + b*b)) if (c*c <= (a*a + b*b))
{ {
return line.p2(); *intersectionPoint = line.p2();
return true;
} }
} }
return QPointF(); return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -72,8 +72,8 @@ public:
static VToolTriangle *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc, static VToolTriangle *Create(QSharedPointer<DialogTool> dialog, VMainGraphicsScene *scene, VAbstractPattern *doc,
VContainer *data); VContainer *data);
static VToolTriangle *Create(VToolTriangleInitData initData); static VToolTriangle *Create(VToolTriangleInitData initData);
static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, static bool FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint,
const QPointF &secondPoint); const QPointF &secondPoint, QPointF *intersectionPoint);
static const QString ToolType; static const QString ToolType;
virtual int type() const Q_DECL_OVERRIDE {return Type;} virtual int type() const Q_DECL_OVERRIDE {return Type;}
enum { Type = UserType + static_cast<int>(Tool::Triangle)}; enum { Type = UserType + static_cast<int>(Tool::Triangle)};

View File

@ -83,8 +83,8 @@ void VisToolCurveIntersectAxis::RefreshGeometry()
DrawPoint(basePoint, static_cast<QPointF>(*first), mainColor); DrawPoint(basePoint, static_cast<QPointF>(*first), mainColor);
DrawLine(axisLine, axis, supportColor, Qt::DashLine); DrawLine(axisLine, axis, supportColor, Qt::DashLine);
QPointF p = VToolCurveIntersectAxis::FindPoint(static_cast<QPointF>(*first), axis.angle(), QPointF p;
curve->GetPoints()); VToolCurveIntersectAxis::FindPoint(static_cast<QPointF>(*first), axis.angle(), curve->GetPoints(), &p);
QLineF axis_line(static_cast<QPointF>(*first), p); QLineF axis_line(static_cast<QPointF>(*first), p);
DrawLine(this, axis_line, mainColor, lineStyle); DrawLine(this, axis_line, mainColor, lineStyle);

View File

@ -94,7 +94,8 @@ void VisToolLineIntersectAxis::RefreshGeometry()
DrawPoint(basePoint, static_cast<QPointF>(*third), mainColor); DrawPoint(basePoint, static_cast<QPointF>(*third), mainColor);
DrawLine(axisLine, axis, supportColor, Qt::DashLine); DrawLine(axisLine, axis, supportColor, Qt::DashLine);
QPointF p = VToolLineIntersectAxis::FindPoint(axis, base_line); QPointF p;
VToolLineIntersectAxis::FindPoint(axis, base_line, &p);
QLineF axis_line(static_cast<QPointF>(*third), p); QLineF axis_line(static_cast<QPointF>(*third), p);
DrawLine(this, axis_line, mainColor, lineStyle); DrawLine(this, axis_line, mainColor, lineStyle);

View File

@ -72,8 +72,8 @@ void VisToolPointFromArcAndTangent::RefreshGeometry()
FindRays(static_cast<QPointF>(*tan), arc.data()); FindRays(static_cast<QPointF>(*tan), arc.data());
const QPointF fPoint = VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(*tan), arc.data(), QPointF fPoint;
crossPoint); VToolPointFromArcAndTangent::FindPoint(static_cast<QPointF>(*tan), arc.data(), crossPoint, &fPoint);
DrawPoint(point, fPoint, mainColor); DrawPoint(point, fPoint, mainColor);
} }
} }

View File

@ -74,9 +74,9 @@ void VisToolPointFromCircleAndTangent::RefreshGeometry()
FindRays(static_cast<QPointF>(*tan), static_cast<QPointF>(*center), cRadius); FindRays(static_cast<QPointF>(*tan), static_cast<QPointF>(*center), cRadius);
const QPointF fPoint = VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(*tan), QPointF fPoint;
static_cast<QPointF>(*center), VToolPointFromCircleAndTangent::FindPoint(static_cast<QPointF>(*tan), static_cast<QPointF>(*center),
cRadius, crossPoint); cRadius, crossPoint, &fPoint);
DrawPoint(point, fPoint, mainColor); DrawPoint(point, fPoint, mainColor);
} }
} }

View File

@ -80,9 +80,9 @@ void VisToolPointOfContact::RefreshGeometry()
if (not qFuzzyIsNull(radius)) if (not qFuzzyIsNull(radius))
{ {
QPointF fPoint = VToolPointOfContact::FindPoint(radius, static_cast<QPointF>(*third), QPointF fPoint;
static_cast<QPointF>(*first), VToolPointOfContact::FindPoint(radius, static_cast<QPointF>(*third), static_cast<QPointF>(*first),
static_cast<QPointF>(*second)); static_cast<QPointF>(*second), &fPoint);
DrawPoint(point, fPoint, mainColor); DrawPoint(point, fPoint, mainColor);
circle->setRect(PointRect(radius)); circle->setRect(PointRect(radius));

View File

@ -91,9 +91,9 @@ void VisToolTriangle::RefreshGeometry()
DrawLine(this, QLineF(static_cast<QPointF>(*third), Visualization::scenePos), supportColor, DrawLine(this, QLineF(static_cast<QPointF>(*third), Visualization::scenePos), supportColor,
Qt::DashLine); Qt::DashLine);
QPointF trPoint = VToolTriangle::FindPoint(static_cast<QPointF>(*first), QPointF trPoint;
static_cast<QPointF>(*second), VToolTriangle::FindPoint(static_cast<QPointF>(*first), static_cast<QPointF>(*second),
static_cast<QPointF>(*third), Visualization::scenePos); static_cast<QPointF>(*third), Visualization::scenePos, &trPoint);
DrawPoint(point, trPoint, mainColor); DrawPoint(point, trPoint, mainColor);
DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor, Qt::DashLine); DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor, Qt::DashLine);
@ -107,10 +107,9 @@ void VisToolTriangle::RefreshGeometry()
DrawLine(this, QLineF(static_cast<QPointF>(*third), static_cast<QPointF>(*forth)), supportColor, DrawLine(this, QLineF(static_cast<QPointF>(*third), static_cast<QPointF>(*forth)), supportColor,
Qt::DashLine); Qt::DashLine);
QPointF trPoint = VToolTriangle::FindPoint(static_cast<QPointF>(*first), QPointF trPoint;
static_cast<QPointF>(*second), VToolTriangle::FindPoint(static_cast<QPointF>(*first), static_cast<QPointF>(*second),
static_cast<QPointF>(*third), static_cast<QPointF>(*third), static_cast<QPointF>(*forth), &trPoint);
static_cast<QPointF>(*forth));
DrawPoint(point, trPoint, mainColor); DrawPoint(point, trPoint, mainColor);
DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor, Qt::DashLine); DrawLine(foot1, QLineF(static_cast<QPointF>(*third), trPoint), supportColor, Qt::DashLine);

View File

@ -235,7 +235,8 @@ void TST_FindPoint::TestLineIntersectAxis()
QFETCH(QLineF, line); QFETCH(QLineF, line);
QFETCH(QPointF, point); QFETCH(QPointF, point);
QPointF resultPoint = VToolLineIntersectAxis::FindPoint(axis, line); QPointF resultPoint;
VToolLineIntersectAxis::FindPoint(axis, line, &resultPoint);
QCOMPARE(point, resultPoint); QCOMPARE(point, resultPoint);
} }
@ -266,7 +267,8 @@ void TST_FindPoint::TestTriangle()
QFETCH(QPointF, secondPoint); QFETCH(QPointF, secondPoint);
QFETCH(QPointF, point); QFETCH(QPointF, point);
QPointF resultPoint = VToolTriangle::FindPoint(axisP1, axisP2, firstPoint, secondPoint); QPointF resultPoint;
VToolTriangle::FindPoint(axisP1, axisP2, firstPoint, secondPoint, &resultPoint);
QCOMPARE(point, resultPoint); QCOMPARE(point, resultPoint);
} }
@ -544,7 +546,8 @@ void TST_FindPoint::TestCurveIntersectAxis()
QFETCH(QVector<QPointF>, curvePoints); QFETCH(QVector<QPointF>, curvePoints);
QFETCH(QPointF, result); QFETCH(QPointF, result);
const QPointF resultPoint = VToolCurveIntersectAxis::FindPoint(basePoint, angle, curvePoints); QPointF resultPoint;
VToolCurveIntersectAxis::FindPoint(basePoint, angle, curvePoints, &resultPoint);
QCOMPARE(result, resultPoint); QCOMPARE(result, resultPoint);
} }