From 3d40bb294395ca2548e83d8553e26c072bf1e4d9 Mon Sep 17 00:00:00 2001 From: Amy Bowersox Date: Tue, 10 Dec 2019 13:40:23 -0700 Subject: [PATCH] now disco debugging the clipping algorithm --- src/dc_screen.c | 10 ++++++++++ src/devctxt.c | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/dc_screen.c b/src/dc_screen.c index 31b3197..37d173e 100755 --- a/src/dc_screen.c +++ b/src/dc_screen.c @@ -1,4 +1,5 @@ #include +#include "log.h" #include "fbinit.h" #include "devctxt.h" #include "dc_screen.h" @@ -78,6 +79,15 @@ static BOOL screen_line(PVOID privdata, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT32 tmp; PUINT16 loc; + ASSERT(x1 >= 0); + ASSERT(x1 < Fb_Info->width); + ASSERT(y1 >= 0); + ASSERT(y1 < Fb_Info->height); + ASSERT(x2 >= 0); + ASSERT(x2 < Fb_Info->width); + ASSERT(y2 >= 0); + ASSERT(y2 < Fb_Info->height); + if (ABS(dx) < ABS(dy)) { if (y1 > y2) diff --git a/src/devctxt.c b/src/devctxt.c index 83fc8ab..c501005 100755 --- a/src/devctxt.c +++ b/src/devctxt.c @@ -1,5 +1,6 @@ #include #include +#include "log.h" #include "gfxtype.h" #include "gfxobj.h" #include "devctxt.h" @@ -23,17 +24,27 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT BYTE outcode1, outcode2, tmpb; INT32 tmp; + Log(LDEBUG, "clipping line from (%d, %d) to (%d, %d) against bounding box (%d, %d, %d, %d)", x1 >> 16, y1 >> 16, x2 >> 16, y2 >> 16, + xmin >> 16, ymin >> 16, xmax >> 16, ymax >> 16); + /* Cohen-Sutherland line-clipping algorithm (see Foley & Van Dam, pp. 145-149) */ for (;;) { outcode1 = line_clip_outcode(x1, y1, xmin, ymin, xmax, ymax); outcode2 = line_clip_outcode(x2, y2, xmin, ymin, xmax, ymax); if ((outcode1 & outcode2) != 0) + { + Log.debug("*REJECT*"); return FALSE; /* trivial rejection */ + } else if ((outcode1 == 0) && (outcode2 == 0)) + { + Log.debug("*ACCEPT*"); break; /* trivial acceptance */ + } if (outcode1 == 0) { + Log(LDEBUG, "exchange points") tmp = x1; x1 = x2; x2 = tmp; @@ -48,23 +59,28 @@ static BOOL line_clip(PINT32 output, INT32 x1, INT32 y1, INT32 x2, INT32 y2, INT { x1 += (x2 - x1) * (ymin - y1) / (y2 - y1); y1 = ymin; + Log.debug("clipped against top to point (%d, %d)", x1 >> 16, y1 >> 16); } else if (outcode1 & 0x4) { x1 += (x2 - x1) * (ymax - y1) / (y2 - y1); y1 = ymax; + Log.debug("clipped against bottom to point (%d, %d)", x1 >> 16, y1 >> 16); } else if (outcode1 & 0x2) { y1 += (y2 - y1) * (xmax - x1) / (x2 - x1); x1 = xmax; + Log.debug("clipped against right to point (%d, %d)", x1 >> 16, y1 >> 16); } else if (outcode1 & 0x1) { y1 += (y2 - y1) * (xmin - x1) / (x2 - x1); x1 = xmin; + Log.debug("clipped against left to point (%d, %d)", x1 >> 16, y1 >> 16); } } + Log(LDEBUG, "final line is from (%d, %d) to (%d, %d)", x1 >> 16, y1 >> 16, x2 >> 16, y2 >> 16); output[0] = x1; output[1] = y1; output[2] = x2;