X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsupport%2Fxform.cpp;h=cf35c4c9872bf2b2a168e58e4b5a49d3c4895b1c;hp=8d58f766a4dfdcbbb0e19b48aeffe9fde4de7964;hb=f13a8c004b8f182b42d9e4df2bcd7c7f030bf1ad;hpb=99dd1d6ed10db1f669a5fe6af71225a50fc0ddfb diff --git a/libctsupport/xform.cpp b/libctsupport/xform.cpp index 8d58f76..cf35c4c 100644 --- a/libctsupport/xform.cpp +++ b/libctsupport/xform.cpp @@ -1,8 +1,6 @@ /***************************************************************************** ** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: xform.cpp,v 1.1 2000/06/19 02:58:08 kevin Exp $ +** Copyright (c) 1983-2009 Kevin Rosenberg ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -18,19 +16,20 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#include "kmath.h" +#include "ctsupport.h" + /* NAME - * rotate2d Rotates an array of 2 dimensional vectors + * rotate2d Rotates an array of 2 dimensional vectors * * SYNOPSIS * rotate2d (x, y, n, angle) - * double x[], y[] Array of points - * int n Number of points in array - * double angle Rotation angle (counter-clockwise) + * double x[], y[] Array of points + * int n Number of points in array + * double angle Rotation angle (counter-clockwise) */ -void +void rotate2d (double x[], double y[], int n, double angle) { double cos_theta = cos (angle); @@ -46,16 +45,16 @@ rotate2d (double x[], double y[], int n, double angle) /* NAME - * xlat2d Translates an array of 2 dimensional vectors + * xlat2d Translates an array of 2 dimensional vectors * * SYNOPSIS * xlat2d (x, y, n, xoffset, yoffset) - * double x[], y[] Array of points - * int n Number of points in array - * double xoffset, yoffset Offset to translate points by + * double x[], y[] Array of points + * int n Number of points in array + * double xoffset, yoffset Offset to translate points by */ -void +void xlat2d (double x[], double y[], int n, double xoffset, double yoffset) { for (int i = 0; i < n; i++) { @@ -66,16 +65,16 @@ xlat2d (double x[], double y[], int n, double xoffset, double yoffset) /* NAME - * scale2d Scale an array of 2 dimensional vectors + * scale2d Scale an array of 2 dimensional vectors * * SYNOPSIS * scale2d (x, y, n, xoffset, yoffset) - * double x[], y[] Array of points - * int n Number of points in array - * double xfact, yfact x & y scaling factors + * double x[], y[] Array of points + * int n Number of points in array + * double xfact, yfact x & y scaling factors */ -void +void scale2d (double x[], double y[], int n, double xfact, double yfact) { for (int i = 0; i < n; i++) { @@ -85,7 +84,7 @@ scale2d (double x[], double y[], int n, double xfact, double yfact) } -void +void indent_mtx2 (GRFMTX_2D m) { m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; @@ -93,7 +92,7 @@ indent_mtx2 (GRFMTX_2D m) m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; } -void +void xlat_mtx2 (GRFMTX_2D m, const double x, const double y) { indent_mtx2 (m); @@ -101,7 +100,7 @@ xlat_mtx2 (GRFMTX_2D m, const double x, const double y) m[2][1] = y; } -void +void scale_mtx2 (GRFMTX_2D m, const double sx, const double sy) { indent_mtx2 (m); @@ -109,7 +108,7 @@ scale_mtx2 (GRFMTX_2D m, const double sx, const double sy) m[1][1] = sy; } -void +void rot_mtx2 (GRFMTX_2D m, const double theta) { double c = cos(theta); @@ -120,25 +119,26 @@ rot_mtx2 (GRFMTX_2D m, const double theta) m[1][0] = -s; m[1][1] = c; } -void -mult_mtx2 (GRFMTX_2D m1, GRFMTX_2D m2, GRFMTX_2D result) +void +mult_mtx2 (const GRFMTX_2D m1, const GRFMTX_2D m2, GRFMTX_2D result) { GRFMTX_2D temp; - for (int row = 0; row < 3; row++) + for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { temp[row][col] = 0; for (int calc = 0; calc < 3; calc++) - temp[row][col] += m1[row][calc] * m2[calc][col]; + temp[row][col] += m1[row][calc] * m2[calc][col]; } + } - for (int row = 0; row < 3; row++) + for (int r = 0; r < 3; r++) for (int col = 0; col < 3; col++) - result[row][col] = temp[row][col]; + result[r][col] = temp[r][col]; } -void -xform_mtx2 (GRFMTX_2D m, double& x, double& y) +void +xform_mtx2 (const GRFMTX_2D m, double& x, double& y) { double xt = x * m[0][0] + y * m[1][0] + m[2][0]; double yt = x * m[0][1] + y * m[1][1] + m[2][1];