Make sure that a point is really lies on curve.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-12 14:00:07 +02:00
parent e1d559e1d3
commit caba2db95b
3 changed files with 57 additions and 12 deletions

View File

@ -236,6 +236,33 @@ bool VAbstractCurve::IsIntersectLine(const QLineF &line) const
return not points.isEmpty(); return not points.isEmpty();
} }
//---------------------------------------------------------------------------------------------------------------------
bool VAbstractCurve::IsPointOnCurve(const QPointF &p) const
{
const QVector<QPointF> points = GetPoints();
if (points.isEmpty())
{
return false;
}
else if (points.size() < 2)
{
return points.at(0) == p;
}
else
{
for (qint32 i = 0; i < points.count()-1; ++i)
{
if (IsPointOnLineSegment(p, points.at(i), points.at(i+1)))
{
return true;
}
}
}
return false;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
quint32 VAbstractCurve::GetDuplicate() const quint32 VAbstractCurve::GetDuplicate() const
{ {

View File

@ -70,6 +70,8 @@ public:
virtual QVector<QPointF> IntersectLine(const QLineF &line) const; virtual QVector<QPointF> IntersectLine(const QLineF &line) const;
virtual bool IsIntersectLine(const QLineF &line) const; virtual bool IsIntersectLine(const QLineF &line) const;
bool IsPointOnCurve(const QPointF &p) const;
virtual qreal GetStartAngle () const=0; virtual qreal GetStartAngle () const=0;
virtual qreal GetEndAngle () const=0; virtual qreal GetEndAngle () const=0;

View File

@ -471,22 +471,30 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const
if (at(CountNodes()-1).GetTypeTool() == Tool::NodePoint) if (at(CountNodes()-1).GetTypeTool() == Tool::NodePoint)
{ {
const VPieceNode node = at(CountNodes()-1); const VPieceNode node = at(CountNodes()-1);
begin = VSAPoint(*data->GeometricObject<VPointF>(node.GetId())); const QPointF p = *data->GeometricObject<VPointF>(node.GetId());
if (curve->IsPointOnCurve(p))
{
begin = VSAPoint(p);
begin.SetSAAfter(node.GetSAAfter()); begin.SetSAAfter(node.GetSAAfter());
begin.SetSABefore(node.GetSABefore()); begin.SetSABefore(node.GetSABefore());
} }
} }
}
else else
{ {
if (at(i-1).GetTypeTool() == Tool::NodePoint) if (at(i-1).GetTypeTool() == Tool::NodePoint)
{ {
const VPieceNode node = at(i-1); const VPieceNode node = at(i-1);
begin = VSAPoint(*data->GeometricObject<VPointF>(node.GetId())); const QPointF p = *data->GeometricObject<VPointF>(node.GetId());
if (curve->IsPointOnCurve(p))
{
begin = VSAPoint(p);
begin.SetSAAfter(node.GetSAAfter()); begin.SetSAAfter(node.GetSAAfter());
begin.SetSABefore(node.GetSABefore()); begin.SetSABefore(node.GetSABefore());
} }
} }
} }
}
return begin; return begin;
} }
@ -514,22 +522,30 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const
if (at(0).GetTypeTool() == Tool::NodePoint) if (at(0).GetTypeTool() == Tool::NodePoint)
{ {
const VPieceNode node = at(0); const VPieceNode node = at(0);
end = VSAPoint(*data->GeometricObject<VPointF>(node.GetId())); const QPointF p = *data->GeometricObject<VPointF>(node.GetId());
if (curve->IsPointOnCurve(p))
{
end = VSAPoint(p);
end.SetSAAfter(node.GetSAAfter()); end.SetSAAfter(node.GetSAAfter());
end.SetSABefore(node.GetSABefore()); end.SetSABefore(node.GetSABefore());
} }
} }
}
else else
{ {
if (at(i+1).GetTypeTool() == Tool::NodePoint) if (at(i+1).GetTypeTool() == Tool::NodePoint)
{ {
const VPieceNode node = at(i+1); const VPieceNode node = at(i+1);
end = VSAPoint(*data->GeometricObject<VPointF>(node.GetId())); const QPointF p = *data->GeometricObject<VPointF>(node.GetId());
if (curve->IsPointOnCurve(p))
{
end = VSAPoint(p);
end.SetSAAfter(node.GetSAAfter()); end.SetSAAfter(node.GetSAAfter());
end.SetSABefore(node.GetSABefore()); end.SetSABefore(node.GetSABefore());
} }
} }
} }
}
return end; return end;
} }