Skip to content

Commit

Permalink
WIP: first version of a test program for the HPGL library itself. Tes…
Browse files Browse the repository at this point in the history
…ts circles and arcs, plus an initial text test. TODO: test moveto/lineto, correct scaling, rectangles and line sequences.
  • Loading branch information
anachrocomputer committed Aug 10, 2020
1 parent 7acb887 commit 5b7405b
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ hexspiral
hilb
hyp
isogrid
libtest
lissajous
lobe
lotus
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ HPGL=flake.hpgl op.hpgl dala1.hpgl hconic2.hpgl tree.hpgl dome.hpgl \
curve_stitching.hpgl cs_rosette.hpgl allover13.hpgl allover12.hpgl \
qrplot.hpgl lotus.hpgl celticstep.hpgl op_moire.hpgl sutpent.hpgl \
morphpoly.hpgl pin_circle.hpgl isogrid.hpgl circle_lines.hpgl \
star_grid.hpgl ternary_arcs.hpgl hexspiral.hpgl poly_oval.hpgl
star_grid.hpgl ternary_arcs.hpgl hexspiral.hpgl poly_oval.hpgl \
libtest.hpgl

PNG=$(HPGL:.hpgl=.png)

Expand Down Expand Up @@ -149,6 +150,15 @@ morphpoly: morphpoly.o hpgllib.o
morphpoly.o: morphpoly.c hpgllib.h
$(CC) $(CFLAGS) -o $@ morphpoly.c

libtest.hpgl: libtest Makefile
./libtest $(TITLE) $(BOLDPEN) -o $@

libtest: libtest.o hpgllib.o
$(LD) -o $@ libtest.o hpgllib.o -lm

libtest.o: libtest.c hpgllib.h
$(CC) $(CFLAGS) -o $@ libtest.c

lissajous.hpgl: lissajous Makefile
./lissajous $(TITLE) $(BOLDPEN) -o $@

Expand Down
130 changes: 130 additions & 0 deletions libtest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* libtest --- test the HPGL library 2020-08-10 */
/* Copyright (c) 2020 John Honniball, Froods Software Development */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include "hpgllib.h"

struct Point {
double x;
double y;
};

void lineTest(const double xc, const double yc, const double wd, const double ht);
void circleTest(const double xc, const double yc, const double wd, const double ht);
void arcTest(const double xc, const double yc, const double wd, const double ht);
void textTest(const double xc, const double yc, const double wd, const double ht);

int main(int argc, char * const argv[])
{
int opt;
double xc, yc;
double h4, w4;
double maxx, maxy;

while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 's':
case 'n':
case 'o':
case 'p':
case 't':
case 'v':
plotopt(opt, optarg);
break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n", argv[0]);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
exit(EXIT_FAILURE);
}
}

plotbegin(1);

getplotsize(&maxx, &maxy);

xc = maxx / 2.0;
yc = maxy / 2.0;

w4 = maxx / 4.0;
h4 = maxy / 4.0;

moveto(0.0, yc);
lineto(maxx, yc);

moveto(xc, 0.0);
lineto(xc, maxy);

lineTest(w4, yc + h4, w4, h4);
circleTest(w4, h4, w4, h4);
arcTest(xc + w4, yc + h4, w4, h4);
textTest(xc + w4, h4, w4, h4);

plotend();

return (0);
}


void lineTest(const double xc, const double yc, const double wd, const double ht)
{
const double len = wd / 16.0;

moveto(xc - len, yc);
lineto(xc + len, yc);

moveto(xc, yc - len);
lineto(xc, yc + len);
}


void circleTest(const double xc, const double yc, const double wd, const double ht)
{
const double major = wd / 2.0;
const double minor = ht / 2.0;

circle(xc, yc, minor);
ellipse(xc, yc, major, minor, 0.0);
ellipse(xc, yc, major, minor, (M_PI / 4.0));
ellipse(xc, yc, major, minor, (M_PI / 2.0));
circle(xc, yc, major);
}


void arcTest(const double xc, const double yc, const double wd, const double ht)
{
double radius = wd / 2.0;
const double delta = M_PI / 4.0;
double angle;
int i;

moveto(xc - (wd / 2.0), yc);
lineto(xc, yc);
lineto(xc, yc + (wd / 2.0));

for (i = 0; i < 7; i++) {
radius = (wd / 16.0) * (i + 1);
angle = 45.0 * (i + 1);

moveto(xc - radius, yc);
arc(xc, yc, angle);
}
}


void textTest(const double xc, const double yc, const double wd, const double ht)
{
const double len = wd / 16.0;

moveto(xc - len, yc);
lineto(xc + len, yc);

moveto(xc, yc - len);
lineto(xc, yc + len);

hlabel(xc, yc, 10.0, "ABCDEF");
// hlabel(xc, yc + (len * 2.0), 10.0, "\x99\x9F\xEC");
}

0 comments on commit 5b7405b

Please sign in to comment.