2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 void Math::limitChar(signed char *in, int low, int high)
31 void Math::limitChar(unsigned char *in, int low, int high)
39 void Math::limitInt(int *in, int low, int high)
47 void Math::limitFloat(float *in, float low, float high)
55 void Math::wrapChar(signed char *in, signed char low, signed char high)
63 void Math::wrapInt(int *in, int low, int high)
71 void Math::wrapFloat(float *in, float low, float high)
85 ix = 16807 * (ix - k1 * 127773) - k1 * 2836;
97 long Math::rrand(int min, int max)
103 if ((max - min) == 0)
108 return r += prand() % (max - min);
111 void Math::addBit(long *currentBits, long newBits)
113 if (!(*currentBits & newBits))
114 *currentBits += newBits;
117 void Math::removeBit(long *currentBits, long oldBits)
119 if (*currentBits & oldBits)
120 *currentBits -= oldBits;
123 void Math::calculateSlope(float x, float y, float x2, float y2, float *dx, float *dy)
125 int steps = (int)max(fabs(x - x2), fabs(y - y2));
139 char *Math::formatTime(int t)
141 static char time[1024];
145 int hours = t / 3600;
146 int minutes = (t % 3600) / 60;
147 int seconds = (t % 60);
149 snprintf(time, sizeof time, "%dh %dm %ds", hours, minutes, seconds);