Normal quotes

This commit is contained in:
James Gregory 2013-12-30 18:34:31 +11:00
commit 18011c595a
352 changed files with 6040 additions and 6040 deletions

View file

@ -8,21 +8,21 @@ How, then, do you fit polygons together? *Very* carefully. First, the
line-tracing algorithm must be adjusted so that it selects only those
pixels that are truly inside the polygon. This basically requires
shifting a standard line-drawing algorithm horizontally by one
half-pixel toward the polygon’s interior. That leaves the issue of how
half-pixel toward the polygon's interior. That leaves the issue of how
to handle points that are exactly on the boundary, and points that lie
at vertices, so that those points are drawn once and only once. To deal
with that, we’re going to adopt the following rules:
with that, we're going to adopt the following rules:
- Points located exactly on nonhorizontal edges are drawn only if the
interior of the polygon is directly to the right (left edges are
drawn, right edges aren’t).
drawn, right edges aren't).
![](images/38-03.jpg)\
**Figure 38.3**  *The adjacent polygons problem.*
- Points located exactly on horizontal edges are drawn only if the
interior of the polygon is directly below them (horizontal top edges
are drawn, horizontal bottom edges aren’t).
are drawn, horizontal bottom edges aren't).
- A vertex is drawn only if all lines ending at that point meet the
above conditions (no right or bottom edges end at that point).
@ -38,10 +38,10 @@ once—just what we need in order to be able to fit filled polygons
together seamlessly.
------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
![](images/i.jpg) *This sort of non-overlapping polygon filling isn’t ideal for all purposes. Polygons are skewed toward the top and left edges, which not only introduces drawing error relative to the ideal polygon but also means that a filled polygon won’t match the same polygon drawn unfilled. Narrow wedges and one-pixel-wide polygons will show up spottily. All in all, the choice of polygon-filling approach depends entirely on the ways in which the filled polygons must be used.*
![](images/i.jpg) *This sort of non-overlapping polygon filling isn't ideal for all purposes. Polygons are skewed toward the top and left edges, which not only introduces drawing error relative to the ideal polygon but also means that a filled polygon won't match the same polygon drawn unfilled. Narrow wedges and one-pixel-wide polygons will show up spottily. All in all, the choice of polygon-filling approach depends entirely on the ways in which the filled polygons must be used.*
------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
For our purposes, nonoverlapping polygons are the way to go, so let’s
For our purposes, nonoverlapping polygons are the way to go, so let's
have at them.
### Filling Non-Overlapping Convex Polygons {#Heading6}
@ -53,19 +53,19 @@ scans it into a list of lines to fill, then passes that list to the
function **DrawHorizontalLineList** in Listing 38.2. Listing 38.3 is a
sample program that calls **FillConvexPolygon** to draw polygons of
various sorts, and Listing 38.4 is a header file included by the other
listings. Here are the listings; we’ll pick up discussion on the other
listings. Here are the listings; we'll pick up discussion on the other
side.
**LISTING 38.1 L38-1.C**
/* Color-fills a convex polygon. All vertices are offset by (XOffset,
YOffset). “Convex” means that every horizontal line drawn through
YOffset). "Convex" means that every horizontal line drawn through
the polygon at any point would cross exactly two active edges
(neither horizontal lines nor zero-length edges count as active
edges; both are acceptable anywhere in the polygon), and that the
right & left edges never cross. (It’s OK for them to touch, though,
right & left edges never cross. (It's OK for them to touch, though,
so long as the right edge never crosses over to the left of the
left edge.) Nonconvex polygons won’t be drawn properly. Returns 1
left edge.) Nonconvex polygons won't be drawn properly. Returns 1
for success, 0 if memory allocation failed. */
#include <stdio.h>
@ -75,7 +75,7 @@ side.
#else /* MSC */
#include <malloc.h>
#endif
#include “polygon.h”
#include "polygon.h"
/* Advances the index by one vertex forward through the vertex list,
wrapping at the end of the list */
@ -171,20 +171,20 @@ side.
}
/* Set the # of scan lines in the polygon, skipping the bottom edge
and also skipping the top vertex if the top isn’t flat because
and also skipping the top vertex if the top isn't flat because
in that case the top vertex has a right edge component, and set
the top scan line to draw, which is likewise the second line of
the polygon unless the top is flat */
if ((WorkingHLineList.Length =
MaxPoint_Y - MinPoint_Y - 1 + TopIsFlat) <= 0)
return(1); /* there’s nothing to draw, so we’re done */
return(1); /* there's nothing to draw, so we're done */
WorkingHLineList.YStart = YOffset + MinPoint_Y + 1 - TopIsFlat;
/* Get memory in which to store the line list we generate */
if ((WorkingHLineList.HLinePtr =
(struct HLine *) (malloc(sizeof(struct HLine) *
WorkingHLineList.Length))) == NULL)
return(0); /* couldn’t get memory for the line list */
return(0); /* couldn't get memory for the line list */
/* Scan the left edge and store the boundary points in the list */
/* Initial pointer for storing scan converted left-edge coords */
@ -192,8 +192,8 @@ side.
/* Start from the top of the left edge */
PreviousIndex = CurrentIndex = MinIndexL;
/* Skip the first point of the first line unless the top is flat;
if the top isn’t flat, the top vertex is exactly on a right
edge and isn’t drawn */
if the top isn't flat, the top vertex is exactly on a right
edge and isn't drawn */
SkipFirst = TopIsFlat ? 0 : 1;
/* Scan convert each line in the left edge from top to bottom */
do {
@ -226,7 +226,7 @@ side.
/* Draw the line list representing the scan converted polygon */
DrawHorizontalLineList(&WorkingHLineList, Color);
/* Release the line list’s memory and we’re successfully done */
/* Release the line list's memory and we're successfully done */
free(WorkingHLineList.HLinePtr);
return(1);
}
@ -235,7 +235,7 @@ side.
point at (X2,Y2). This avoids overlapping the end of one line with
the start of the next, and causes the bottom scan line of the
polygon not to be drawn. If SkipFirst != 0, the point at (X1,Y1)
isn’t drawn. For each scan line, the pixel closest to the scanned
isn't drawn. For each scan line, the pixel closest to the scanned
line without being to the left of the scanned line is chosen. */
static void ScanEdge(int X1, int Y1, int X2, int Y2, int SetXStart,
int SkipFirst, struct HLine **EdgePointPtr)
@ -263,18 +263,18 @@ side.
WorkingEdgePointPtr->XEnd =
X1 + (int)(ceil((Y-Y1) * InverseSlope));
}
*EdgePointPtr = WorkingEdgePointPtr; /* advance caller’s ptr */
*EdgePointPtr = WorkingEdgePointPtr; /* advance caller's ptr */
}
**LISTING 38.2 L38-2.C**
/* Draws all pixels in the list of horizontal lines passed in, in
mode 13h, the VGA’s 320x200 256-color mode. Uses a slow pixel-by-
mode 13h, the VGA's 320x200 256-color mode. Uses a slow pixel-by-
pixel approach, which does have the virtue of being easily ported
to any environment. */
#include <dos.h>
#include “polygon.h”
#include "polygon.h"
#define SCREEN_WIDTH 320
#define SCREEN_SEGMENT 0xA000