1 /* -*- mode: C -*- */
2 /*
3 IGraph library.
4 Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
5 334 Harvard st, Cambridge MA, 02139 USA
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA
21
22 */
23
24 #include <igraph.h>
25 #include <stdlib.h>
26 #include <math.h>
27
28 #include "layout/layout_internal.h"
29
30 #include "test_utilities.inc"
31
main()32 int main () {
33 long int i;
34 igraph_matrix_t m;
35 igraph_real_t x, y, z, r;
36
37 srand(42); /* make tests deterministic */
38
39 /* 2D */
40 igraph_matrix_init(&m, 1000, 2);
41 for (i = 0; i < igraph_matrix_nrow(&m); i++) {
42 MATRIX(m, i, 0) = rand() / (double)RAND_MAX;
43 MATRIX(m, i, 1) = rand() / (double)RAND_MAX;
44 }
45 igraph_i_layout_sphere_2d(&m, &x, &y, &r);
46
47 for (i = 0; i < igraph_matrix_nrow(&m); i++) {
48 igraph_real_t dist = sqrt((MATRIX(m, i, 0) - x) * (MATRIX(m, i, 0) - x) +
49 (MATRIX(m, i, 1) - y) * (MATRIX(m, i, 1) - y));
50 if (dist > r) {
51 printf("x: %f y: %f r: %f\n", x, y, r);
52 printf("x: %f y: %f dist: %f (%li)\n",
53 MATRIX(m, i, 0), MATRIX(m, i, 1), dist, i);
54 return 1;
55 }
56 }
57 igraph_matrix_destroy(&m);
58
59 /* 3D */
60 igraph_matrix_init(&m, 1000, 3);
61 for (i = 0; i < igraph_matrix_nrow(&m); i++) {
62 MATRIX(m, i, 0) = rand() / (double)RAND_MAX;
63 MATRIX(m, i, 1) = rand() / (double)RAND_MAX;
64 MATRIX(m, i, 2) = rand() / (double)RAND_MAX;
65 }
66 igraph_i_layout_sphere_3d(&m, &x, &y, &z, &r);
67
68 for (i = 0; i < igraph_matrix_nrow(&m); i++) {
69 igraph_real_t dist = sqrt((MATRIX(m, i, 0) - x) * (MATRIX(m, i, 0) - x) +
70 (MATRIX(m, i, 1) - y) * (MATRIX(m, i, 1) - y) +
71 (MATRIX(m, i, 2) - z) * (MATRIX(m, i, 2) - z));
72 if (dist > r) {
73 printf("x: %f y: %f z: %f r: %f\n", x, y, z, r);
74 printf("x: %f y: %f z: %f dist: %f (%li)\n",
75 MATRIX(m, i, 0), MATRIX(m, i, 1), MATRIX(m, i, 2), dist, i);
76 return 1;
77 }
78 }
79 igraph_matrix_destroy(&m);
80
81 VERIFY_FINALLY_STACK();
82
83 return 0;
84 }
85