-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: first version of a test program for the HPGL library itself. Tes…
…ts circles and arcs, plus an initial text test. TODO: test moveto/lineto, correct scaling, rectangles and line sequences.
- Loading branch information
1 parent
7acb887
commit 5b7405b
Showing
3 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ hexspiral | |
hilb | ||
hyp | ||
isogrid | ||
libtest | ||
lissajous | ||
lobe | ||
lotus | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |