annotate src/coord.c @ 1381:9a585df24e52

Consider the width and height attribute for the rect elements. The inkscape will change the width and height directly without using transform when we resize the rectangle.
author wycc
date Wed, 23 Mar 2011 23:02:36 +0800
parents 586e50f82c1f
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
2 // vim: sw=4:ts=8:sts=4
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
3 /*! \brief Implement coordination tranform mechanism.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
4 * \file
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
5 * This file implements coordination transforming for containers.
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
6 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include <stdio.h>
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include <string.h>
31
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
9 #include <math.h>
186
530bb7728546 Move header files to $(top_srcdir)/include/ and prefixed with 'mb_'.
Thinker K.F. Li <thinker@branda.to>
parents: 185
diff changeset
10 #include "mb_types.h"
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
13 #define ASSERT(x)
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
14
3
164162781a7a Test cairo with Xlib surface
Thinker K.F. Li <thinker@branda.to>
parents: 2
diff changeset
15 /* To keep possibility of changing type of aix */
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
16 #define MUL(a, b) ((a) * (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
17 #define ADD(a, b) ((a) + (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
18 #define DIV(a, b) ((a) / (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
19 #define SUB(a, b) ((a) - (b))
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
20
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
21 static void mul_matrix(co_aix *m1, co_aix *m2, co_aix *dst) {
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
22 dst[0] = ADD(MUL(m1[0], m2[0]), MUL(m1[1], m2[3]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
23 dst[1] = ADD(MUL(m1[0], m2[1]), MUL(m1[1], m2[4]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
24 dst[2] = ADD(ADD(MUL(m1[0], m2[2]), MUL(m1[1], m2[5])), m1[2]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
25 dst[3] = ADD(MUL(m1[3], m2[0]), MUL(m1[4], m2[3]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
26 dst[4] = ADD(MUL(m1[3], m2[1]), MUL(m1[4], m2[4]));
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
27 dst[5] = ADD(ADD(MUL(m1[3], m2[2]), MUL(m1[4], m2[5])), m1[5]);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
30 void matrix_mul(co_aix *m1, co_aix *m2, co_aix *dst) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
31 co_aix *_dst = dst;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
32 co_aix fake_dst[6];
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
33
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
34 if(m1 == dst || m2 == dst)
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
35 _dst = fake_dst;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
36
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
37 mul_matrix(m1, m2, _dst);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
38
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
39 if(m1 == dst || m2 == dst) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
40 dst[0] = fake_dst[0];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
41 dst[1] = fake_dst[1];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
42 dst[2] = fake_dst[2];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
43 dst[3] = fake_dst[3];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
44 dst[4] = fake_dst[4];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
45 dst[5] = fake_dst[5];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
46 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
47 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
48
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
49 void matrix_trans_pos(co_aix *matrix, co_aix *x, co_aix *y) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
50 co_aix nx, ny;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
51
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
52 nx = ADD(ADD(MUL(matrix[0], *x),
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
53 MUL(matrix[1], *y)),
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
54 matrix[2]);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
55 ny = ADD(ADD(MUL(matrix[3], *x),
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
56 MUL(matrix[4], *y)),
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
57 matrix[5]);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
58 *x = nx;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
59 *y = ny;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
60 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
61
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
62 /*! \brief Compute aggregated transform matrix.
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
63 *
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
64 * Base on parent's aggregated matrix if it is existed, or use transform
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
65 * matrix as aggregated matrix.
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
66 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67 static void compute_transform_function(coord_t *visit) {
533
b51ae415f459 Use coord_is_root() to indicate the root coord
Thinker K.F. Li <thinker@branda.to>
parents: 314
diff changeset
68 if(!coord_is_root(visit))
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 mul_matrix(visit->parent->aggr_matrix,
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 visit->matrix, visit->aggr_matrix);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 else
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
72 memcpy(visit->aggr_matrix, visit->matrix, sizeof(visit->matrix));
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74
16
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
75 void compute_aggr_of_coord(coord_t *coord) {
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
76 compute_transform_function(coord);
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
77 }
e17e12b112c4 A simple animation using rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 15
diff changeset
78
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
79 /*! \brief Compute aggregated transform matrix for cached coord.
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
80 *
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
81 * \sa \ref img_cache
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
82 */
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
83 static void compute_transform_function_cached(coord_t *visit) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
84 co_aix *p_matrix;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
85 co_aix cache_p_matrix[6];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
86 co_aix cache_scale_x, cache_scale_y;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
87
533
b51ae415f459 Use coord_is_root() to indicate the root coord
Thinker K.F. Li <thinker@branda.to>
parents: 314
diff changeset
88 if(!coord_is_root(visit)) {
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
89 p_matrix = coord_get_aggr_matrix(visit->parent);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
90 cache_scale_x =
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
91 sqrtf(p_matrix[0] * p_matrix[0] + p_matrix[3] * p_matrix[3]);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
92 cache_scale_y =
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
93 sqrtf(p_matrix[1] * p_matrix[1] + p_matrix[4] * p_matrix[4]);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
94 cache_p_matrix[0] = cache_scale_x;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
95 cache_p_matrix[1] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
96 cache_p_matrix[2] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
97 cache_p_matrix[3] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
98 cache_p_matrix[4] = cache_scale_y;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
99 cache_p_matrix[5] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
100 mul_matrix(cache_p_matrix, visit->matrix, visit->aggr_matrix);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
101 } else {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
102 memcpy(visit->aggr_matrix, visit->matrix, sizeof(visit->matrix));
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
103 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
104 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
105
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
106 void compute_aggr_of_cached_coord(coord_t *coord) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
107 compute_transform_function_cached(coord);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
108 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
109
535
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
110 void
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
111 compute_aggr(coord_t *coord) {
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
112 if(coord->flags & COF_OWN_CANVAS)
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
113 compute_transform_function_cached(coord);
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
114 else
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
115 compute_transform_function(coord);
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
116 }
a545f126d2bf pcached_area replaces owner_mems_area
Thinker K.F. Li <thinker@branda.to>
parents: 533
diff changeset
117
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
118 void compute_reverse(co_aix *orig, co_aix *reverse) {
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
119 co_aix working[6];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
120 co_aix factor;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
121
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
122 #define VEC_MAC(src, factor, dst) \
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
123 do { \
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
124 (dst)[0] += (src)[0] * (factor); \
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
125 (dst)[1] += (src)[1] * (factor); \
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
126 (dst)[2] += (src)[2] * (factor); \
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
127 } while(0)
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
128
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
129 reverse[0] = 1;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
130 reverse[1] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
131 reverse[2] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
132 reverse[3] = 0;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
133 reverse[4] = 1;
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
134 reverse[5] = 0;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
135
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
136 memcpy(working, orig, sizeof(co_aix) * 6);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
137
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
138 factor = -working[3] / working[0];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
139 VEC_MAC(working, factor, working + 3);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
140 VEC_MAC(reverse, factor, reverse + 3);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
141
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
142 factor = -working[1] / working[4];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
143 VEC_MAC(working + 3, factor, working);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
144 VEC_MAC(reverse + 3, factor, reverse);
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
145
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
146 reverse[2] = -working[2];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
147 reverse[5] = -working[5];
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
148
779
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
149 factor = 1 / working[0];
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
150 reverse[0] *= factor;
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
151 reverse[1] *= factor;
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
152 reverse[2] *= factor;
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
153 factor = 1 / working[4];
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
154 reverse[3] *= factor;
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
155 reverse[4] *= factor;
8e9481bf1cc0 Avoid float divide to improve performance
Thinker K.F. Li <thinker@codemud.net>
parents: 535
diff changeset
156 reverse[5] *= factor;
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
157 }
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
158
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
159 /*! \brief Update aggregate matrices of elements under a sub-tree.
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
160 *
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
161 * A subtree is specified by the root of it. All elements in the subtree
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
162 * are effected by that changes of matrix of the subtree root.
314
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
163 *
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
164 * \todo Remove update_aggr_matrix() since it is out of date and
6c350fc92ae3 Cache rednering result is now workable.
Thinker K.F. Li <thinker@branda.to>
parents: 224
diff changeset
165 * no one use it.
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 void update_aggr_matrix(coord_t *start) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 coord_t *visit, *child, *next;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 compute_transform_function(start);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 visit = start;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 while(visit) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
174 child = STAILQ_HEAD(visit->children);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175 while(child) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 compute_transform_function(child);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
177 child = STAILQ_NEXT(coord_t, sibling, child);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
178 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
180 if(STAILQ_HEAD(visit->children))
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
181 visit = STAILQ_HEAD(visit->children);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
182 else if(STAILQ_NEXT(coord_t, sibling, visit))
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
183 visit = STAILQ_NEXT(coord_t, sibling, visit);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184 else {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 next = NULL;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 while(visit->parent && visit->parent != start) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
187 visit = visit->parent;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
188 if(STAILQ_NEXT(coord_t, sibling, visit)) {
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
189 next = STAILQ_NEXT(coord_t, sibling, visit);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
190 break;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 visit = next;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
198 /*! \brief Initialize a coord object.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
199 *
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
200 * The object is cleared and matrix was initialized to ID.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
201 * The object is be a children of specified parent.
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
202 */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
203 void coord_init(coord_t *co, coord_t *parent) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
204 memset(co, 0, sizeof(coord_t));
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
205 if(parent) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
206 /* insert at tail of children list. */
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
207 co->parent = parent;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
208 STAILQ_INS_TAIL(parent->children, coord_t, sibling, co);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
209 }
224
29e1b2bffe4c X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents: 196
diff changeset
210 mb_obj_init(co, MBO_COORD);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
211 co->matrix[0] = 1;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
212 co->matrix[4] = 1;
17
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
213 co->aggr_matrix[0] = 1;
41f0907b27ac Unittest for rdman_redraw_changed().
Thinker K.F. Li <thinker@branda.to>
parents: 16
diff changeset
214 co->aggr_matrix[4] = 1;
15
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
215 co->cur_area = &co->areas[0];
c2ce186a5c37 X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 13
diff changeset
216 co->last_area = &co->areas[1];
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
217 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
218
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
219 void coord_trans_pos(coord_t *co, co_aix *x, co_aix *y) {
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
220 co_aix nx, ny;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
221
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
222 nx = ADD(ADD(MUL(co->aggr_matrix[0], *x),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
223 MUL(co->aggr_matrix[1], *y)),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
224 co->aggr_matrix[2]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
225 ny = ADD(ADD(MUL(co->aggr_matrix[3], *x),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
226 MUL(co->aggr_matrix[4], *y)),
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
227 co->aggr_matrix[5]);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
228 *x = nx;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
229 *y = ny;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
230 }
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
231
31
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
232 co_aix coord_trans_size(coord_t *co, co_aix sz) {
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
233 co_aix x, y;
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
234
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
235 x = MUL(co->aggr_matrix[0], sz);
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
236 y = MUL(co->aggr_matrix[3], sz);
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
237
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
238 return sqrt(x * x + y * y);
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
239 }
da770188a44d resize font size for changige of coord.
Thinker K.F. Li <thinker@branda.to>
parents: 17
diff changeset
240
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
241 /*!
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
242 * \note Coords, marked with COF_SKIP_TRIVAL (for temporary), and
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
243 * descendants of them will not be trivaled and the flag with be removed
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
244 * after skipping them.
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
245 */
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
246 coord_t *preorder_coord_subtree(coord_t *root, coord_t *last) {
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
247 coord_t *next = NULL;
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
248
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
249 ASSERT(last != NULL);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
250
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
251 if((!(last->flags & COF_SKIP_TRIVAL)) &&
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
252 STAILQ_HEAD(last->children)) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
253 next = STAILQ_HEAD(last->children);
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
254 if(!(next->flags & COF_SKIP_TRIVAL))
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
255 return next;
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
256 } else {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
257 next = last;
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
258 }
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
259
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
260 do {
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
261 next->flags &= ~COF_SKIP_TRIVAL;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
262 while(next != root && STAILQ_NEXT(coord_t, sibling, next) == NULL)
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
263 next = next->parent;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
264 if(next == root)
151
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
265 return NULL;
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
266 next = STAILQ_NEXT(coord_t, sibling, next);
d11aa8fc06c7 Fix bug of tanks do not show at right places.
Thinker K.F. Li <thinker@branda.to>
parents: 140
diff changeset
267 } while(next->flags & COF_SKIP_TRIVAL);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
268
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
269 return next;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
270 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
271
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
272 coord_t *postorder_coord_subtree(coord_t *root, coord_t *last) {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
273 coord_t *next;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
274
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
275 if(root == last)
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
276 return NULL;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
277
138
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
278 if(last == NULL) {
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
279 /* Go most left leaf. */
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
280 next = root;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
281 while(STAILQ_HEAD(next->children))
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
282 next = STAILQ_HEAD(next->children);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
283 return next;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
284 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
285
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
286 next = last;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
287 if(STAILQ_NEXT(coord_t, sibling, next) == NULL) /* most right */
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
288 return next->parent;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
289
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
290 /* Go most left leaf of right sibling sub-tree. */
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
291 next = STAILQ_NEXT(coord_t, sibling, next);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
292 while(STAILQ_HEAD(next->children))
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
293 next = STAILQ_HEAD(next->children);
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
294
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
295 return next;
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
296 }
9f4fc9ecfd1f Make shapes and coords drawed in post-order of tree.
Thinker K.F. Li <thinker@branda.to>
parents: 31
diff changeset
297
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
298 #ifdef UNITTEST
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
299
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
300 #include <CUnit/Basic.h>
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
301
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
302 void test_update_aggr_matrix(void) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
303 coord_t elms[6];
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
304 co_aix x, y;
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
305
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
306 coord_init(elms, NULL);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
307 coord_init(elms + 1, elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
308 coord_init(elms + 2, elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
309 coord_init(elms + 3, elms + 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
310 coord_init(elms + 4, elms + 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
311 coord_init(elms + 5, elms + 2);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
312
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
313 /* | 2 -1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
314 * | 0 1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
315 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
316 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
317 elms[0].matrix[0] = 2;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
318 elms[0].matrix[1] = -1;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
319
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
320 /* | 1 3 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
321 * | 5 1 0 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
322 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
323 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
324 elms[1].matrix[1] = 3;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
325 elms[1].matrix[3] = 5;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
326
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
327 update_aggr_matrix(elms);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
328
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
329 /* | -3 5 0 |
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
330 * | 5 1 0 |
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
331 * | 0 0 1 |
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
332 */
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
333 CU_ASSERT(elms[3].aggr_matrix[0] == -3);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
334 CU_ASSERT(elms[3].aggr_matrix[1] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
335 CU_ASSERT(elms[3].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
336 CU_ASSERT(elms[3].aggr_matrix[3] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
337 CU_ASSERT(elms[3].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
338 CU_ASSERT(elms[3].aggr_matrix[5] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
339
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
340 CU_ASSERT(elms[4].aggr_matrix[0] == -3);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
341 CU_ASSERT(elms[4].aggr_matrix[1] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
342 CU_ASSERT(elms[4].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
343 CU_ASSERT(elms[4].aggr_matrix[3] == 5);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
344 CU_ASSERT(elms[4].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
345 CU_ASSERT(elms[4].aggr_matrix[5] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
346
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
347 CU_ASSERT(elms[5].aggr_matrix[0] == 2);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
348 CU_ASSERT(elms[5].aggr_matrix[1] == -1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
349 CU_ASSERT(elms[5].aggr_matrix[2] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
350 CU_ASSERT(elms[5].aggr_matrix[3] == 0);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
351 CU_ASSERT(elms[5].aggr_matrix[4] == 1);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
352 CU_ASSERT(elms[5].aggr_matrix[5] == 0);
2
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
353
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
354 x = 50;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
355 y = 99;
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
356 coord_trans_pos(elms + 5, &x, &y);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
357 CU_ASSERT(x == 1);
31402929c587 Transform position
Thinker K.F. Li <thinker@branda.to>
parents: 1
diff changeset
358 CU_ASSERT(y == 99);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
359 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
360
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
361 void test_preorder_coord_subtree(void) {
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
362 coord_t elms[6];
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
363 coord_t *last;
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
364
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
365 coord_init(elms, NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
366 coord_init(elms + 1, elms);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
367 coord_init(elms + 2, elms);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
368 coord_init(elms + 3, elms + 1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
369 coord_init(elms + 4, elms + 1);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
370 coord_init(elms + 5, elms + 2);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
371
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
372 last = elms;
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
373 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
374 CU_ASSERT(last == elms + 1);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
375 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
376 CU_ASSERT(last == elms + 3);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
377 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
378 CU_ASSERT(last == elms + 4);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
379 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
380 CU_ASSERT(last == elms + 2);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
381 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
382 CU_ASSERT(last == elms + 5);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
383 last = preorder_coord_subtree(elms, last);
12
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
384 CU_ASSERT(last == NULL);
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
385 }
79e9edf4c00a Add redraw manager
Thinker K.F. Li <thinker@branda.to>
parents: 5
diff changeset
386
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
387 CU_pSuite get_coord_suite(void) {
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
388 CU_pSuite suite;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
389
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
390 suite = CU_add_suite("Suite_coord", NULL, NULL);
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
391 CU_ADD_TEST(suite, test_update_aggr_matrix);
13
ed55009d96d3 refactory for redrawing
Thinker K.F. Li <thinker@branda.to>
parents: 12
diff changeset
392 CU_ADD_TEST(suite, test_preorder_coord_subtree);
1
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
393
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
394 return suite;
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
395 }
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
396
b5c0162ccf69 Coordination tranforming
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
397 #endif