home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / libgimp / gimpmath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-06  |  2.6 KB  |  101 lines

  1. /* LIBGIMP - The GIMP Library 
  2.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
  3.  *
  4.  * gimpmath.h
  5.  *
  6.  * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball                
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Lesser General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Lesser General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Lesser General Public
  19.  * License along with this library; if not, write to the
  20.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21.  * Boston, MA 02111-1307, USA.
  22.  */
  23.  
  24. #ifndef __GIMPMATH_H__
  25. #define __GIMPMATH_H__
  26.  
  27. #include <math.h>
  28.  
  29. #ifdef G_OS_WIN32
  30. #include <float.h>
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif /* __cplusplus */
  36.  
  37.  
  38. /* Some portability enhancing stuff. For use both by the gimp app
  39.  * as well as plug-ins and modules.
  40.  *
  41.  * Include this instead of just <math.h>.
  42.  */
  43.  
  44. #ifndef G_PI            /* G_PI will be in GLib eventually */
  45. #define G_PI    3.14159265358979323846
  46. #endif
  47. #ifndef G_PI_2            /* As will G_PI_2 */
  48. #define G_PI_2  1.57079632679489661923
  49. #endif
  50. #ifndef G_PI_4            /* As will G_PI_4 */
  51. #define G_PI_4  0.78539816339744830962
  52. #endif
  53. #ifndef G_SQRT2            /* As will G_SQRT2 */
  54. #define G_SQRT2 1.4142135623730951
  55. #endif
  56.  
  57. #ifndef RAND_MAX
  58. #define G_MAXRAND G_MAXINT
  59. #else
  60. #define G_MAXRAND RAND_MAX
  61. #endif
  62.  
  63. /* Use RINT() instead of rint() */
  64. #ifdef HAVE_RINT
  65. #define RINT(x) rint(x)
  66. #else
  67. #define RINT(x) floor ((x) + 0.5)
  68. #endif
  69.  
  70. #define ROUND(x) ((int) ((x) + 0.5))
  71.  
  72. /* Square */
  73. #define SQR(x) ((x) * (x))
  74.  
  75. /* limit a (0->511) int to 255 */
  76. #define MAX255(a)  ((a) | (((a) & 256) - (((a) & 256) >> 8)))
  77.  
  78. /* clamp a >>int32<<-range int between 0 and 255 inclusive */
  79. /* broken! -> #define CLAMP0255(a)  ((a & 0xFFFFFF00)? (~(a>>31)) : a) */
  80. #define CLAMP0255(a)  CLAMP(a,0,255)
  81.  
  82. #define gimp_deg_to_rad(angle) ((angle) * (2.0 * G_PI) / 360.0)
  83. #define gimp_rad_to_deg(angle) ((angle) * 360.0 / (2.0 * G_PI))
  84.  
  85. #ifdef G_OS_WIN32
  86. #define FINITE(x) _finite(x)
  87. #else
  88. #ifdef __EMX__
  89. #define FINITE(x) isfinite(x)
  90. #else
  91. #define FINITE(x) finite(x) 
  92. #endif
  93. #endif
  94.  
  95.  
  96. #ifdef __cplusplus
  97. }
  98. #endif /* __cplusplus */
  99.  
  100. #endif /* __GIMPMATH_H__ */
  101.