comparison src/shape_path.c @ 269:c96f38ad4bb6

Fix mis-behavior of translate_path_data() on arc. - Arc in a path in svg2code_ex is not showed. - translate_path_data() in svg2code.py was modified for calling binary version new method for path shape. - rdman_shape_path_new_from_binary() - Code to translate path data does not handle arc in a right way. - Copy calc_center_and_x_aix() from shape_path.c to svg2code.py and change name _calc_ellipse_of_arc() - _calc_ellipse_of_arc() handle arc data for translate_path_data()
author Thinker K.F. Li <thinker@branda.to>
date Sun, 25 Jan 2009 00:20:34 +0800
parents 65cabbdd5284
children cd6af7da32c9
comparison
equal deleted inserted replaced
268:43900cae1d49 269:c96f38ad4bb6
51 * Implement arc in path. 51 * Implement arc in path.
52 */ 52 */
53 #include <math.h> 53 #include <math.h>
54 /*! \brief Calculate center of the ellipse of an arc. 54 /*! \brief Calculate center of the ellipse of an arc.
55 * 55 *
56 * Origin of our coordination is left-top corner, and y-axis are grown
57 * to down-side.
58 *
59 * Space of the arc is transformed to space that correspondent
60 * ellipse containing the arc is mapped into an unit circle.
56 * - ux0 = x0 / rx 61 * - ux0 = x0 / rx
57 * - uy0 = y0 / ry 62 * - uy0 = y0 / ry
58 * - ux = x / rx 63 * - ux = x / rx
59 * - uy = y / rx 64 * - uy = y / ry
60 * ux0, uy0, ux, yu are got by transforming (x0, y0) and (x, y) into points 65 * ux0, uy0, ux, uy are got by transforming (x0, y0) and (x, y) into points
61 * on the unit circle. The center of unit circle are (ucx, ucy): 66 * on the unit circle. The center of unit circle are (ucx, ucy):
62 * - umx = (ux0 + ux) / 2 67 * - umx = (ux0 + ux) / 2
63 * - umy = (uy0 + uy) / 2 68 * - umy = (uy0 + uy) / 2
64 * - udcx = ucx - umx 69 * - udcx = ucx - umx
65 * - udcy = ucy - umy 70 * - udcy = ucy - umy
66 * - udx = ux - umx 71 * - udx = ux - umx
67 * - udy = uy - umy 72 * - udy = uy - umy
68 * 73 *
69 * - udx * udcx + udy * udcy = 0 74 * - udx * udcx + udy * udcy = 0
70 * 75 *
71 * - udl2 = udx ** 2 + udy ** 2; 76 * - udl2 = udx ** 2 + udy ** 2
77 *
78 * For drawing small arc in clockwise
72 * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2) 79 * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2)
73 * 80 *
74 * - udcy = -udcx * udx / udy 81 * - udcy = -udcx * udx / udy
75 * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2) 82 * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2)
76 * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2) 83 * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2)
116 udx2 = udx * udx; 123 udx2 = udx * udx;
117 udy2 = udy * udy; 124 udy2 = udy * udy;
118 udl2 = udx2 + udy2; 125 udl2 = udx2 + udy2;
119 126
120 if(udy != 0) { 127 if(udy != 0) {
128 /* center is at left-side of arc */
121 udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); 129 udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy);
122 udcy = -udcx * udx / udy; 130 udcy = -udcx * udx / udy;
123 } else { 131 } else {
132 /* center is at down-side of arc */
124 udcx = 0; 133 udcx = 0;
125 udcy = sqrtf((1 - udl2) * udl2) / udx; 134 udcy = sqrtf((1 - udl2) * udl2) / udx;
126 } 135 }
127 136
128 reflect = 0; 137 reflect = 0;