Use wxPoint2DDouble in wxPostScriptDC::DrawSpline

We can simplify the code by using wxPoint2DDouble in the calculations.
This commit is contained in:
Artur Wieczorek
2021-07-04 20:35:19 +02:00
parent 9b542a965e
commit 1e2dbcbc24

View File

@@ -1451,75 +1451,66 @@ void wxPostScriptDCImpl::DoDrawSpline( const wxPointList *points )
SetPen( m_pen ); SetPen( m_pen );
double c, d, x1, y1, x3, y3;
wxPoint *p, *q;
wxPointList::compatibility_iterator node = points->GetFirst(); wxPointList::compatibility_iterator node = points->GetFirst();
p = node->GetData(); wxPoint* p = node->GetData();
x1 = p->x; wxPoint2DDouble p1(*p);
y1 = p->y;
node = node->GetNext(); node = node->GetNext();
p = node->GetData(); p = node->GetData();
c = p->x; wxPoint2DDouble p2(*p);
d = p->y; wxPoint2DDouble p3 = (p1 + p2) / 2.0;
x3 = (double)(x1 + c) / 2;
y3 = (double)(y1 + d) / 2;
wxString buffer; wxString buffer;
buffer.Printf( "newpath\n" buffer.Printf( "newpath\n"
"%f %f moveto\n" "%f %f moveto\n"
"%f %f lineto\n", "%f %f lineto\n",
XLOG2DEV(wxRound(x1)), YLOG2DEV(wxRound(y1)), XLOG2DEV(wxRound(p1.m_x)), YLOG2DEV(wxRound(p1.m_y)),
XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3)) ); XLOG2DEV(wxRound(p3.m_x)), YLOG2DEV(wxRound(p3.m_y)) );
buffer.Replace( ",", "." ); buffer.Replace( ",", "." );
PsPrint( buffer ); PsPrint( buffer );
CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); CalcBoundingBox( (wxCoord)p1.m_x, (wxCoord)p1.m_y );
CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); CalcBoundingBox( (wxCoord)p3.m_x, (wxCoord)p3.m_y );
node = node->GetNext(); node = node->GetNext();
while (node) while (node)
{ {
double x2, y2; p = node->GetData();
q = node->GetData();
x1 = x3; wxPoint2DDouble p0 = p3;
y1 = y3; p1 = p2;
x2 = c; p2 = *p;
y2 = d; p3 = (p1 + p2) / 2.0;
c = q->x;
d = q->y;
x3 = (double)(x2 + c) / 2;
y3 = (double)(y2 + d) / 2;
// Calculate using degree elevation to a cubic bezier // Calculate using degree elevation to a cubic bezier
wxDouble c1x = (x1 + 2 * x2) / 3.0; wxPoint2DDouble c1 = (p0 + (p1 * 2.0)) / 3.0;
wxDouble c1y = (y1 + 2 * y2) / 3.0; wxPoint2DDouble c2 = ((p1 * 2.0) + p3) / 3.0;
wxDouble c2x = (2 * x2 + x3) / 3.0;
wxDouble c2y = (2 * y2 + y3) / 3.0;
buffer.Printf("%f %f %f %f %f %f curveto\n", buffer.Printf("%f %f %f %f %f %f curveto\n",
XLOG2DEV(wxRound(c1x)), YLOG2DEV(wxRound(c1y)), XLOG2DEV(wxRound(c1.m_x)), YLOG2DEV(wxRound(c1.m_y)),
XLOG2DEV(wxRound(c2x)), YLOG2DEV(wxRound(c2y)), XLOG2DEV(wxRound(c2.m_x)), YLOG2DEV(wxRound(c2.m_y)),
XLOG2DEV(wxRound(x3)), YLOG2DEV(wxRound(y3))); XLOG2DEV(wxRound(p3.m_x)), YLOG2DEV(wxRound(p3.m_y)));
buffer.Replace( ",", "." ); buffer.Replace( ",", "." );
PsPrint( buffer ); PsPrint( buffer );
CalcBoundingBox( (wxCoord)x1, (wxCoord)y1 ); CalcBoundingBox( (wxCoord)p0.m_x, (wxCoord)p0.m_y );
CalcBoundingBox( (wxCoord)x3, (wxCoord)y3 ); CalcBoundingBox( (wxCoord)p3.m_x, (wxCoord)p3.m_y );
node = node->GetNext(); node = node->GetNext();
} }
/* /*
At this point, (x2,y2) and (c,d) are the position of the At this point, p1 and p2 are the position of the
next-to-last and last point respectively, in the point list next-to-last and last point respectively, in the point list
*/ */
buffer.Printf( "%f %f lineto\nstroke\n", XLOG2DEV(wxRound(c)), YLOG2DEV(wxRound(d)) ); buffer.Printf( "%f %f lineto\n"
"stroke\n",
XLOG2DEV(wxRound(p2.m_x)), YLOG2DEV(wxRound(p2.m_y)) );
buffer.Replace( ",", "." ); buffer.Replace( ",", "." );
PsPrint( buffer ); PsPrint( buffer );
CalcBoundingBox((wxCoord)p2.m_x, (wxCoord)p2.m_y);
} }
#endif // wxUSE_SPLINES #endif // wxUSE_SPLINES