Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
20
39-03.md
20
39-03.md
|
|
@ -11,7 +11,7 @@ pixels advanced per scan line is the same as the ratio of the X delta of
|
|||
the edge to the Y delta. Listing 39.2 is more complex than the original
|
||||
floating point implementation, but not painfully so. In return for that
|
||||
complexity, Listing 39.2 is more than 80 times faster at scanning
|
||||
edges—and, as just mentioned, it’s actually more accurate than the
|
||||
edges—and, as just mentioned, it's actually more accurate than the
|
||||
floating point code.
|
||||
|
||||
Ya gotta love that integer arithmetic.
|
||||
|
|
@ -19,14 +19,14 @@ Ya gotta love that integer arithmetic.
|
|||
**LISTING 39.2 L39-2.C**
|
||||
|
||||
/* Scan converts an edge from (X1,Y1) to (X2,Y2), not including the
|
||||
point at (X2,Y2). If SkipFirst == 1, the point at (X1,Y1) isn’t
|
||||
point at (X2,Y2). If SkipFirst == 1, the point at (X1,Y1) isn't
|
||||
drawn; if SkipFirst == 0, it is. For each scan line, the pixel
|
||||
closest to the scanned edge without being to the left of the
|
||||
scanned edge is chosen. Uses an all-integer approach for speed and
|
||||
precision. */
|
||||
|
||||
#include <math.h>
|
||||
#include “polygon.h”
|
||||
#include "polygon.h"
|
||||
|
||||
void ScanEdge(int X1, int Y1, int X2, int Y2, int SetXStart,
|
||||
int SkipFirst, struct HLine **EdgePointPtr)
|
||||
|
|
@ -78,7 +78,7 @@ Ya gotta love that integer arithmetic.
|
|||
else
|
||||
ErrorTerm = -Height + 1; /* going right->left */
|
||||
if (SkipFirst) { /* skip the first point if so indicated */
|
||||
/* Determine whether it’s time for the X coord to advance */
|
||||
/* Determine whether it's time for the X coord to advance */
|
||||
if ((ErrorTerm += Width) > 0) {
|
||||
X1 += AdvanceAmt; /* move 1 pixel to the left or right */
|
||||
ErrorTerm -= Height; /* advance ErrorTerm to next point */
|
||||
|
|
@ -91,7 +91,7 @@ Ya gotta love that integer arithmetic.
|
|||
WorkingEdgePointPtr->XStart = X1;
|
||||
else
|
||||
WorkingEdgePointPtr->XEnd = X1;
|
||||
/* Determine whether it’s time for the X coord to advance */
|
||||
/* Determine whether it's time for the X coord to advance */
|
||||
if ((ErrorTerm += Width) > 0) {
|
||||
X1 += AdvanceAmt; /* move 1 pixel to the left or right */
|
||||
ErrorTerm -= Height; /* advance ErrorTerm to correspond */
|
||||
|
|
@ -109,7 +109,7 @@ Ya gotta love that integer arithmetic.
|
|||
ErrorTerm = -Height + 1; /* going right->left */
|
||||
if (SkipFirst) { /* skip the first point if so indicated */
|
||||
X1 += XMajorAdvanceAmt; /* move X minimum distance */
|
||||
/* Determine whether it’s time for X to advance one extra */
|
||||
/* Determine whether it's time for X to advance one extra */
|
||||
if ((ErrorTerm += ErrorTermAdvance) > 0) {
|
||||
X1 += AdvanceAmt; /* move X one more */
|
||||
ErrorTerm -= Height; /* advance ErrorTerm to correspond */
|
||||
|
|
@ -123,7 +123,7 @@ Ya gotta love that integer arithmetic.
|
|||
else
|
||||
WorkingEdgePointPtr->XEnd = X1;
|
||||
X1 += XMajorAdvanceAmt; /* move X minimum distance */
|
||||
/* Determine whether it’s time for X to advance one extra */
|
||||
/* Determine whether it's time for X to advance one extra */
|
||||
if ((ErrorTerm += ErrorTermAdvance) > 0) {
|
||||
X1 += AdvanceAmt; /* move X one more */
|
||||
ErrorTerm -= Height; /* advance ErrorTerm to correspond */
|
||||
|
|
@ -131,21 +131,21 @@ Ya gotta love that integer arithmetic.
|
|||
}
|
||||
}
|
||||
|
||||
*EdgePointPtr = WorkingEdgePointPtr; /* advance caller’s ptr */
|
||||
*EdgePointPtr = WorkingEdgePointPtr; /* advance caller's ptr */
|
||||
}
|
||||
|
||||
### The Finishing Touch: Assembly Language {#Heading6}
|
||||
|
||||
The C implementation in Listing 39.2 is now nearly 20 times as fast as
|
||||
the original, which is good enough for most purposes. Still, it requires
|
||||
that one of the large data models be used (for **memset** ), and it’s
|
||||
that one of the large data models be used (for **memset** ), and it's
|
||||
certainly not the fastest possible code. The obvious next step is
|
||||
assembly language.
|
||||
|
||||
Listing 39.3 is an assembly language version of
|
||||
**DrawHorizontalLineList** . In actual use, it proved to be about 36
|
||||
percent faster than Listing 39.1; better than a poke in the eye with a
|
||||
sharp stick, but just barely. There’s more to these timing results than
|
||||
sharp stick, but just barely. There's more to these timing results than
|
||||
meets that eye, though. Display memory generally responds much more
|
||||
slowly than system memory, especially in 386 and 486 systems. That means
|
||||
that much of the time taken by Listing 39.3 is actually spent waiting
|
||||
|
|
|
|||
Loading…
Reference in a new issue