VSAPoint class should keep data in pixels. Make testing a lot easier.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2016-11-17 14:08:23 +02:00
parent afb267c05c
commit a284ac024e
4 changed files with 40 additions and 19 deletions

View file

@ -333,13 +333,13 @@ Q_DECL_CONSTEXPR qreal VAbstractPiece::PointPosition(const QPointF &p, const QLi
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VAbstractPiece::MaxLocalSA(const VSAPoint &p, qreal width) qreal VAbstractPiece::MaxLocalSA(const VSAPoint &p, qreal width)
{ {
qreal w1 = qApp->toPixel(p.GetSAAfter()); qreal w1 = p.GetSAAfter();
if (w1 < 0) if (w1 < 0)
{ {
w1 = width; w1 = width;
} }
qreal w2 = qApp->toPixel(p.GetSABefore()); qreal w2 = p.GetSABefore();
if (w2 < 0) if (w2 < 0)
{ {
w2 = width; w2 = width;
@ -493,13 +493,13 @@ QVector<QPointF> VAbstractPiece::EkvPoint(const VSAPoint &p1Line1, const VSAPoin
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QLineF VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width) QLineF VAbstractPiece::ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width)
{ {
qreal w1 = qApp->toPixel(p1.GetSAAfter()); qreal w1 = p1.GetSAAfter();
if (w1 < 0) if (w1 < 0)
{ {
w1 = width; w1 = width;
} }
qreal w2 = qApp->toPixel(p2.GetSABefore()); qreal w2 = p2.GetSABefore();
if (w2 < 0) if (w2 < 0)
{ {
w2 = width; w2 = width;

View file

@ -221,8 +221,9 @@ QVector<QPointF> VPiece::SeamAllowancePoints(const VContainer *data) const
{ {
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(node.GetId()); const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(node.GetId());
VSAPoint p(point->toQPointF()); VSAPoint p(point->toQPointF());
p.SetSAAfter(node.GetSAAfter());
p.SetSABefore(node.GetSABefore()); p.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit()));
p.SetSABefore(node.GetSABefore(*data->GetPatternUnit()));
pointsEkv.append(p); pointsEkv.append(p);
} }
break; break;
@ -411,13 +412,11 @@ void VPiece::CurveSeamAllowanceSegment(QVector<VSAPoint> &pointsEkv, const VCont
{ {
const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit());
w1 = ToPixel(w1, *data->GetPatternUnit());
if (w1 < 0) if (w1 < 0)
{ {
w1 = width; w1 = width;
} }
w2 = ToPixel(w2, *data->GetPatternUnit());
if (w2 < 0) if (w2 < 0)
{ {
w2 = width; w2 = width;
@ -445,9 +444,7 @@ void VPiece::CurveSeamAllowanceSegment(QVector<VSAPoint> &pointsEkv, const VCont
else else
{ {
length += QLineF(points.at(i-1), points.at(i)).length(); length += QLineF(points.at(i-1), points.at(i)).length();
const qreal localWidth = w1 + wDiff*(length/fullLength);
qreal localWidth = w1 + wDiff*(length/fullLength);
localWidth = FromPixel(localWidth, *data->GetPatternUnit());
p.SetSAAfter(localWidth); p.SetSAAfter(localWidth);
p.SetSABefore(localWidth); p.SetSABefore(localWidth);
@ -486,8 +483,8 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const
if (curve->IsPointOnCurve(p)) if (curve->IsPointOnCurve(p))
{ {
begin = VSAPoint(p); begin = VSAPoint(p);
begin.SetSAAfter(node.GetSAAfter()); begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit()));
begin.SetSABefore(node.GetSABefore()); begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit()));
} }
} }
} }
@ -500,8 +497,8 @@ VSAPoint VPiece::StartSegment(const VContainer *data, int i, bool reverse) const
if (curve->IsPointOnCurve(p)) if (curve->IsPointOnCurve(p))
{ {
begin = VSAPoint(p); begin = VSAPoint(p);
begin.SetSAAfter(node.GetSAAfter()); begin.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit()));
begin.SetSABefore(node.GetSABefore()); begin.SetSABefore(node.GetSABefore(*data->GetPatternUnit()));
} }
} }
} }
@ -537,8 +534,8 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const
if (curve->IsPointOnCurve(p)) if (curve->IsPointOnCurve(p))
{ {
end = VSAPoint(p); end = VSAPoint(p);
end.SetSAAfter(node.GetSAAfter()); end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit()));
end.SetSABefore(node.GetSABefore()); end.SetSABefore(node.GetSABefore(*data->GetPatternUnit()));
} }
} }
} }
@ -551,8 +548,8 @@ VSAPoint VPiece::EndSegment(const VContainer *data, int i, bool reverse) const
if (curve->IsPointOnCurve(p)) if (curve->IsPointOnCurve(p))
{ {
end = VSAPoint(p); end = VSAPoint(p);
end.SetSAAfter(node.GetSAAfter()); end.SetSAAfter(node.GetSAAfter(*data->GetPatternUnit()));
end.SetSABefore(node.GetSABefore()); end.SetSABefore(node.GetSABefore(*data->GetPatternUnit()));
} }
} }
} }

View file

@ -104,6 +104,17 @@ qreal VPieceNode::GetSABefore() const
return d->m_saBefore; return d->m_saBefore;
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VPieceNode::GetSABefore(Unit unit) const
{
qreal value = d->m_saBefore;
if (value >= 0)
{
value = ToPixel(value, unit);
}
return value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceNode::SetSABefore(qreal value) void VPieceNode::SetSABefore(qreal value)
{ {
@ -119,6 +130,17 @@ qreal VPieceNode::GetSAAfter() const
return d->m_saAfter; return d->m_saAfter;
} }
//---------------------------------------------------------------------------------------------------------------------
qreal VPieceNode::GetSAAfter(Unit unit) const
{
qreal value = d->m_saAfter;
if (value >= 0)
{
value = ToPixel(value, unit);
}
return value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPieceNode::SetSAAfter(qreal value) void VPieceNode::SetSAAfter(qreal value)
{ {

View file

@ -59,9 +59,11 @@ public:
void SetReverse(bool reverse); void SetReverse(bool reverse);
qreal GetSABefore() const; qreal GetSABefore() const;
qreal GetSABefore(Unit unit) const;
void SetSABefore(qreal value); void SetSABefore(qreal value);
qreal GetSAAfter() const; qreal GetSAAfter() const;
qreal GetSAAfter(Unit unit) const;
void SetSAAfter(qreal value); void SetSAAfter(qreal value);
private: private:
QSharedDataPointer<VPieceNodeData> d; QSharedDataPointer<VPieceNodeData> d;