Mercurial > MadButterfly
changeset 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 |
files | examples/svg2code_ex/svg2code_ex.svg src/shape_path.c tools/mb_c_header.m4 tools/mb_c_source.m4 |
diffstat | 4 files changed, 38 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/svg2code_ex/svg2code_ex.svg Tue Sep 09 22:17:17 2008 +0800 +++ b/examples/svg2code_ex/svg2code_ex.svg Wed Sep 10 10:02:31 2008 +0800 @@ -448,15 +448,16 @@ </g> <path sodipodi:type="arc" - style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:2.39700006999999982;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" + style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:2.39700007;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" id="path2451" sodipodi:cx="648.28497" sodipodi:cy="541.4248" sodipodi:rx="98.944588" - sodipodi:ry="47.493404" - d="M 747.22956,541.4248 A 98.944588,47.493404 0 0 1 549.36227,542.42361" - sodipodi:start="0" - sodipodi:end="3.1205606" - sodipodi:open="true" /> + sodipodi:ry="37.994728" + d="M 723.62808,516.79651 A 98.944588,37.994728 0 1 1 549.36227,542.22385" + sodipodi:start="5.5779634" + sodipodi:end="9.4037459" + sodipodi:open="true" + transform="translate(0,-17.414248)" /> </g> </svg>
--- a/src/shape_path.c Tue Sep 09 22:17:17 2008 +0800 +++ b/src/shape_path.c Wed Sep 10 10:02:31 2008 +0800 @@ -58,20 +58,20 @@ * - udx = ux - umx * - udy = uy - umy * - * - udcx * udx + udcy * udy = 0 + * - udx * udcx + udy * udcy = 0 * * - udl2 = udx ** 2 + udy ** 2; - * - udcx * udy - udcy * udx = sqrt((1 - udl2) * udl2) + * - udx * udcy - udy * udcx = sqrt((1 - udl2) * udl2) * * - udcy = -udcx * udx / udy - * - udcx * udy + udcx * (udx ** 2) / udy = sqrt((1 - udl2) * udl2) - * - udcx * (udy + (udx ** 2) / udy) = sqrt((1 - udl2) * udl2) - * - udcx = sqrt((1 - udl2) * udl2) / (udy + (udx ** 2) / udy) + * - -udcx * (udx ** 2) / udy - udy * udcx = sqrt((1 - udl2) * udl2) + * - -udcx * ((udx ** 2) / udy + udy) = sqrt((1 - udl2) * udl2) + * - udcx = -sqrt((1 - udl2) * udl2) / ((udx ** 2) / udy + udy) * or * - udcx = -udcy * udy / udx - * - -udcy * (udy ** 2) / udx - udcy * udx = sqrt((1 - udl2) * udl2) - * - -udcy * ((udy ** 2) / udx + udx) = sqrt((1 - udl2) * udl2) - * - udcy = -sqrt((1 - udl2) * udl2) / ((udy ** 2) / udx + udx) + * - udx * udcy + udcy * (udy ** 2) / udx = sqrt((1 - udl2) * udl2) + * - udcy * (udx + (udy ** 2) / udx) = sqrt((1 - udl2) * udl2) + * - udcy = sqrt((1 - udl2) * udl2) / (udx + (udy ** 2) / udx) * * - cx = rx * ucx * - cx = rx * (udcx + umx) @@ -110,11 +110,11 @@ udl2 = udx2 + udy2; if(udy != 0) { - udcx = sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); - udcy = - udcx * udx / udy; + udcx = -sqrtf((1 - udl2) * udl2) / (udy + udx2 / udy); + udcy = -udcx * udx / udy; } else { udcx = 0; - udcy = -sqrtf((1 - udl2) * udl2) / udx; + udcy = sqrtf((1 - udl2) * udl2) / udx; } reflect = 0; @@ -216,6 +216,8 @@ #define INNER(x1, y1, x2, y2) ((x1) * (x2) + (y1) * (y2)) #define CROSS(x1, y1, x2, y2) ((x1) * (y2) - (y1) * (x2)) +/*! \brief Make path for arcs in a path. + */ void sh_path_arc_path(cairo_t *cr, const co_aix **args_p, const int **fix_args_p) { co_aix cx, cy, x0, y0, x, y, xx, xy; @@ -257,8 +259,8 @@ * we can avoid to recompute it for every drawing. But, transforming of * coordinate can effect value of the numbers. */ - inner0 = INNER(dx0, dy0, dxx, dxy); - cross0 = CROSS(dx0, dy0, dxx, dxy); + inner0 = INNER(dxx, dxy, dx0, dy0); + cross0 = CROSS(dxx, dxy, dx0, dy0); circle_h0 = sqrtf(rx2 - inner0 * inner0 / rx2); xyratio = cross0 / rx / circle_h0; if(xyratio < 0) @@ -268,8 +270,8 @@ if(cross0 < 0) angle0 = PI * 2 - angle0; /* 3rd, 4th Quadrant */ - inner = INNER(dx, dy, dxx, dxy); - cross = CROSS(dx, dy, dxx, dxy); + inner = INNER(dxx, dxy, dx, dy); + cross = CROSS(dxx, dxy, dx, dy); angle = acos(inner / rx2); if(cross < 0) angle = PI * 2 - angle; /* 3rd, 4th Quadrant */ @@ -702,7 +704,7 @@ free(path); return NULL; } - memcpy(path->dev_data, path->user_data, cmd_cnt); + memcpy(path->dev_data, path->user_data, msz); path->shape.free = sh_path_free;
--- a/tools/mb_c_header.m4 Tue Sep 09 22:17:17 2008 +0800 +++ b/tools/mb_c_header.m4 Wed Sep 10 10:02:31 2008 +0800 @@ -38,6 +38,7 @@ define([RECT_HIDE],) define([COORD_TRANSLATE],) define([COORD_MATRIX],) +define([SHAPE_TRANSLATE],) define([SHAPE_MATRIX],) define([MADBUTTERFLY],[dnl
--- a/tools/mb_c_source.m4 Tue Sep 09 22:17:17 2008 +0800 +++ b/tools/mb_c_source.m4 Wed Sep 10 10:02:31 2008 +0800 @@ -48,6 +48,7 @@ define([PATH_HIDE],) define([COORD_TRANSLATE],) define([COORD_MATRIX],) +define([SHAPE_TRANSLATE],) define([SHAPE_MATRIX],) divert[]]) @@ -155,6 +156,15 @@ rdman_coord_changed(rdman, obj->$1); ]]) +define([S_SHAPE_TRANSLATE],[dnl +[ memset(obj->$1->matrix, 0, sizeof(obj->$1->matrix)); + obj->$1->matrix[0] = 1; + obj->$1->matrix[2] = $2; + obj->$1->matrix[4] = 1; + obj->$1->matrix[5] = $3; + rdman_coord_changed(rdman, obj->$1); +]]) + define([S_SHAPE_MATRIX],[dnl [ obj->$1->matrix[0] = $2; obj->$1->matrix[3] = $3; @@ -186,6 +196,7 @@ SIMPORT([PATH_HIDE]) SIMPORT([COORD_TRANSLATE]) SIMPORT([COORD_MATRIX]) +SIMPORT([SHAPE_TRANSLATE]) SIMPORT([SHAPE_MATRIX]) divert[]]) @@ -242,6 +253,7 @@ define([PATH_HIDE],) define([COORD_TRANSLATE],) define([COORD_MATRIX],) +define([SHAPE_TRANSLATE],) define([SHAPE_MATRIX],) divert[]])