Mercurial > MadButterfly
annotate src/shape_path.c @ 1524:d46ba9e7f837
Update action list with timeline names of current component.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Aug 2011 14:53:55 +0800 |
parents | bae104d8d247 |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
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:
770
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <stdio.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #include <stdlib.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 #include <ctype.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 #include <string.h> |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
7 #include <math.h> |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
8 #include "mb_graph_engine.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
|
9 #include "mb_types.h" |
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_redraw_man.h" |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 |
8 | 12 /*! \brief Implement respective objects for SVG path tag. |
13 * | |
14 * In user_data or dev_data, 0x00 bytes are padding after commands. | |
15 * No commands other than 0x00 can resident after 0x00 itself. | |
16 * It means command processing code can skip commands after a 0x00. | |
12 | 17 * |
18 * Shapes should check if shape_t::geo is assigned. Once transformation | |
19 * matrics are changed, shape objects should update shape_t::geo if | |
20 * it is assigned. | |
8 | 21 */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 typedef struct _sh_path { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 shape_t shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 int cmd_len; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
25 int pnt_len; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
26 int float_arg_len; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
27 char *user_data; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 char *dev_data; /* device space data */ |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
29 |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
30 redraw_man_t *rdman; /*!< \brief This is used by sh_path_free() */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 } sh_path_t; |
10 | 32 #define RESERVED_AIXS sizeof(co_aix[2]) |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
34 int _sh_path_size = sizeof(sh_path_t); |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
35 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 #define ASSERT(x) |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
37 #define SKIP_SPACE(x) while(*(x) && (isspace(*(x)) || *(x) == ',')) { (x)++; } |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 #define SKIP_NUM(x) \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 while(*(x) && \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 (isdigit(*(x)) || \ |
112
abb5511c23f7
Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents:
101
diff
changeset
|
41 *(x) == 'e' || \ |
abb5511c23f7
Accept exponent of float point
Thinker K.F. Li <thinker@branda.to>
parents:
101
diff
changeset
|
42 *(x) == 'E' || \ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 *(x) == '-' || \ |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
44 *(x) == '+' || \ |
709 | 45 *(x) == '.')) { \ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 (x)++; \ |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 #define OK 0 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 #define ERR -1 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
50 #define PI 3.1415926535897931 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
51 #define FRAC_PI ((int)(PI * FRACTION_ONE)) |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
52 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
53 #define SWAP(x, y) do { x ^= y; y ^= x; x ^= y; } while(0) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
54 #define MAX(x, y) (((x) > (y))? (x): (y)) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
55 #define MIN(x, y) (((x) > (y))? (y): (x)) |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
56 #define IS_NEGATIVE(x) ((x) < 0) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
57 |
235 | 58 #ifdef UNITTEST |
1062
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
865
diff
changeset
|
59 #undef rdman_man_shape |
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
865
diff
changeset
|
60 #define rdman_man_shape(x, y) |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
61 |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
62 #undef elmpool_elm_alloc |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
63 #define elmpool_elm_alloc(pool) _elmpool_elm_alloc(pool) |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
64 static void * |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
65 _elmpool_elm_alloc(void *dummy) { |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
66 return malloc(sizeof(sh_path_t)); |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
67 } |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
68 |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
69 #undef elmpool_elm_free |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
70 #define elmpool_elm_free(pool, elm) _elmpool_elm_free(pool, elm) |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
71 static void |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
72 _elmpool_elm_free(void *pool, void *elm) { |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
73 free(elm); |
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
74 } |
235 | 75 #endif |
76 | |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
77 /* ============================================================ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
78 * Implement arc in path. |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
79 */ |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
80 #if 1 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
81 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
82 #include <stdint.h> |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
83 #include "precomputed.h" |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
84 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
85 #define ABS(x) (((x) > 0)? (x): -(x)) |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
86 #define FRACTION_ONE (1 << FRACTION_SHIFT) |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
87 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
88 /*! \brief Compute the small slope of a vector. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
89 * |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
90 * A small slope is based on absolute value of x-axis and y-axis. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
91 * And use smaller one of absolute values as divisor. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
92 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
93 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
94 _small_slope(int x, int y) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
95 int _x, _y; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
96 int r; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
97 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
98 _x = ABS(x); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
99 _y = ABS(y); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
100 if(_x > _y) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
101 r = (_y << FRACTION_SHIFT) / _x; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
102 else |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
103 r = (_x << FRACTION_SHIFT) / _y; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
104 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
105 return r; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
106 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
107 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
108 /*! \brief Index a given angle in slope table. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
109 * |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
110 * Binary search. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
111 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
112 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
113 _find_slope_index(int slope) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
114 int left, right, v; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
115 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
116 left = 0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
117 right = SLOPE_TAB_SZ - 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
118 while(left <= right) { |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
119 v = (left + right) / 2; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
120 if(slope < slope_tab[v]) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
121 right = v - 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
122 else |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
123 left = v + 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
124 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
125 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
126 return v; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
127 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
128 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
129 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
130 _vector_len(int x, int y) { |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
131 int64_t _x, _y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
132 int64_t slope; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
133 int64_t slope_index; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
134 int64_t radius; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
135 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
136 _x = ABS(x); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
137 _y = ABS(y); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
138 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
139 if(_x > _y) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
140 slope = (_y << FRACTION_SHIFT) / _x; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
141 slope_index = _find_slope_index(slope); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
142 radius = _x * vector_len_factor_tab[slope_index]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
143 } else { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
144 slope = (_x << FRACTION_SHIFT) / _y; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
145 slope_index = _find_slope_index(slope); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
146 radius = _y * vector_len_factor_tab[slope_index]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
147 } |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
148 radius = radius / FRACTION_ONE; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
149 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
150 return radius; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
151 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
152 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
153 /*! \brief Find index of an arc-to-radius ratio in arc_radius_ratio_tab. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
154 * |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
155 * Binary search. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
156 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
157 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
158 _find_arc_radius(int arc_radius_ratio) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
159 int left, right, v; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
160 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
161 left = 0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
162 right = ARC_RADIUS_RATIO_TAB_SZ - 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
163 while(left <= right) { |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
164 v = (left + right) / 2; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
165 if(arc_radius_ratio < arc_radius_ratio_tab[v]) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
166 right = v - 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
167 else |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
168 left = v + 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
169 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
170 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
171 return v; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
172 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
173 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
174 /* Compute shift factor for the ratio of arc to radius */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
175 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
176 _get_arc_radius_shift_factor(int arc_x, int arc_y, int radius) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
177 int arc_len; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
178 int radius_len; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
179 int arc_radius_ratio; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
180 int arc_radius_index; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
181 int arc_radius_factor; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
182 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
183 arc_len = _vector_len(ABS(arc_x), ABS(arc_y)); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
184 arc_radius_ratio = (arc_len << FRACTION_SHIFT) / radius; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
185 arc_radius_index = _find_arc_radius(arc_radius_ratio); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
186 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
187 arc_radius_factor = arc_radius_factor_tab[arc_radius_index]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
188 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
189 return arc_radius_factor; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
190 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
191 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
192 /* Return a unit vector in the extend direction. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
193 * |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
194 * This function make a decision on the direction of extend to make |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
195 * radius of rx direction equivlant to ry direction. It extends the |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
196 * direction of short one. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
197 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
198 static void |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
199 _compute_extend_unit_vector(int rx, int ry, int x_rotate, |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
200 int64_t *ext_unit_x, int64_t *ext_unit_y) { |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
201 int extend_dir; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
202 int extend_phase; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
203 int extend_index; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
204 int extend_sin, extend_cos; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
205 /* Change sign of x, y values accroding phase of the vector. */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
206 static int sin_cos_signs_tab[4][2] = { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
207 /* 0 for positive, 1 for negative */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
208 {0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
209 int *signs; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
210 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
211 if(rx > ry) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
212 extend_dir = x_rotate + (FRAC_PI >> 1); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
213 else |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
214 extend_dir = x_rotate; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
215 extend_dir %= FRAC_PI * 2; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
216 extend_phase = extend_dir / (FRAC_PI >> 1); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
217 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
218 extend_index = (extend_dir % (FRAC_PI >> 1)) * SIN_TAB_SZ / |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
219 (FRAC_PI >> 1); |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
220 if(extend_phase & 0x1) /* half-phases 1,3 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
221 extend_index = SIN_TAB_SZ - extend_index - 1; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
222 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
223 extend_sin = sin_tab[extend_index]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
224 extend_cos = sin_tab[SIN_TAB_SZ - extend_index - 1]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
225 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
226 signs = sin_cos_signs_tab[extend_phase]; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
227 *ext_unit_x = signs[0]? -extend_cos: extend_cos; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
228 *ext_unit_y = signs[1]? -extend_sin: extend_sin; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
229 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
230 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
231 static void |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
232 _get_center_ref_shift(int arc_x, int arc_y, int large, int sweep, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
233 int slope_index, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
234 int64_t *shift_cx, int64_t *shift_cy) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
235 int _shift_cx, _shift_cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
236 int stat = 0; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
237 /* Change sign of shift-x/y accroding sign of arc_x, arc_y, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
238 * large and sweep. |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
239 */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
240 static int shift_signs_tab[16][2] = { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
241 /* +x,+y -x,+y +x,-y -x,-y */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
242 {1, 1}, {0, 1}, {1, 0}, {0, 0}, /* small, negative-angle */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
243 {0, 0}, {1, 0}, {0, 1}, {1, 1}, /* large, negative-angle */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
244 {0, 0}, {1, 0}, {0, 1}, {1, 1}, /* small, positive-angle */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
245 {1, 1}, {0, 1}, {1, 0}, {0, 0} /* large, positive-angle */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
246 }; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
247 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
248 _shift_cx = center_shift_tab[slope_index][0]; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
249 _shift_cy = center_shift_tab[slope_index][1]; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
250 if(ABS(arc_x) <= ABS(arc_y)) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
251 SWAP(_shift_cx, _shift_cy); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
252 _shift_cx = -_shift_cx; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
253 _shift_cy = -_shift_cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
254 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
255 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
256 if(IS_NEGATIVE(arc_x)) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
257 stat |= 0x1; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
258 if(IS_NEGATIVE(arc_y)) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
259 stat |= 0x2; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
260 if(large) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
261 stat |= 0x4; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
262 if(sweep) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
263 stat |= 0x8; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
264 if(shift_signs_tab[stat][0]) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
265 _shift_cx = -_shift_cx; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
266 if(shift_signs_tab[stat][1]) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
267 _shift_cy = -_shift_cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
268 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
269 *shift_cx = _shift_cx; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
270 *shift_cy = _shift_cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
271 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
272 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
273 static int |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
274 _calc_center_i(int x0, int y0, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
275 int x, int y, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
276 int rx, int ry, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
277 int x_rotate, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
278 int large, int sweep, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
279 int *cx, int *cy) { |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
280 int64_t radius; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
281 int64_t ext_unit_y, ext_unit_x; /* x and y value of unit vector on |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
282 * extend direction */ |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
283 int64_t arc_x, arc_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
284 int64_t radius_ref_ratio; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
285 int64_t arc_radius_factor; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
286 int64_t slope, slope_index; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
287 int64_t shift_cx, shift_cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
288 int64_t center_shift_factor; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
289 static int negatives[4] = {0, 1, 1, 0}; |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
290 int64_t extend_len; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
291 int64_t extend_x, extend_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
292 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
293 ASSERT(rx >= 0 && ry >= 0); |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
294 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
295 arc_x = x - x0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
296 arc_y = y - y0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
297 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
298 if(arc_x == 0 && arc_y == 0) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
299 *cx = x0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
300 *cy = y0; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
301 return OK; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
302 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
303 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
304 /* Translate arc to the coordinate that extend rx or ry to the |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
305 * equivlant size as another. It translate the ellipse to a |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
306 * circle. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
307 */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
308 radius = MAX(rx, ry); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
309 _compute_extend_unit_vector(rx, ry, x_rotate, &ext_unit_x, &ext_unit_y); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
310 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
311 extend_len = (arc_x * ext_unit_x + arc_y * ext_unit_y) / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
312 extend_len = extend_len * (MAX(rx, ry) - MIN(rx, ry)) / MIN(rx, ry); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
313 extend_x = ext_unit_x * extend_len / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
314 extend_y = ext_unit_y * extend_len / FRACTION_ONE; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
315 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
316 arc_x += extend_x; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
317 arc_y += extend_y; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
318 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
319 /* Find range index of slope. */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
320 slope = _small_slope(arc_x, arc_y); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
321 slope_index = _find_slope_index(slope); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
322 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
323 /* Compute shift factor for the ratio of arc to radius */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
324 arc_radius_factor = _get_arc_radius_shift_factor(arc_x, arc_y, radius); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
325 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
326 /* Compute ratio of radius to reference radius */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
327 radius_ref_ratio = radius >> REF_RADIUS_SHIFT; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
328 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
329 /* Compute x/y-shift of center range index according |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
330 * slope_index, radius_ref_ratio and arc_radius_factor. |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
331 */ |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
332 _get_center_ref_shift(arc_x, arc_y, large, sweep, slope_index, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
333 &shift_cx, &shift_cy); |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
334 center_shift_factor = radius_ref_ratio * arc_radius_factor; |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
335 center_shift_factor = center_shift_factor / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
336 shift_cx = shift_cx * center_shift_factor / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
337 shift_cy = shift_cy * center_shift_factor / FRACTION_ONE; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
338 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
339 shift_cx += arc_x / 2; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
340 shift_cy += arc_y / 2; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
341 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
342 /* translate shift_cx/cy back to original coordinate */ |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
343 extend_len = (shift_cx * ext_unit_x + shift_cy * ext_unit_y) / |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
344 FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
345 extend_len = extend_len * (MAX(rx, ry) - MIN(rx, ry)) / MAX(rx, ry); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
346 extend_x = ext_unit_x * extend_len / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
347 extend_y = ext_unit_y * extend_len / FRACTION_ONE; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
348 shift_cx = shift_cx - extend_x; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
349 shift_cy = shift_cy - extend_y; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
350 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
351 /* get center */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
352 *cx = x0 + shift_cx; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
353 *cy = y0 + shift_cy; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
354 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
355 return OK; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
356 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
357 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
358 static int _calc_center(co_aix x0, co_aix y0, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
359 co_aix x, co_aix y, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
360 co_aix rx, co_aix ry, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
361 co_aix x_rotate, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
362 int large, int sweep, |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
363 co_aix *cx, co_aix *cy) { |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
364 int cx_i, cy_i; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
365 int r; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
366 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
367 r = _calc_center_i(x0 * FRACTION_ONE, y0 * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
368 x * FRACTION_ONE, y * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
369 rx * FRACTION_ONE, ry * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
370 x_rotate * FRACTION_ONE, |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
371 large, sweep, &cx_i, &cy_i); |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
372 *cx = (co_aix)cx_i / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
373 *cy = (co_aix)cy_i / FRACTION_ONE; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
374 return r; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
375 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
376 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
377 #else |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
378 /*! \brief Calculate center of the ellipse of an arc. |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
379 * |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
380 * Origin of our coordination is left-top corner, and y-axis are grown |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
381 * to down-side. |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
382 * |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
383 * Space of the arc is transformed to space that correspondent |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
384 * ellipse containing the arc is mapped into an unit circle. |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
385 * - ux0 = x0 / rx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
386 * - uy0 = y0 / ry |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
387 * - ux = x / rx |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
388 * - uy = y / ry |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
389 * ux0, uy0, ux, uy are got by transforming (x0, y0) and (x, y) into points |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
390 * on the unit circle. The center of unit circle are (ucx, ucy): |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
391 * - umx = (ux0 + ux) / 2 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
392 * - umy = (uy0 + uy) / 2 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
393 * - udcx = ucx - umx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
394 * - udcy = ucy - umy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
395 * - udx = ux - umx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
396 * - udy = uy - umy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
397 * |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
398 * - udx * udcx + udy * udcy = 0 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
399 * |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
400 * - udl2 = udx ** 2 + udy ** 2 |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
401 * |
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
402 * For drawing small arc in clockwise |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
403 * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
404 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
405 * - udcy = -udcx * udx / udy |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
406 * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
407 * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
408 * - udcx = -sqrt((1 - udl2) * udl2) / ((udx ** 2) / udy + udy) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
409 * or |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
410 * - udcx = -udcy * udy / udx |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
411 * - udx * udcy + udcy * (udy ** 2) / udx = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
412 * - udcy * (udx + (udy ** 2) / udx) = sqrt((1 - udl2) * udl2) |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
413 * - udcy = sqrt((1 - udl2) * udl2) / (udx + (udy ** 2) / udx) |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
414 * |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
415 * - cx = rx * ucx |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
416 * - cx = rx * (udcx + umx) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
417 * - cy = ry * ucy |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
418 * - cy = ry * (udcy + umy) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
419 */ |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
420 static int _calc_center(co_aix x0, co_aix y0, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
421 co_aix x, co_aix y, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
422 co_aix rx, co_aix ry, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
423 co_aix x_rotate, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
424 int large, int sweep, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
425 co_aix *cx, co_aix *cy) { |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
426 co_aix br_x, br_y, br_x0, br_y0; /* before-rotated x, y, x0, y0 */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
427 co_aix udx, udy, udx2, udy2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
428 co_aix umx, umy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
429 co_aix udcx, udcy; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
430 co_aix br_cx, br_cy; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
431 co_aix udl2; |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
432 co_aix rev_rx2, rev_ry2; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
433 float _sin = -sinf(x_rotate); /* rotate to oposite direction */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
434 float _cos = cosf(x_rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
435 int reflect; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
436 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
437 #define X_AFTER_ROTATE(x, y, sin, cos) (x * cos - y * sin) |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
438 #define Y_AFTER_ROTATE(x, y, sin, cos) (x * sin + y * cos) |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
439 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
440 /* Restore positions to the value before rotation */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
441 br_x = X_AFTER_ROTATE(x, y, _sin, _cos); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
442 br_y = Y_AFTER_ROTATE(x, y, _sin, _cos); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
443 br_x0 = X_AFTER_ROTATE(x0, y0, _sin, _cos); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
444 br_y0 = Y_AFTER_ROTATE(x0, y0, _sin, _cos); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
445 |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
446 /* Resize to be an unit circle */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
447 rev_rx2 = 1.0 / (2 * rx); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
448 rev_ry2 = 1.0 / (2 * ry); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
449 udx = (br_x - br_x0) * rev_rx2; /* ux - umx */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
450 udy = (br_y - br_y0) * rev_ry2; /* uy - umy */ |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
451 umx = (br_x + br_x0) * rev_rx2; |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
452 umy = (br_y + br_y0) * rev_ry2; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
453 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
454 udx2 = udx * udx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
455 udy2 = udy * udy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
456 udl2 = udx2 + udy2; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
457 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
458 if(udy != 0) { |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
459 /* center is at left-side of arc */ |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
460 udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
461 udcy = -udcx * udx / udy; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
462 } else { |
269
c96f38ad4bb6
Fix mis-behavior of translate_path_data() on arc.
Thinker K.F. Li <thinker@branda.to>
parents:
235
diff
changeset
|
463 /* center is at down-side of arc */ |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
464 udcx = 0; |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
465 udcy = sqrtf((1 - udl2) * udl2) / udx; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
466 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
467 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
468 reflect = 0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
469 if(large) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
470 reflect ^= 1; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
471 if(sweep != 1) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
472 reflect ^= 1; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
473 if(reflect) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
474 udcx = -udcx; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
475 udcy = -udcy; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
476 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
477 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
478 br_cx = rx * (udcx + umx); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
479 br_cy = ry * (udcy + umy); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
480 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
481 *cx = X_AFTER_ROTATE(br_cx, br_cy, -_sin, _cos); |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
482 *cy = Y_AFTER_ROTATE(br_cx, br_cy, -_sin, _cos); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
483 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
484 return OK; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
485 } |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
486 #endif |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
487 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
488 static co_aix _angle_rotated_ellipse(co_aix x, co_aix y, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
489 co_aix rx, co_aix ry, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
490 co_aix x_rotate) { |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
491 co_aix nrx, nry; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
492 co_aix _sin, _cos; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
493 co_aix xy_tan; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
494 co_aix angle; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
495 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
496 _sin = sinf(x_rotate); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
497 _cos = cosf(x_rotate); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
498 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
499 nrx = (x * _cos + y * _sin) / rx; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
500 nry = (-x * _sin + y * _cos) / ry; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
501 xy_tan = nry / nrx; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
502 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
503 angle = atan(xy_tan); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
504 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
505 if(nrx < 0) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
506 angle = PI + angle; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
507 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
508 return angle; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
509 } |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
510 |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
511 static void _rotate(co_aix *x, co_aix *y, co_aix _sin, co_aix _cos) { |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
512 co_aix nx, ny; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
513 |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
514 nx = *x * _cos - *y * _sin; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
515 ny = *x * _sin + *y * _cos; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
516 |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
517 *x = nx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
518 *y = ny; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
519 } |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
520 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
521 #define TAKE_NUM(r) do { \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
522 SKIP_SPACE(p); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
523 old = p; \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
524 SKIP_NUM(p); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
525 if(p == old) \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
526 return ERR; \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
527 r = atof(old); \ |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
528 } while(0); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
529 |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
530 static int _sh_path_arc_cmd_arg_fill(char cmd, char **cmds_p, |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
531 const char **data_p, |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
532 co_aix **pnts_p, |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
533 co_aix **float_args_p) { |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
534 co_aix rx, ry; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
535 co_aix x_rotate; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
536 int large, sweep; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
537 co_aix x, y, x0, y0, cx, cy; |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
538 co_aix corners[4][2]; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
539 co_aix angle_start, angle_stop; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
540 co_aix *pnts = *pnts_p; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
541 const char *old; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
542 const char *p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
543 char *cmds; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
544 co_aix *float_args; |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
545 co_aix _sin, _cos; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
546 int i; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
547 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
548 p = *data_p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
549 cmds = *cmds_p; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
550 float_args = *float_args_p; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
551 while(*p) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
552 SKIP_SPACE(p); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
553 old = p; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
554 SKIP_NUM(p); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
555 if(p == old) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
556 break; |
99
4aa1c9673363
Arc in path pass the test in example svg2code_ex.
Thinker K.F. Li <thinker@branda.to>
parents:
98
diff
changeset
|
557 rx = atof(old); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
558 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
559 TAKE_NUM(ry); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
560 TAKE_NUM(x_rotate); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
561 TAKE_NUM(large); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
562 TAKE_NUM(sweep); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
563 TAKE_NUM(x); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
564 TAKE_NUM(y) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
565 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
566 x0 = *(pnts - 2); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
567 y0 = *(pnts - 1); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
568 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
569 if(islower(cmd)) { |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
570 x += x0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
571 y += y0; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
572 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
573 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
574 _calc_center(x0, y0, x, y, rx, ry, x_rotate, large, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
575 sweep, &cx, &cy); |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
576 |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
577 /* Compute positions for four corners. |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
578 * These four corners form a bounding box for the arc. |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
579 */ |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
580 _sin = sinf(x_rotate); |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
581 _cos = cosf(x_rotate); |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
582 corners[0][0] = -rx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
583 corners[0][1] = -ry; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
584 corners[1][0] = rx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
585 corners[1][1] = -ry; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
586 corners[2][0] = rx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
587 corners[2][1] = ry; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
588 corners[3][0] = -rx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
589 corners[3][1] = ry; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
590 for(i = 0; i < 4; i++) { |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
591 _rotate(&corners[i][0], &corners[i][1], _sin, _cos); |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
592 *pnts++ = corners[i][0] + cx; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
593 *pnts++ = corners[i][1] + cy; |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
594 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
595 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
596 *(pnts++) = x; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
597 *(pnts++) = y; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
598 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
599 angle_start = _angle_rotated_ellipse(x0 - cx, y0 - cy, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
600 rx, ry, x_rotate); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
601 angle_stop = _angle_rotated_ellipse(x - cx, y - cy, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
602 rx, ry, x_rotate); |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
603 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
604 if(sweep && angle_start > angle_stop) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
605 angle_stop += 2 * PI; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
606 else if((!sweep) && angle_start < angle_stop) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
607 angle_start += 2 * PI; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
608 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
609 *float_args++ = cx; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
610 *float_args++ = cy; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
611 *float_args++ = rx; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
612 *float_args++ = ry; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
613 *float_args++ = angle_start; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
614 *float_args++ = angle_stop; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
615 *float_args++ = x_rotate; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
616 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
617 *cmds++ = toupper(cmd); |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
618 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
619 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
620 *data_p = p; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
621 *pnts_p = pnts; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
622 *cmds_p = cmds; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
623 *float_args_p = float_args; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
624 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
625 return OK; |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
626 } |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
627 |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
628 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
629 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) |
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
630 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
631 static co_aix distance_pow2(co_aix x, co_aix y) { |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
632 return x * x + y * y; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
633 } |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
634 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
635 static co_aix angle_diff(co_aix sx, co_aix sy, co_aix dx, co_aix dy) { |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
636 co_aix inner, cross; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
637 co_aix angle; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
638 co_aix rd2, rd; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
639 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
640 rd2 = distance_pow2(dx, dy); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
641 rd = sqrtf(rd2); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
642 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
643 inner = INNER(sx, sy, dx, dy); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
644 cross = CROSS(sx, sy, dx, dy); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
645 angle = acos(inner / rd); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
646 if(cross < 0) |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
647 angle = 2 * PI - angle; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
648 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
649 return angle; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
650 } |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
651 |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
652 /*! \brief Make path for arcs in a path. |
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
653 */ |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
654 void _sh_path_arc_path(mbe_t *cr, sh_path_t *path, const co_aix **pnts_p, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
655 const co_aix **float_args_p) { |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
656 co_aix cx, cy, x0, y0, x, y; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
657 co_aix rx, ry; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
658 co_aix xyratio; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
659 co_aix angle_start, angle_stop; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
660 co_aix x_rotate; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
661 const co_aix *pnts; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
662 const co_aix *float_args; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
663 co_aix matrix[6]; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
664 co_aix dev_matrix[6]; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
665 co_aix *aggr; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
666 co_aix _sin, _cos; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
667 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
668 pnts = *pnts_p; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
669 float_args = *float_args_p; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
670 x0 = *(pnts - 2); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
671 y0 = *(pnts - 1); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
672 pnts += 8; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
673 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
674 y = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
675 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
676 cx = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
677 cy = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
678 rx = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
679 ry = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
680 angle_start = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
681 angle_stop = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
682 x_rotate = *float_args++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
683 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
684 _sin = sinf(x_rotate); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
685 _cos = cosf(x_rotate); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
686 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
687 xyratio = ry / rx; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
688 aggr = sh_get_aggr_matrix((shape_t *)path); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
689 matrix[0] = _cos; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
690 matrix[1] = -_sin * xyratio; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
691 matrix[2] = cx; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
692 matrix[3] = _sin; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
693 matrix[4] = _cos * xyratio; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
694 matrix[5] = cy; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
695 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
696 matrix_mul(aggr, matrix, dev_matrix); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
697 mbe_save(cr); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
698 mbe_transform(cr, dev_matrix); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
699 mbe_arc(cr, 0, 0, rx, angle_start, angle_stop); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
700 mbe_restore(cr); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
701 |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
702 *pnts_p = pnts; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
703 *float_args_p = float_args; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
704 } |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
705 |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
706 /* ============================================================ */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
707 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
708 static void sh_path_free(shape_t *shape) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
709 sh_path_t *path = (sh_path_t *)shape; |
770
abd9bbf24545
mb_obj_destroy for sh_path_t
Thinker K.F. Li <thinker@codemud.net>
parents:
711
diff
changeset
|
710 |
abd9bbf24545
mb_obj_destroy for sh_path_t
Thinker K.F. Li <thinker@codemud.net>
parents:
711
diff
changeset
|
711 mb_obj_destroy(path); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
712 if(path->user_data) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
713 free(path->user_data); |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
714 elmpool_elm_free(path->rdman->sh_path_pool, path); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
715 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
716 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
717 /*! \brief Count number of arguments. |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
718 * |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
719 * \todo Notify programmers that syntax or value error of path data. |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
73
diff
changeset
|
720 */ |
492
e95598916dfb
Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents:
460
diff
changeset
|
721 static int sh_path_cmd_arg_cnt(const char *data, int *cmd_cntp, int *pnt_cntp, |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
722 int *float_arg_cntp) { |
492
e95598916dfb
Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents:
460
diff
changeset
|
723 const char *p, *old; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
724 int cmd_cnt, pnt_cnt, float_arg_cnt; |
96 | 725 int i; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
726 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
727 cmd_cnt = pnt_cnt = float_arg_cnt = 0; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
728 p = data; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
729 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
730 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
731 switch(*p++) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
732 case 'c': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
733 case 'C': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
734 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
735 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
736 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
737 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
738 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
739 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
740 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
741 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
742 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
743 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
744 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
745 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
746 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
747 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
748 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
749 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
750 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
751 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
752 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
753 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
754 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
755 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
756 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
757 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
758 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
759 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
760 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
761 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
762 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
763 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
764 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
765 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
766 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
767 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
768 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
769 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
770 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
771 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
772 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
773 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
774 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
775 pnt_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
776 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
777 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
778 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
779 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
780 case 's': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
781 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
782 case 'q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
783 case 'Q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
784 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
785 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
786 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
787 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
788 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
789 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
790 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
791 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
792 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
793 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
794 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
795 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
796 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
797 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
798 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
799 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
800 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
801 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
802 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
803 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
804 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
805 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
806 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
807 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
808 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
809 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
810 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
811 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
812 pnt_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
813 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
814 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
815 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
816 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
817 case 'm': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
818 case 'M': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
819 case 'l': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
820 case 'L': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
821 case 't': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
822 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
823 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
824 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
825 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
826 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
827 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
828 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
829 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
830 pnt_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
831 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
832 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
833 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
834 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
835 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
836 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
837 pnt_cnt++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
838 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
839 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
840 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
841 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
842 case 'h': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
843 case 'H': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
844 case 'v': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
845 case 'V': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
846 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
847 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
848 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
849 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
850 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
851 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
852 pnt_cnt += 2; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
853 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
854 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
855 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
856 break; |
96 | 857 case 'A': |
858 case 'a': | |
859 while(*p) { | |
860 SKIP_SPACE(p); | |
861 old = p; | |
862 SKIP_NUM(p); | |
863 if(p == old) | |
864 break; | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
865 |
96 | 866 for(i = 0; i < 6; i++) { |
867 SKIP_SPACE(p); | |
868 old = p; | |
869 SKIP_NUM(p); | |
870 if(p == old) | |
871 return ERR; | |
872 } | |
873 | |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
874 pnt_cnt += 10; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
875 float_arg_cnt += 7; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
876 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
877 cmd_cnt++; |
96 | 878 } |
879 break; | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
880 case 'z': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
881 case 'Z': |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
882 cmd_cnt++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
883 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
884 default: |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
885 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
886 } |
96 | 887 /*! \todo cmd_cnt should be increased for each implicit repeating. */ |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
888 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
889 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
890 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
891 *cmd_cntp = cmd_cnt; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
892 *pnt_cntp = pnt_cnt; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
893 *float_arg_cntp = float_arg_cnt; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
894 return OK; |
96 | 895 } |
896 | |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
897 #define TO_ABSX islower(cmd)? x + atof(old): atof(old) |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
898 #define TO_ABSY islower(cmd)? y + atof(old): atof(old) |
10 | 899 |
492
e95598916dfb
Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents:
460
diff
changeset
|
900 static int sh_path_cmd_arg_fill(const char *data, sh_path_t *path) { |
e95598916dfb
Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents:
460
diff
changeset
|
901 const char *p, *old; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
902 char *cmds; |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
903 char cmd; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
904 co_aix *pnts; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
905 co_aix *float_args; |
711
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
906 co_aix sx = 0, sy = 0; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
907 co_aix x, y; |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
908 int r; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
909 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
910 cmds = path->user_data; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
911 pnts = (co_aix *)(cmds + path->cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
912 float_args = (co_aix *)(cmds + path->cmd_len + |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
913 path->pnt_len * sizeof(co_aix)); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
914 p = data; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
915 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
916 while(*p) { |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
917 /* Transform all relative to absolute, */ |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
918 x = *(pnts - 2); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
919 y = *(pnts - 1); |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
920 |
7
569f3168ba53
Clear background & tranform relative pos into absolute ones
Thinker K.F. Li <thinker@branda.to>
parents:
6
diff
changeset
|
921 switch((cmd = *p++)) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
922 case 'c': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
923 case 'C': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
924 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
925 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
926 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
927 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
928 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
929 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
930 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
931 *pnts = TO_ABSX; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
932 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
933 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
934 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
935 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
936 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
937 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
938 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
939 *pnts = TO_ABSY; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
940 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
941 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
942 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
943 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
944 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
945 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
946 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
947 *pnts = TO_ABSX; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
948 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
949 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
950 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
951 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
952 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
953 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
954 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
955 *pnts = TO_ABSY; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
956 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
957 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
958 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
959 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
960 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
961 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
962 *pnts = TO_ABSX; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
963 x = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
964 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
965 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
966 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
967 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
968 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
969 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
970 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
971 *pnts = TO_ABSY; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
972 y = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
973 pnts++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
974 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
975 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
976 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
977 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
978 case 's': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
979 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
980 case 'q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
981 case 'Q': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
982 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
983 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
984 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
985 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
986 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
987 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
988 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
989 *pnts = TO_ABSX; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
990 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
991 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
992 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
993 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
994 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
995 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
996 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
997 *pnts = TO_ABSY; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
998 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
999 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1000 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1001 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1002 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1003 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1004 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1005 *pnts = TO_ABSX; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
1006 x = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1007 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1008 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1009 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1010 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1011 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1012 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1013 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1014 *pnts = TO_ABSY; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
1015 y = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1016 pnts++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1017 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1018 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1019 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1020 break; |
711
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1021 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1022 case 'm': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1023 case 'M': |
711
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1024 while(*p) { |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1025 old = p; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1026 SKIP_SPACE(p); |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1027 old = p; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1028 SKIP_NUM(p); |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1029 if(p == old) |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1030 break; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1031 *pnts = TO_ABSX; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1032 x = *pnts; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1033 pnts++; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1034 |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1035 SKIP_SPACE(p); |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1036 old = p; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1037 SKIP_NUM(p); |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1038 if(p == old) |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1039 return ERR; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1040 *pnts = TO_ABSY; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1041 y = *pnts; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1042 pnts++; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1043 |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1044 *cmds++ = toupper(cmd); |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1045 |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1046 /* save initial point of a subpath */ |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1047 sx = x; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1048 sy = y; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1049 } |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1050 break; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
1051 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1052 case 'l': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1053 case 'L': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1054 case 't': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1055 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1056 while(*p) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1057 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1058 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1059 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1060 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1061 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1062 break; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1063 *pnts = TO_ABSX; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
1064 x = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1065 pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1066 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1067 SKIP_SPACE(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1068 old = p; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1069 SKIP_NUM(p); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1070 if(p == old) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1071 return ERR; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1072 *pnts = TO_ABSY; |
707
594827d0f3e5
Fix issue of relative path data.
Thinker K.F. Li <thinker@branda.to>
parents:
492
diff
changeset
|
1073 y = *pnts; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1074 pnts++; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1075 |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1076 *cmds++ = toupper(cmd); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1077 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1078 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1079 case 'h': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1080 case 'H': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1081 case 'v': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1082 case 'V': |
58 | 1083 /*! \todo implement h, H, v, V comamnds for path. */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1084 return ERR; |
96 | 1085 |
1086 case 'A': | |
1087 case 'a': | |
459
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
1088 r = _sh_path_arc_cmd_arg_fill(cmd, &cmds, |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
1089 (const char **)&p, &pnts, |
8b155b77fa14
Count positions an arc being for bounding box of the path.
Thinker K.F. Li <thinker@branda.to>
parents:
458
diff
changeset
|
1090 &float_args); |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1091 if(r != OK) |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1092 return ERR; |
96 | 1093 break; |
1094 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1095 case 'z': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1096 case 'Z': |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1097 *cmds++ = toupper(cmd); |
711
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1098 /* Go back to initial point of a subpath */ |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1099 x = sx; |
da794f4fe96c
save and restore initial point at m and z commands of path
Thinker K.F. Li <thinker@branda.to>
parents:
709
diff
changeset
|
1100 y = sy; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1101 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1102 default: |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1103 return ERR; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1104 } |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1105 SKIP_SPACE(p); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1106 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1107 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1108 return OK; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1109 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1110 |
9 | 1111 /*! \brief Create a path from value of 'data' of SVG path. |
1112 */ | |
492
e95598916dfb
Make path data constant.
Thinker K.F. Li <thinker@branda.to>
parents:
460
diff
changeset
|
1113 shape_t *rdman_shape_path_new(redraw_man_t *rdman, const char *data) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1114 sh_path_t *path; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1115 int cmd_cnt, pnt_cnt, float_arg_cnt; |
98
688f76b8e71c
Implement arc for path, but it is still under testing
Thinker K.F. Li <thinker@branda.to>
parents:
97
diff
changeset
|
1116 int msz; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1117 int r; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1118 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1119 r = sh_path_cmd_arg_cnt(data, &cmd_cnt, &pnt_cnt, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1120 &float_arg_cnt); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1121 if(r == ERR) |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1122 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1123 |
8 | 1124 /* Align at 4's boundary and keep 2 unused co_aix space |
1125 * to make logic of transformation from relative to absolute | |
1126 * simple. | |
1127 */ | |
10 | 1128 cmd_cnt += RESERVED_AIXS; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1129 cmd_cnt = (cmd_cnt + 3) & ~0x3; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1130 |
149 | 1131 /*! \todo Use elmpool to manage sh_path_t objects. */ |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1132 path = (sh_path_t *)elmpool_elm_alloc(rdman->sh_path_pool); |
146
e96a584487af
Use elmpool to manage paint_color_t objects.
Thinker K.F. Li <thinker@branda.to>
parents:
145
diff
changeset
|
1133 /*! \todo Remove this memset()? */ |
12 | 1134 memset(&path->shape, 0, sizeof(shape_t)); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
202
diff
changeset
|
1135 mb_obj_init(path, MBO_PATH); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1136 path->cmd_len = cmd_cnt; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1137 path->pnt_len = pnt_cnt; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1138 path->float_arg_len = float_arg_cnt; |
145
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1139 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1140 msz = cmd_cnt + sizeof(co_aix) * pnt_cnt + |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1141 sizeof(co_aix) * float_arg_cnt; |
145
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1142 path->user_data = (char *)malloc(msz * 2); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1143 if(path->user_data == NULL) { |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1144 elmpool_elm_free(rdman->sh_path_pool, path); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1145 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1146 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1147 |
145
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1148 path->dev_data = path->user_data + msz; |
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1149 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1150 r = sh_path_cmd_arg_fill(data, path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1151 if(r == ERR) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1152 free(path->user_data); |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1153 elmpool_elm_free(rdman->sh_path_pool, path); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1154 return NULL; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1155 } |
100
1a1dda98730c
Fix the bug of order of cross & inner product of vectors
Thinker K.F. Li <thinker@branda.to>
parents:
99
diff
changeset
|
1156 memcpy(path->dev_data, path->user_data, msz); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1157 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1158 path->shape.free = sh_path_free; |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1159 path->rdman = rdman; |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1160 |
1062
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
865
diff
changeset
|
1161 rdman_man_shape(rdman, (shape_t *)path); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
149
diff
changeset
|
1162 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1163 return (shape_t *)path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1164 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1165 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1166 shape_t *rdman_shape_path_new_from_binary(redraw_man_t *rdman, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1167 char *commands, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1168 co_aix *pnts, int pnt_cnt, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1169 co_aix *float_args, |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1170 int float_arg_cnt) { |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1171 sh_path_t *path; |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1172 int msz; |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1173 int cmd_cnt = strlen(commands); |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1174 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1175 /*! \todo Use elmpool to manage sh_path_t objects. */ |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1176 path = (sh_path_t *)elmpool_elm_alloc(rdman->sh_path_pool); |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1177 /*! \todo Remove this memset()? */ |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1178 memset(&path->shape, 0, sizeof(shape_t)); |
224
29e1b2bffe4c
X backend only sent EVT_MOUSE_MOVE_RAW to MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
202
diff
changeset
|
1179 mb_obj_init(path, MBO_PATH); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1180 cmd_cnt = (cmd_cnt + 3) & ~0x3; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1181 path->cmd_len = cmd_cnt; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1182 path->pnt_len = pnt_cnt; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1183 path->float_arg_len = float_arg_cnt; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1184 msz = cmd_cnt + sizeof(co_aix) * pnt_cnt + |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1185 sizeof(co_aix) * float_arg_cnt; |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1186 path->user_data = (char *)malloc(msz * 2); |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1187 if(path->user_data == NULL) { |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1188 elmpool_elm_free(rdman->sh_path_pool, path); |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1189 return NULL; |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1190 } |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1191 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1192 path->dev_data = path->user_data + msz; |
1165
9f2b5a1a0d84
Fix bug of unpredicatible output of tank.
Thinker K.F. Li <thinker@codemud.net>
parents:
1134
diff
changeset
|
1193 memcpy(path->user_data, commands, strlen(commands) + 1); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1194 memcpy(path->user_data + cmd_cnt, pnts, sizeof(co_aix) * pnt_cnt); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1195 memcpy(path->user_data + cmd_cnt + pnt_cnt * sizeof(co_aix), |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1196 float_args, sizeof(co_aix) * float_arg_cnt); |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1197 memcpy(path->dev_data, path->user_data, msz); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
1198 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1199 path->shape.free = sh_path_free; |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1200 path->rdman = rdman; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
770
diff
changeset
|
1201 |
1062
a8d20bc8ce40
Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents:
865
diff
changeset
|
1202 rdman_man_shape(rdman, (shape_t *)path); |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1203 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1204 return (shape_t *)path; |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1205 } |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1206 |
1370
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1207 shape_t * |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1208 rdman_shape_path_clone(redraw_man_t *rdman, const shape_t *_src_path) { |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1209 const sh_path_t *src_path = (const sh_path_t *)_src_path; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1210 sh_path_t *new_path; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1211 char *udata; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1212 char *cmds; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1213 co_aix *pnts, *float_args; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1214 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1215 udata = src_path->user_data; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1216 cmds = udata; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1217 pnts = (co_aix *)(udata + src_path->cmd_len); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1218 float_args = pnts + src_path->pnt_len; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1219 new_path = |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1220 (sh_path_t *)rdman_shape_path_new_from_binary(rdman, |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1221 cmds, |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1222 pnts, src_path->pnt_len, |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1223 float_args, |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1224 src_path->float_arg_len); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1225 if(new_path == NULL) |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1226 return NULL; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1227 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1228 sh_copy_style(rdman, (shape_t *)src_path, (shape_t *)new_path); |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1229 |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1230 return (shape_t *)new_path; |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1231 } |
bae104d8d247
Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents:
1165
diff
changeset
|
1232 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
186
diff
changeset
|
1233 |
9 | 1234 /*! \brief Transform a path from user space to device space. |
1235 * | |
1236 */ | |
12 | 1237 void sh_path_transform(shape_t *shape) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1238 sh_path_t *path; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1239 co_aix *pnts, *dev_pnts; |
12 | 1240 co_aix (*poses)[2]; |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
1241 area_t *area; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1242 int pnt_len; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1243 int i; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1244 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1245 ASSERT(shape->type == SHT_PATH); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1246 ASSERT((shape->pnt_len & 0x1) == 0); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1247 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1248 path = (sh_path_t *)shape; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1249 pnts = (co_aix *)(path->user_data + path->cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1250 dev_pnts = (co_aix *)(path->dev_data + path->cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1251 pnt_len = path->pnt_len; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1252 for(i = 0; i < pnt_len; i += 2) { |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1253 dev_pnts[0] = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1254 dev_pnts[1] = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1255 coord_trans_pos(shape->coord, dev_pnts, dev_pnts + 1); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1256 dev_pnts += 2; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1257 } |
12 | 1258 |
1259 if(path->shape.geo) { | |
1260 poses = (co_aix (*)[2])(path->dev_data + path->cmd_len); | |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1261 geo_from_positions(path->shape.geo, pnt_len / 2, poses); |
26
d50f33040de6
Set line width for path.
Thinker K.F. Li <thinker@branda.to>
parents:
22
diff
changeset
|
1262 area = shape->geo->cur_area; |
270
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
269
diff
changeset
|
1263 area->x -= shape->stroke_width / 2 + 0.5; |
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
269
diff
changeset
|
1264 area->y -= shape->stroke_width / 2 + 0.5; |
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
269
diff
changeset
|
1265 area->w += shape->stroke_width + 1; |
cd6af7da32c9
Fix the problem that clean_canvas() can not clean canvas cleanly.
Thinker K.F. Li <thinker@branda.to>
parents:
269
diff
changeset
|
1266 area->h += shape->stroke_width + 1; |
12 | 1267 } |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1268 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1269 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1270 static void sh_path_path(shape_t *shape, mbe_t *cr) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1271 sh_path_t *path; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1272 int cmd_len; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1273 char *cmds, cmd; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1274 const co_aix *pnts; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1275 const co_aix *float_args; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1276 co_aix x, y, x1, y1, x2, y2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1277 int i; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1278 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1279 ASSERT(shape->type == SHT_PATH); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1280 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1281 path = (sh_path_t *)shape; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1282 cmd_len = path->cmd_len; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1283 cmds = path->dev_data; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1284 pnts = (co_aix *)(cmds + cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1285 float_args = (co_aix *)(cmds + cmd_len + path->pnt_len * sizeof(co_aix)); |
15
c2ce186a5c37
X_main uses rdman_redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
12
diff
changeset
|
1286 x = y = x1 = y1 = x2 = y2 = 0; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1287 for(i = 0; i < cmd_len; i++) { |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1288 /* All path commands and arguments are transformed |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1289 * to absoluted form. |
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1290 */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1291 cmd = *cmds++; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1292 switch(cmd) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1293 case 'M': |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1294 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1295 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1296 mbe_move_to(cr, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1297 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1298 case 'L': |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1299 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1300 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1301 mbe_line_to(cr, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1302 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1303 case 'C': |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1304 x1 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1305 y1 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1306 x2 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1307 y2 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1308 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1309 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1310 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1311 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1312 case 'S': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1313 x1 = x + x - x2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1314 y1 = y + y - y2; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1315 x2 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1316 y2 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1317 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1318 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1319 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1320 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1321 case 'Q': |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1322 x1 = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1323 y1 = *pnts++; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1324 x2 = x1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1325 y2 = y1; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1326 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1327 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1328 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1329 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1330 case 'T': |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1331 x1 = x + x - x2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1332 y1 = y + y - y2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1333 x2 = x1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1334 y2 = y1; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1335 x = *pnts++; |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1336 y = *pnts++; |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1337 mbe_curve_to(cr, x1, y1, x2, y2, x, y); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1338 break; |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1339 case 'A': |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1340 _sh_path_arc_path(cr, path, &pnts, &float_args); |
97
9453e68092b5
Fix bug of translation relative to absolute points
Thinker K.F. Li <thinker@branda.to>
parents:
96
diff
changeset
|
1341 break; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1342 case 'Z': |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1343 mbe_close_path(cr); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1344 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1345 case '\x0': |
8 | 1346 i = cmd_len; /* padding! Skip remain ones. */ |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1347 break; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1348 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1349 } |
22 | 1350 } |
6
772511b8b9be
Cairo specify RGB values in range 0.0 ~ 1.0.
Thinker K.F. Li <thinker@branda.to>
parents:
5
diff
changeset
|
1351 |
448
16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents:
270
diff
changeset
|
1352 void sh_path_draw(shape_t *shape, mbe_t *cr) { |
30
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
1353 sh_path_path(shape, cr); |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
1354 } |
e06a4a667ce2
Accept mouse/pointer event and hint the shape that the pointer is over.
Thinker K.F. Li <thinker@branda.to>
parents:
26
diff
changeset
|
1355 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1356 #ifdef UNITTEST |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1357 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1358 #include <CUnit/Basic.h> |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1359 |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
149
diff
changeset
|
1360 void test_rdman_shape_path_new(void) { |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1361 sh_path_t *path; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1362 co_aix *pnts; |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1363 redraw_man_t rdman; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1364 |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1365 path = (sh_path_t *)rdman_shape_path_new(&rdman, "M 33 25l33 55c 33 87 44 22 55 99L33 77z"); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1366 CU_ASSERT(path != NULL); |
10 | 1367 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1368 CU_ASSERT(path->pnt_len == 12); |
145
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1369 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); |
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1370 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1371 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1372 pnts = (co_aix *)(path->user_data + path->cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1373 CU_ASSERT(pnts[0] == 33); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1374 CU_ASSERT(pnts[1] == 25); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1375 CU_ASSERT(pnts[2] == 66); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1376 CU_ASSERT(pnts[3] == 80); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1377 CU_ASSERT(pnts[4] == 99); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1378 CU_ASSERT(pnts[5] == 167); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1379 CU_ASSERT(pnts[6] == 110); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1380 CU_ASSERT(pnts[7] == 102); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1381 CU_ASSERT(pnts[8] == 121); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1382 CU_ASSERT(pnts[9] == 179); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1383 CU_ASSERT(pnts[10] == 33); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1384 CU_ASSERT(pnts[11] == 77); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1385 sh_path_free((shape_t *)path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1386 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1387 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1388 void test_path_transform(void) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1389 sh_path_t *path; |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1390 co_aix *pnts; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1391 coord_t coord; |
12 | 1392 geo_t geo; |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1393 redraw_man_t rdman; |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1394 |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1395 path = (sh_path_t *)rdman_shape_path_new(&rdman, "M 33 25l33 55C 33 87 44 22 55 99L33 77z"); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1396 CU_ASSERT(path != NULL); |
10 | 1397 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1398 CU_ASSERT(path->pnt_len == 12); |
145
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1399 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); |
609ed47a58f2
Decrease number of malloc().
Thinker K.F. Li <thinker@branda.to>
parents:
112
diff
changeset
|
1400 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1401 |
73
9ab15ebc9061
Observer for mouse events
Thinker K.F. Li <thinker@branda.to>
parents:
58
diff
changeset
|
1402 geo_init(&geo); |
12 | 1403 path->shape.geo = &geo; |
1404 geo.shape = (shape_t *)path; | |
1405 | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1406 coord.aggr_matrix[0] = 1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1407 coord.aggr_matrix[1] = 0; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1408 coord.aggr_matrix[2] = 1; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1409 coord.aggr_matrix[3] = 0; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1410 coord.aggr_matrix[4] = 2; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1411 coord.aggr_matrix[5] = 0; |
12 | 1412 path->shape.coord = &coord; |
1413 sh_path_transform((shape_t *)path); | |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1414 |
458
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1415 pnts = (co_aix *)(path->dev_data + path->cmd_len); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1416 CU_ASSERT(pnts[0] == 34); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1417 CU_ASSERT(pnts[1] == 50); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1418 CU_ASSERT(pnts[2] == 67); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1419 CU_ASSERT(pnts[3] == 160); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1420 CU_ASSERT(pnts[4] == 34); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1421 CU_ASSERT(pnts[5] == 174); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1422 CU_ASSERT(pnts[6] == 45); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1423 CU_ASSERT(pnts[7] == 44); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1424 CU_ASSERT(pnts[8] == 56); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1425 CU_ASSERT(pnts[9] == 198); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1426 CU_ASSERT(pnts[10] == 34); |
bb4f651090bf
Use cairo to transform and draw arc.
Thinker K.F. Li <thinker@branda.to>
parents:
448
diff
changeset
|
1427 CU_ASSERT(pnts[11] == 154); |
12 | 1428 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1429 sh_path_free((shape_t *)path); |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1430 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1431 |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1432 void test_small_slope(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1433 co_aix x, y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1434 co_aix slope; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1435 co_aix r; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1436 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1437 x = 135.3; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1438 y = 149.6; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1439 r = (co_aix)_small_slope(x * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1440 y * FRACTION_ONE) / |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1441 FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1442 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1443 slope = MIN(x, y) / MAX(x, y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1444 CU_ASSERT(((r - slope) / slope) < 0.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1445 ((r - slope) / slope) > -0.01); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1446 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1447 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1448 void test_find_slope_index(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1449 co_aix slope; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1450 int idx; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1451 co_aix r; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1452 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1453 slope = 0.754; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1454 idx = _find_slope_index(slope * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1455 r = (co_aix)slope_tab[idx] / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1456 CU_ASSERT((r / slope) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1457 (r / slope) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1458 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1459 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1460 void test_vector_len(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1461 co_aix x, y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1462 co_aix len; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1463 co_aix r; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1464 int rlen; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1465 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1466 x = 397; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1467 y = 449; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1468 len = sqrt(x * x + y * y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1469 rlen = _vector_len(x * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1470 y * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1471 r = (co_aix)rlen / (1 <<FRACTION_SHIFT); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1472 CU_ASSERT((r / len) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1473 (r / len) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1474 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1475 x = 357; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1476 y = 224; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1477 len = sqrt(x * x + y * y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1478 rlen = _vector_len(x * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1479 y * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1480 r = (co_aix)rlen / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1481 CU_ASSERT((r / len) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1482 (r / len) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1483 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1484 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1485 void test_find_arc_radius(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1486 co_aix ratio; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1487 int idx; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1488 co_aix r; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1489 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1490 ratio = 0.732; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1491 idx = _find_arc_radius(ratio * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1492 r = (co_aix)arc_radius_ratio_tab[idx] / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1493 CU_ASSERT((r / ratio) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1494 (r / ratio) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1495 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1496 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1497 void test_get_arc_radius_shift_factor(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1498 co_aix arc_x, arc_y, radius; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1499 co_aix factor; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1500 int rfactor; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1501 co_aix r; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1502 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1503 arc_x = 30.5; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1504 arc_y = 10.3; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1505 radius = 90.3; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1506 factor = sqrt(radius * radius - (arc_x * arc_x + arc_y * arc_y) / 4) / |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1507 radius; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1508 rfactor = _get_arc_radius_shift_factor(arc_x * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1509 arc_y * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1510 radius * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1511 r = (co_aix)rfactor / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1512 CU_ASSERT((r / factor) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1513 (r / factor) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1514 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1515 arc_x = 30.5; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1516 arc_y = 70.3; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1517 radius = 190.3; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1518 factor = sqrt(radius * radius - (arc_x * arc_x + arc_y * arc_y) / 4) / |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1519 radius; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1520 rfactor = _get_arc_radius_shift_factor(arc_x * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1521 arc_y * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1522 radius * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1523 r = (co_aix)rfactor / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1524 CU_ASSERT((r / factor) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1525 (r / factor) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1526 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1527 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1528 void test_compute_extend_unit_vector(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1529 co_aix rx, ry; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1530 co_aix x_rotate; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1531 co_aix unit_x, unit_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1532 co_aix runit_x, runit_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1533 int64_t ext_unit_x, ext_unit_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1534 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1535 rx = 200; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1536 ry = 153; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1537 x_rotate = PI * 30 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1538 unit_x = cos(PI * 90 / 180 + x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1539 unit_y = sin(PI * 90 / 180 + x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1540 _compute_extend_unit_vector(rx * FRACTION_ONE, ry * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1541 x_rotate * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1542 &ext_unit_x, &ext_unit_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1543 runit_x = (co_aix)ext_unit_x / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1544 runit_y = (co_aix)ext_unit_y / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1545 CU_ASSERT((runit_x / unit_x) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1546 (runit_x / unit_x) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1547 CU_ASSERT((runit_y / unit_y) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1548 (runit_y / unit_y) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1549 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1550 rx = 200; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1551 ry = 153; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1552 x_rotate = PI * 158 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1553 unit_x = cos(PI * 90 / 180 + x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1554 unit_y = sin(PI * 90 / 180 + x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1555 _compute_extend_unit_vector(rx * FRACTION_ONE, ry * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1556 x_rotate * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1557 &ext_unit_x, &ext_unit_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1558 runit_x = (co_aix)ext_unit_x / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1559 runit_y = (co_aix)ext_unit_y / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1560 CU_ASSERT((runit_x / unit_x) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1561 (runit_x / unit_x) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1562 CU_ASSERT((runit_y / unit_y) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1563 (runit_y / unit_y) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1564 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1565 rx = 100; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1566 ry = 153; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1567 x_rotate = PI * 158 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1568 unit_x = cos(x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1569 unit_y = sin(x_rotate); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1570 _compute_extend_unit_vector(rx * FRACTION_ONE, ry * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1571 x_rotate * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1572 &ext_unit_x, &ext_unit_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1573 runit_x = (co_aix)ext_unit_x / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1574 runit_y = (co_aix)ext_unit_y / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1575 CU_ASSERT((runit_x / unit_x) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1576 (runit_x / unit_x) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1577 CU_ASSERT((runit_y / unit_y) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1578 (runit_y / unit_y) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1579 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1580 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1581 void test_get_center_ref_shift(void) { |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1582 co_aix slope; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1583 int slope_index; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1584 co_aix arc_len; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1585 co_aix arc_x, arc_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1586 int large, sweep; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1587 co_aix shift_x, shift_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1588 co_aix r_x, r_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1589 int64_t rshift_x, rshift_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1590 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1591 arc_x = 311; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1592 arc_y = 210; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1593 large = 0; /* small arc */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1594 sweep = 1; /* positive sweep */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1595 arc_len = sqrt(arc_x * arc_x + arc_y * arc_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1596 shift_x = arc_y / arc_len * (1 << REF_RADIUS_SHIFT); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1597 shift_y = arc_x / arc_len * (1 << REF_RADIUS_SHIFT); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1598 if((arc_x < 0) ^ (arc_y < 0)) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1599 /* exactly one of arc_x and arc_y is negative */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1600 shift_y = -shift_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1601 else |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1602 shift_x = -shift_x; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1603 slope = MIN(ABS(arc_x), ABS(arc_y)) / MAX(ABS(arc_x), ABS(arc_y)); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1604 slope_index = _find_slope_index(slope * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1605 _get_center_ref_shift(arc_x * FRACTION_ONE, arc_y * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1606 large, sweep, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1607 slope_index, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1608 &rshift_x, &rshift_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1609 r_x = (co_aix)rshift_x / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1610 r_y = (co_aix)rshift_y / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1611 CU_ASSERT((r_x / shift_x) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1612 (r_x / shift_x) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1613 CU_ASSERT((r_y / shift_y) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1614 (r_y / shift_y) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1615 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1616 arc_x = 311; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1617 arc_y = 210; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1618 large = 1; /* small arc */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1619 sweep = 1; /* positive sweep */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1620 arc_len = sqrt(arc_x * arc_x + arc_y * arc_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1621 shift_x = -arc_y / arc_len * (1 << REF_RADIUS_SHIFT); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1622 shift_y = -arc_x / arc_len * (1 << REF_RADIUS_SHIFT); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1623 if((arc_x < 0) ^ (arc_y < 0)) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1624 /* exactly one of arc_x and arc_y is negative */ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1625 shift_y = -shift_y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1626 else |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1627 shift_x = -shift_x; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1628 slope = MIN(ABS(arc_x), ABS(arc_y)) / MAX(ABS(arc_x), ABS(arc_y)); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1629 slope_index = _find_slope_index(slope * FRACTION_ONE); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1630 _get_center_ref_shift(arc_x * FRACTION_ONE, arc_y * FRACTION_ONE, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1631 large, sweep, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1632 slope_index, |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1633 &rshift_x, &rshift_y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1634 r_x = (co_aix)rshift_x / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1635 r_y = (co_aix)rshift_y / FRACTION_ONE; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1636 CU_ASSERT((r_x / shift_x) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1637 (r_x / shift_x) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1638 CU_ASSERT((r_y / shift_y) < 1.01 && |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1639 (r_y / shift_y) > 0.99); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1640 } |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1641 |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
1642 void test_calc_center(void) { |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1643 co_aix x0, y0, x, y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1644 co_aix rx, ry, x_rotate; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1645 int large, sweep; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1646 co_aix cx, cy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1647 co_aix angle_start, angle_stop; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1648 co_aix rcx, rcy; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1649 co_aix _x, _y; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1650 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1651 #define ELLIPSE_POINT(angle, point_x, point_y) \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1652 do { \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1653 _x = rx * cos(angle); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1654 _y = ry * sin(angle); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1655 point_x = _x * cos(x_rotate) - _y * sin(x_rotate) + cx; \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1656 point_y = _x * sin(x_rotate) + _y * cos(x_rotate) + cy; \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1657 } while(0) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1658 #define CENTER_TEST() \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1659 do { \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1660 _calc_center(x0, y0, x, y, rx, ry, x_rotate, \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1661 0, 1, &rcx, &rcy); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1662 CU_ASSERT((cx - rcx) <= 2 && (cx - rcx) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1663 CU_ASSERT((cy - rcy) <= 2 && (cy - rcy) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1664 _calc_center(x0, y0, x, y, rx, ry, x_rotate, \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1665 1, 0, &rcx, &rcy); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1666 CU_ASSERT((cx - rcx) <= 2 && (cx - rcx) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1667 CU_ASSERT((cy - rcy) <= 2 && (cy - rcy) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1668 _calc_center(x, y, x0, y0, rx, ry, x_rotate, \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1669 0, 0, &rcx, &rcy); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1670 CU_ASSERT((cx - rcx) <= 2 && (cx - rcx) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1671 CU_ASSERT((cy - rcy) <= 2 && (cy - rcy) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1672 _calc_center(x, y, x0, y0, rx, ry, x_rotate, \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1673 1, 1, &rcx, &rcy); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1674 CU_ASSERT((cx - rcx) <= 2 && (cx - rcx) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1675 CU_ASSERT((cy - rcy) <= 2 && (cy - rcy) >= -2); \ |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1676 } while(0) |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1677 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1678 cx = 135; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1679 cy = 254; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1680 rx = 200; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1681 ry = 170; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1682 x_rotate = PI * 20 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1683 angle_start = PI * 55 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1684 angle_stop = PI * 97 / 180; |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1685 |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1686 ELLIPSE_POINT(angle_start, x0, y0); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1687 ELLIPSE_POINT(angle_stop, x, y); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1688 CENTER_TEST(); |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
1689 } |
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
1690 |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1691 void test_spaces_head_tail(void) { |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1692 sh_path_t *path; |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1693 redraw_man_t rdman; |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1694 |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1695 path = (sh_path_t *) |
865
48df0f97f09e
Allocate sh_path_t objects from an elmpool
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
1696 rdman_shape_path_new(&rdman, |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
149
diff
changeset
|
1697 " M 33 25l33 55C 33 87 44 22 55 99L33 77z "); |
11
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1698 CU_ASSERT(path != NULL); |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1699 sh_path_free((shape_t *)path); |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1700 } |
128af06c876c
Fix the bug that data of a path end with white spaces would make system down
Thinker K.F. Li <thinker@branda.to>
parents:
10
diff
changeset
|
1701 |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1702 CU_pSuite get_shape_path_suite(void) { |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1703 CU_pSuite suite; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1704 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1705 suite = CU_add_suite("Suite_shape_path", NULL, NULL); |
159
b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
Thinker K.F. Li <thinker@branda.to>
parents:
149
diff
changeset
|
1706 CU_ADD_TEST(suite, test_rdman_shape_path_new); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1707 CU_ADD_TEST(suite, test_path_transform); |
1134
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1708 CU_ADD_TEST(suite, test_small_slope); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1709 CU_ADD_TEST(suite, test_find_slope_index); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1710 CU_ADD_TEST(suite, test_vector_len); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1711 CU_ADD_TEST(suite, test_find_arc_radius); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1712 CU_ADD_TEST(suite, test_get_arc_radius_shift_factor); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1713 CU_ADD_TEST(suite, test_compute_extend_unit_vector); |
bd0cfb8666b8
Pass testcases for _calc_center() of shape_path.c.
Thinker K.F. Li <thinker@codemud.net>
parents:
1129
diff
changeset
|
1714 CU_ADD_TEST(suite, test_get_center_ref_shift); |
1129
eca737d33a18
Improve performance of function to compute center of an arc.
Thinker K.F. Li <thinker@codemud.net>
parents:
1062
diff
changeset
|
1715 CU_ADD_TEST(suite, test_calc_center); |
5
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1716 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1717 return suite; |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1718 } |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1719 |
9c331ec9e210
SVG path is partially supported
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1720 #endif /* UNITTEST */ |