line-test.c:


/* line-line.c
 * © Copyright 1999 John Halleck
 * All rights reserved.
 */
/* Version of August 27th, 1999 */

#include <stdio.h>
  /* C standard IO library */

#include "line.h"
 /* Routines we want to test */

#include "reportframe.h"
 /* Standard output form for tests */

char bitgrid[24][80]; /* a grid to do bit mapped graphics on. */
int i, j;             /* indices */

static int cleargrid () {
  for(i=0;i<24;i++) for (j=0;j<80;j++) bitgrid[i][j] = ' ';
  return NoError;
}

static int dumpgrid () {
  for (i=0;i<24;i++) {
     for (j=0;j<80;j++) {
         printf ("%c", bitgrid[i][j]);
     }
     printf ("\n");
  }
  return NoError;
}

int drawpoint (int x, int y) {
  /* printf ("drawpoint called %d %d\n", x, y); */
  if (x<0)  return 1;
  if (x>79) return 2;
  if (y<0)  return 3;
  if (y>23) return 4;
  bitgrid[y][x] = '.';
  return NoError;
}

int drawspoint (int x, int y, double value) {
  printf ("drawspoint called, %d, %d, %f\n", x, y, value);
  return NoError;
}

int main () {
error problem;

cleargrid();

inittests("line");

newtest("line");
/* On axis. */
if (!(problem= line (11, 11,  11,  1)))
if (!(problem= line (11, 11,  11, 21)))
if (!(problem= line (11, 11,   1, 11)))
if (!(problem= line (11, 11,  21, 11)))

/* On diagonal */
if (!(problem= line (11, 11,   1,  1)))
if (!(problem= line (11, 11,  21, 21)))
if (!(problem= line (11, 11,   1, 21)))
if (!(problem= line (11, 11,  21,  1)))

/* Slope test */
if (!(problem= line (25,  1,   41,  1)))
if (!(problem= line (25,  3,   41,  4)))
if (!(problem= line (25,  5,   41,  7)))
if (!(problem= line (25,  7,   41, 10)))
if (!(problem= line (25,  9,   41, 13)))
if (!(problem= line (25, 11,   41, 16)))
if (!(problem= line (25, 13,   41, 19)))
if (!(problem= line (25, 15,   41, 22)))
/* shifted slope test */
if (!(problem= line (50,  1,   66,  9)))
if (!(problem= line (50,  3,   66, 12)))
if (!(problem= line (50,  5,   66, 15)))
if (!(problem= line (50,  7,   66, 18)))
if (!(problem= line (50,  9,   66, 21)))
printf ("bitmat generated...\n");

if (problem) {
   goterrorstat ("Failed?", problem);
}
endtest();
dumpgrid();


  newtest ("sline");
/* OK, now test anti-aliased line */
if (!(problem = sline (1, 1,  10,  1)))
if (!(problem = sline (1, 1,  10, 10)))
if (!(problem = sline (1, 1,  10,  5)))
if (!(problem = sline (1, 1,  10, 2)))
printf ("anti-aliased line tests done.\n");
  endtest();

  finalizetests();
  return progerrors;
}

Go to ...


This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/line-test.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000