aboutsummaryrefslogtreecommitdiff
path: root/penrose.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-04-02 10:42:42 +0100
committerSimon Tatham <anakin@pobox.com>2023-04-02 14:35:12 +0100
commit83244294f56cbf4c6ac03564489d1775054bbcfc (patch)
tree731721d49f303640449affc8cc2057fa3c9117d9 /penrose.c
parent71e1776094aa9240e9772b7fbc99dd5e2f4e1acb (diff)
downloadpuzzles-83244294f56cbf4c6ac03564489d1775054bbcfc.zip
puzzles-83244294f56cbf4c6ac03564489d1775054bbcfc.tar.gz
puzzles-83244294f56cbf4c6ac03564489d1775054bbcfc.tar.bz2
puzzles-83244294f56cbf4c6ac03564489d1775054bbcfc.tar.xz
Move other test main()s out of library source files.
Having stated the principle in the previous commit, I should apply it consistently. A source file linked into the Puzzles library of common support code should not also define a main() under ifdef. This commit only goes as far as the _library_ support modules. It would be a much bigger job to do the same for all the actual _puzzles_ that have test main()s or standalone-solver main()s. And it's not necessary, because modifying one of those source files only triggers a rebuild of _one_ puzzle, not absolutely everything. (Not to mention that it's quite likely the puzzle and the test main() will need to be modified in conjunction anyway.) As in the previous commit, this has required exposing a few internal API functions as global, and maybe editing them a bit. In particular, the one-shot internal function that divvy_rectangle() loops on until it succeeds is now exposed as divvy_rectangle_attempt(), which means the test program doesn't have to condition a failure counter into the real function. I've thrown away penrose-vector-test completely, because that didn't look like a test program with any ongoing use at all - it was surely vestigial, while James was getting the vector representation up and running in the first place.
Diffstat (limited to 'penrose.c')
-rw-r--r--penrose.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/penrose.c b/penrose.c
index 1318109..457b3fd 100644
--- a/penrose.c
+++ b/penrose.c
@@ -499,131 +499,3 @@ void penrose_calculate_size(int which, int tilesize, int w, int h,
*depth = n;
*required_radius = rradius;
}
-
-/* -------------------------------------------------------
- * Test code.
- */
-
-#ifdef TEST_PENROSE
-
-#include <stdio.h>
-#include <string.h>
-
-static int show_recursion = 0;
-static int ntiles, nfinal;
-
-static int test_cb(penrose_state *state, vector *vs, int n, int depth)
-{
- int i, xoff = 0, yoff = 0;
- double l = penrose_side_length(state->start_size, depth);
- double rball = l / 10.0;
- const char *col;
-
- ntiles++;
- if (state->max_depth == depth) {
- col = n == 4 ? "black" : "green";
- nfinal++;
- } else {
- if (!show_recursion)
- return 0;
- col = n == 4 ? "red" : "blue";
- }
- if (n != 4) yoff = state->start_size;
-
- printf("<polygon points=\"");
- for (i = 0; i < n; i++) {
- printf("%s%f,%f", (i == 0) ? "" : " ",
- v_x(vs, i) + xoff, v_y(vs, i) + yoff);
- }
- printf("\" style=\"fill: %s; fill-opacity: 0.2; stroke: %s\" />\n", col, col);
- printf("<ellipse cx=\"%f\" cy=\"%f\" rx=\"%f\" ry=\"%f\" fill=\"%s\" />",
- v_x(vs, 0) + xoff, v_y(vs, 0) + yoff, rball, rball, col);
-
- return 0;
-}
-
-static void usage_exit(void)
-{
- fprintf(stderr, "Usage: penrose-test [--recursion] P2|P3 SIZE DEPTH\n");
- exit(1);
-}
-
-int main(int argc, char *argv[])
-{
- penrose_state ps;
- int which = 0;
-
- while (--argc > 0) {
- char *p = *++argv;
- if (!strcmp(p, "-h") || !strcmp(p, "--help")) {
- usage_exit();
- } else if (!strcmp(p, "--recursion")) {
- show_recursion = 1;
- } else if (*p == '-') {
- fprintf(stderr, "Unrecognised option '%s'\n", p);
- exit(1);
- } else {
- break;
- }
- }
-
- if (argc < 3) usage_exit();
-
- if (strcmp(argv[0], "P2") == 0) which = PENROSE_P2;
- else if (strcmp(argv[0], "P3") == 0) which = PENROSE_P3;
- else usage_exit();
-
- ps.start_size = atoi(argv[1]);
- ps.max_depth = atoi(argv[2]);
- ps.new_tile = test_cb;
-
- ntiles = nfinal = 0;
-
- printf("\
-<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n\
-<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\"\n\
-\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n\
-\n\
-<svg xmlns=\"http://www.w3.org/2000/svg\"\n\
-xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n\n");
-
- printf("<g>\n");
- penrose(&ps, which, 0);
- printf("</g>\n");
-
- printf("<!-- %d tiles and %d leaf tiles total -->\n",
- ntiles, nfinal);
-
- printf("</svg>");
-
- return 0;
-}
-
-#endif
-
-#ifdef TEST_VECTORS
-
-static void dbgv(const char *msg, vector v)
-{
- printf("%s: %s\n", msg, v_debug(v));
-}
-
-int main(int argc, const char *argv[])
-{
- vector v = v_unit();
-
- dbgv("unit vector", v);
- v = v_rotate(v, 36);
- dbgv("rotated 36", v);
- v = v_scale(v, 2);
- dbgv("scaled x2", v);
- v = v_shrinkphi(v);
- dbgv("shrunk phi", v);
- v = v_rotate(v, -36);
- dbgv("rotated -36", v);
-
- return 0;
-}
-
-#endif
-/* vim: set shiftwidth=4 tabstop=8: */