Mercurial > MadButterfly
comparison src/shape_path.c @ 100:1a1dda98730c
Fix the bug of order of cross & inner product of vectors
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 10 Sep 2008 10:02:31 +0800 |
parents | 4aa1c9673363 |
children | d6f9af55b0d0 |
comparison
equal
deleted
inserted
replaced
99:4aa1c9673363 | 100:1a1dda98730c |
---|---|
56 * - udcx = ucx - umx | 56 * - udcx = ucx - umx |
57 * - udcy = ucy - umy | 57 * - udcy = ucy - umy |
58 * - udx = ux - umx | 58 * - udx = ux - umx |
59 * - udy = uy - umy | 59 * - udy = uy - umy |
60 * | 60 * |
61 * - udcx * udx + udcy * udy = 0 | 61 * - udx * udcx + udy * udcy = 0 |
62 * | 62 * |
63 * - udl2 = udx ** 2 + udy ** 2; | 63 * - udl2 = udx ** 2 + udy ** 2; |
64 * - udcx * udy - udcy * udx = sqrt((1 - udl2) * udl2) | 64 * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2) |
65 * | 65 * |
66 * - udcy = -udcx * udx / udy | 66 * - udcy = -udcx * udx / udy |
67 * - udcx * udy + udcx * (udx ** 2) / udy = sqrt((1 - udl2) * udl2) | 67 * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2) |
68 * - udcx * (udy + (udx ** 2) / udy) = sqrt((1 - udl2) * udl2) | 68 * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2) |
69 * - udcx = sqrt((1 - udl2) * udl2) / (udy + (udx ** 2) / udy) | 69 * - udcx = -sqrt((1 - udl2) * udl2) / ((udx ** 2) / udy + udy) |
70 * or | 70 * or |
71 * - udcx = -udcy * udy / udx | 71 * - udcx = -udcy * udy / udx |
72 * - -udcy * (udy ** 2) / udx - udcy * udx = sqrt((1 - udl2) * udl2) | 72 * - udx * udcy + udcy * (udy ** 2) / udx = sqrt((1 - udl2) * udl2) |
73 * - -udcy * ((udy ** 2) / udx + udx) = sqrt((1 - udl2) * udl2) | 73 * - udcy * (udx + (udy ** 2) / udx) = sqrt((1 - udl2) * udl2) |
74 * - udcy = -sqrt((1 - udl2) * udl2) / ((udy ** 2) / udx + udx) | 74 * - udcy = sqrt((1 - udl2) * udl2) / (udx + (udy ** 2) / udx) |
75 * | 75 * |
76 * - cx = rx * ucx | 76 * - cx = rx * ucx |
77 * - cx = rx * (udcx + umx) | 77 * - cx = rx * (udcx + umx) |
78 * - cy = ry * ucy | 78 * - cy = ry * ucy |
79 * - cy = ry * (udcy + umy) | 79 * - cy = ry * (udcy + umy) |
108 udx2 = udx * udx; | 108 udx2 = udx * udx; |
109 udy2 = udy * udy; | 109 udy2 = udy * udy; |
110 udl2 = udx2 + udy2; | 110 udl2 = udx2 + udy2; |
111 | 111 |
112 if(udy != 0) { | 112 if(udy != 0) { |
113 udcx = sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); | 113 udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); |
114 udcy = - udcx * udx / udy; | 114 udcy = -udcx * udx / udy; |
115 } else { | 115 } else { |
116 udcx = 0; | 116 udcx = 0; |
117 udcy = -sqrtf((1 - udl2) * udl2) / udx; | 117 udcy = sqrtf((1 - udl2) * udl2) / udx; |
118 } | 118 } |
119 | 119 |
120 reflect = 0; | 120 reflect = 0; |
121 if(large) | 121 if(large) |
122 reflect ^= 1; | 122 reflect ^= 1; |
214 } | 214 } |
215 | 215 |
216 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) | 216 #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) |
217 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) | 217 #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) |
218 | 218 |
219 /*! \brief Make path for arcs in a path. | |
220 */ | |
219 void sh_path_arc_path(cairo_t *cr, const co_aix **args_p, | 221 void sh_path_arc_path(cairo_t *cr, const co_aix **args_p, |
220 const int **fix_args_p) { | 222 const int **fix_args_p) { |
221 co_aix cx, cy, x0, y0, x, y, xx, xy; | 223 co_aix cx, cy, x0, y0, x, y, xx, xy; |
222 co_aix dx, dy, dx0, dy0, dxx, dxy; | 224 co_aix dx, dy, dx0, dy0, dxx, dxy; |
223 co_aix xyratio; | 225 co_aix xyratio; |
255 /*! \note Why we calculate these numbers there? | 257 /*! \note Why we calculate these numbers there? |
256 * If we compute it when filling arguments, sh_path_arc_cmd_arg_fill(), | 258 * If we compute it when filling arguments, sh_path_arc_cmd_arg_fill(), |
257 * we can avoid to recompute it for every drawing. But, transforming of | 259 * we can avoid to recompute it for every drawing. But, transforming of |
258 * coordinate can effect value of the numbers. | 260 * coordinate can effect value of the numbers. |
259 */ | 261 */ |
260 inner0 = INNER(dx0, dy0, dxx, dxy); | 262 inner0 = INNER(dxx, dxy, dx0, dy0); |
261 cross0 = CROSS(dx0, dy0, dxx, dxy); | 263 cross0 = CROSS(dxx, dxy, dx0, dy0); |
262 circle_h0 = sqrtf(rx2 - inner0 * inner0 / rx2); | 264 circle_h0 = sqrtf(rx2 - inner0 * inner0 / rx2); |
263 xyratio = cross0 / rx / circle_h0; | 265 xyratio = cross0 / rx / circle_h0; |
264 if(xyratio < 0) | 266 if(xyratio < 0) |
265 xyratio = -xyratio; | 267 xyratio = -xyratio; |
266 | 268 |
267 angle0 = acos(inner0 / rx2); | 269 angle0 = acos(inner0 / rx2); |
268 if(cross0 < 0) | 270 if(cross0 < 0) |
269 angle0 = PI * 2 - angle0; /* 3rd, 4th Quadrant */ | 271 angle0 = PI * 2 - angle0; /* 3rd, 4th Quadrant */ |
270 | 272 |
271 inner = INNER(dx, dy, dxx, dxy); | 273 inner = INNER(dxx, dxy, dx, dy); |
272 cross = CROSS(dx, dy, dxx, dxy); | 274 cross = CROSS(dxx, dxy, dx, dy); |
273 angle = acos(inner / rx2); | 275 angle = acos(inner / rx2); |
274 if(cross < 0) | 276 if(cross < 0) |
275 angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ | 277 angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ |
276 | 278 |
277 /* Make a path for arc */ | 279 /* Make a path for arc */ |
700 free(path->user_data); | 702 free(path->user_data); |
701 free(path->dev_data); | 703 free(path->dev_data); |
702 free(path); | 704 free(path); |
703 return NULL; | 705 return NULL; |
704 } | 706 } |
705 memcpy(path->dev_data, path->user_data, cmd_cnt); | 707 memcpy(path->dev_data, path->user_data, msz); |
706 | 708 |
707 path->shape.free = sh_path_free; | 709 path->shape.free = sh_path_free; |
708 | 710 |
709 return (shape_t *)path; | 711 return (shape_t *)path; |
710 } | 712 } |