X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fkmath.h;h=bb30f05d683f8caf073e37e742ef6bb5c706ed8f;hp=ed8de01fa6be368efaa356c652e06e6577a3697d;hb=f4a23943110823118f35756dd41fbd6707f04511;hpb=2451ac413848718a1dd666ce6f6464e974680f47 diff --git a/include/kmath.h b/include/kmath.h index ed8de01..bb30f05 100644 --- a/include/kmath.h +++ b/include/kmath.h @@ -1,36 +1,15 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: kmath.h,v 1.11 2000/06/09 01:35:33 kevin Exp $ -** $Log: kmath.h,v $ -** Revision 1.11 2000/06/09 01:35:33 kevin -** Convert MPI structure to C++ class -** -** Revision 1.10 2000/06/07 00:59:38 kevin -** added imagefiles -** -** Revision 1.9 2000/05/08 20:00:48 kevin -** ANSI C changes -** -** Revision 1.8 2000/05/07 12:46:19 kevin -** made c++ compatible -** -** Revision 1.7 2000/05/04 18:16:34 kevin -** renamed filter definitions +** FILE IDENTIFICATION ** -** Revision 1.6 2000/05/02 20:00:25 kevin -** *** empty log message *** +** Name: kmath.h +** Purpose: Header file containing definitions for numerical app +** Programmer: Kevin Rosenberg +** Date Started: Nov 84 ** -** Revision 1.5 2000/05/02 15:31:39 kevin -** code cleaning -** -** Revision 1.4 2000/04/30 19:17:35 kevin -** Set up include files for conditional INTERACTIVE_GRAPHICS -** -** Revision 1.3 2000/04/28 14:14:16 kevin -** *** empty log message *** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg ** +** $Id: kmath.h,v 1.14 2000/06/17 20:12:14 kevin Exp $ ** ** 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 @@ -45,13 +24,6 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/****************************************************************************** - * - * PURPOSE - * Header file containing definitions for numerical app's - * Date Started: Nov 84 - * - *****************************************************************************/ #ifndef _H_kmath #define _H_kmath @@ -59,10 +31,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - #define PI 3.14159265358979323846 #define HALFPI 1.57079632679489661923 /* PI divided by 2 */ #define QUARTPI 0.78539816339744830962 /* PI divided by 4 */ @@ -75,36 +43,42 @@ extern "C" { #define F_EPSILON 1.0E-6 #define D_EPSILON 1.0E-10 -#define DEG_TO_RAD(x) (x*(PI/180.)) -#define RAD_TO_DEG(x) (x*(180./PI)) - - #define ASSUMEDZERO 1E-10 typedef double GRFMTX_2D[3][3]; typedef double GRFMTX_3D[4][4]; -/* clip.c */ +inline double +convertDegreesToRadians (double x) +{ return (x * (PI/180.)); } + +inline double +convertRadiansToDegrees (double x) +{ return (x*(180./PI)); } + +template +inline T nearest (double x) +{ return (x > 0 ? static_cast(x+0.5) : static_cast(x-0.5)); } + +template +inline T clamp (T value, T lowerBounds, T upperBounds) +{ return (value >= upperBounds ? upperBounds : (value <= lowerBounds ? lowerBounds : value )); } + +template +inline T lineLength (T x1, T y1, T x2, T y2) +{ return static_cast( sqrt ((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)) ); } + +/* clip.cpp */ int clip_rect(double *x1, double *y1, double *x2, double *y2, const double rect[4]); int clip_segment(double *x1, double *y1, double *x2, double *y2, const double u, const double v); int clip_sector(double *x1, double *y1, double *x2, double *y2, const double u, const double v); int clip_circle(double *x1, double *y1, double *x2, double *y2, const double cx, const double cy, const double radius, double t1, double t2); int clip_triangle(double *x1, double *y1, double *x2, double *y2, const double u, const double v, const int clip_xaxis); -/* lnearest.c */ -long int lnearest(double x); - -/* minmax.c */ -double fmax(const double a, const double b); -void minmax_dvector(const double array[], const int pts, double *xmin, double *xmax); - -/* norm_ang.c */ +/* norm_ang.cpp */ double norm_ang(double theta); -/* simpson.c */ -double simpson(const double xmin, const double xmax, const double *y, const int np); - -/* xform.c */ +/* xform.cpp */ void indent_mtx2(GRFMTX_2D m); void xlat_mtx2(GRFMTX_2D m, const double x, const double y); void scale_mtx2(GRFMTX_2D m, const double sx, const double sy); @@ -115,8 +89,11 @@ void rotate2d(double x[], double y[], int pts, double angle); void xlat2d(double x[], double y[], int pts, double xoffset, double yoffset); void scale2d(double x[], double y[], int pts, double xfact, double yfact); -#ifdef __cplusplus -} -#endif /* __cplusplus */ +/* simpson.cpp */ +double simpson(const double xmin, const double xmax, const double *y, const int np); + +/* minmax.cpp */ +void minmax_dvector(const double array[], const int pts, double *xmin, double *xmax); + #endif