check-layout.c 4.59 KB
Newer Older
1
2
/* tarot implements the rules of the tarot game
 * Copyright (C) 2018, 2019  Vivien Kraus
Vivien Kraus's avatar
Vivien Kraus committed
3
 *
4
5
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, version 3 of the License.
Vivien Kraus's avatar
Vivien Kraus committed
7
8
9
10
11
12
13
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Vivien Kraus's avatar
Vivien Kraus committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 */

#include <config.h>
#include <tarot.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "xalloc.h"
#include <assert.h>

static const size_t skipped[] = {
  0, 1, 3, 2
};

static void
print_svg (const char *description, double view_w, double view_h,
           double card_w, double card_h, size_t n_my_cards, size_t n_center)
{
  TarotPosition *positions = NULL;
  size_t n_positions =
    tarot_layout_position (view_w, view_h, card_w, card_h, n_my_cards,
                           sizeof (skipped) / sizeof (skipped[0]), skipped,
                           n_center, 0, NULL);
  size_t i;
  size_t n_positions_2;
  positions = xmalloc (n_positions * sizeof (TarotPosition));
  n_positions_2 =
    tarot_layout_position (view_w, view_h, card_w, card_h, n_my_cards,
                           sizeof (skipped) / sizeof (skipped[0]), skipped,
                           n_center, n_positions, positions);
  if (n_positions_2 != n_positions)
    {
      fprintf (stderr, "%s:%d: %lu != %lu\n", __FILE__, __LINE__,
               n_positions_2, n_positions);
      assert (0);
    }
  printf
    ("<test description=\"%s (everything)\" width=\"%f\" height=\"%f\" card-width=\"%f\" card-height=\"%f\" n-cards=\"%lu\">",
     description, view_w, view_h, card_w, card_h, n_positions);
  for (i = 0; i < n_positions; i++)
    {
      printf
        ("<card index=\"%lu\" x=\"%f\" y=\"%f\" z=\"%f\" angle=\"%f\" scale=\"%f\" />",
         i, positions[i].x, positions[i].y, positions[i].z,
         positions[i].angle, positions[i].scale);
    }
  printf ("</test>");
  free (positions);
  tarot_layout_hand_alloc (view_w, view_h, card_w, card_h, n_my_cards,
                           &n_positions, &positions);
  printf
    ("<test description=\"%s (only the hand)\" width=\"%f\" height=\"%f\" card-width=\"%f\" card-height=\"%f\" n-cards=\"%lu\">",
     description, view_w, view_h, card_w, card_h, n_positions);
  for (i = 0; i < n_positions; i++)
    {
      printf
        ("<card index=\"%lu\" x=\"%f\" y=\"%f\" z=\"%f\" angle=\"%f\" scale=\"%f\" />",
         i, positions[i].x, positions[i].y, positions[i].z,
         positions[i].angle, positions[i].scale);
    }
  printf ("</test>");
  free (positions);
  tarot_layout_trick_alloc (view_w, view_h, card_w, card_h, 5, &n_positions,
                            &positions);
  printf
    ("<test description=\"%s (only the trick)\" width=\"%f\" height=\"%f\" card-width=\"%f\" card-height=\"%f\" n-cards=\"%lu\">",
     description, view_w, view_h, card_w, card_h, n_positions);
  for (i = 0; i < n_positions; i++)
    {
      printf
        ("<card index=\"%lu\" x=\"%f\" y=\"%f\" z=\"%f\" angle=\"%f\" scale=\"%f\" />",
         i, positions[i].x, positions[i].y, positions[i].z,
         positions[i].angle, positions[i].scale);
    }
  printf ("</test>");
  free (positions);
  tarot_layout_center_alloc (view_w, view_h, card_w, card_h, n_center,
                             &n_positions, &positions);
  printf
    ("<test description=\"%s (only the center)\" width=\"%f\" height=\"%f\" card-width=\"%f\" card-height=\"%f\" n-cards=\"%lu\">",
     description, view_w, view_h, card_w, card_h, n_positions);
  for (i = 0; i < n_positions; i++)
    {
      printf
        ("<card index=\"%lu\" x=\"%f\" y=\"%f\" z=\"%f\" angle=\"%f\" scale=\"%f\" />",
         i, positions[i].x, positions[i].y, positions[i].z,
         positions[i].angle, positions[i].scale);
    }
  printf ("</test>");
  free (positions);
}

int
main ()
{
  printf ("<?xml version=\"1.0\"?>\n");
  printf ("<?xml-stylesheet type=\"text/xsl\" href=\"check-layout.xsl\"?>\n");
  printf ("<example xmlns=\"http://planete-kraus.eu/tarot\">");
  print_svg ("normal", 640, 480, 48, 64, 10, 0);
  print_svg ("with a center", 640, 480, 48, 64, 10, 6);
  print_svg ("portrait mode", 480, 640, 48, 64, 10, 0);
  print_svg ("portrait, a center", 480, 640, 48, 64, 10, 6);
  print_svg ("very thin portrait", 480, 2400, 64, 32, 10, 6);
  printf ("</example>");
  return 0;
}