1 /* 2 * common.h 3 * 4 * Copyright (C) 1989, 1991, Craig E. Kolb 5 * All rights reserved. 6 * 7 * This software may be freely copied, modified, and redistributed 8 * provided that this copyright notice is preserved on all copies. 9 * 10 * You may not distribute this software, in whole or in part, as part of 11 * any commercial product without the express consent of the authors. 12 * 13 * There is no warranty or other guarantee of fitness of this software 14 * for any purpose. It is provided solely "as is". 15 * 16 * $Id: common.h,v 4.0.1.1 91/11/26 21:34:27 cek Exp Locker: cek $ 17 * 18 * $Log: common.h,v $ 19 * Revision 4.0.1.1 91/11/26 21:34:27 cek 20 * patch3: Added EPSILON definition, redefine equal() macro. 21 * 22 * Revision 4.0 91/07/17 14:30:18 kolb 23 * Initial version. 24 * 25 */ 26 #ifndef COMMON_H 27 #define COMMON_H 28 29 #include <stdio.h> 30 #include <math.h> 31 #ifdef I_STDLIB 32 #include <stdlib.h> 33 #endif 34 #include "config.h" 35 36 typedef double Float; 37 38 #if (VOIDFLAGS & 8) == 8 39 typedef void * voidstar; 40 #else 41 typedef char * voidstar; 42 #endif 43 44 #include "expr.h" 45 #include "vector.h" 46 #include "ray.h" 47 #include "color.h" 48 #include "transform.h" 49 #include "error.h" 50 51 #ifndef TRUE 52 #define TRUE 1 53 #endif 54 55 #ifndef FALSE 56 #define FALSE 0 57 #endif 58 59 /* 60 * Various useful constants and macros. 61 */ 62 63 /* 64 * Minimum vector length & fp value. 65 * Modify depending upon Float typedef. 66 */ 67 #define EPSILON (Float)0.00001 68 69 #ifndef PI 70 #define PI 3.14159265358979323846 71 #endif 72 #define TWOPI (2. * PI) 73 #define INV_TWOPI (1. / TWOPI) 74 #define deg2rad(x) (Float)(x * PI/180.) 75 #define LNHALF (-.69314718) 76 77 #ifndef NULL 78 # define NULL 0 79 #endif 80 81 #define UNSET -1 82 83 /* 84 * Some systems, such as the RS6000, have fast fabs already defined. 85 */ 86 #ifndef fabs 87 extern Float RSabstmp; 88 #define fabs(x) ((RSabstmp=x) < 0 ? -RSabstmp : RSabstmp) 89 #endif 90 91 #ifdef MULTIMAX 92 /* 93 * On the multimax, allocate large pieces of memory as shared memory. 94 */ 95 extern char *share_malloc(), *share_calloc(); 96 #else 97 /* 98 * Otherwise, malloc is malloc, etc. 99 */ 100 #define share_malloc(x) Malloc(x) 101 #define share_calloc(x,y) Calloc(x,y) 102 #endif 103 104 /* 105 * Close enough for us. 106 */ 107 #define equal(a, b) (fabs((a) - (b)) < EPSILON) 108 /* 109 * Maximum/Minimum functions 110 */ 111 #define max(a, b) ((a) > (b) ? (a) : (b)) 112 #define min(a, b) ((a) < (b) ? (a) : (b)) 113 114 extern voidstar Malloc(), Calloc(); 115 extern char *strsave(); 116 extern double drand48(); /* just in case */ 117 118 #endif /* COMMON_H */ 119