|
Blender
V2.59
|
00001 00004 /* Copyright (c) 1999, Not a Number / NeoGeo b.v. 00005 * $Id: util.h 35244 2011-02-27 20:32:12Z jesterking $ 00006 * 00007 * All rights reserved. 00008 * 00009 * Contact: info@blender.org 00010 * Information: http://www.blender.org 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted provided that the following conditions 00014 * are met: 00015 * 1. Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright 00018 * notice, this list of conditions and the following disclaimer in the 00019 * documentation and/or other materials provided with the distribution. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 */ 00033 00034 #ifndef UTIL_H 00035 #define UTIL_H 00036 00037 #include <sys/types.h> 00038 #include <stdlib.h> 00039 #include <string.h> 00040 #include "externdef.h" 00041 00042 #ifndef NULL 00043 #define NULL 0 00044 #endif 00045 00046 #ifndef FALSE 00047 #define FALSE 0 00048 #endif 00049 00050 #ifndef TRUE 00051 #define TRUE 1 00052 #endif 00053 00054 #ifndef ulong 00055 #define ulong unsigned long 00056 #endif 00057 00058 #ifndef ushort 00059 #define ushort unsigned short 00060 #endif 00061 00062 #ifndef uchar 00063 #define uchar unsigned char 00064 #endif 00065 00066 #ifndef uint 00067 #define uint unsigned int 00068 #endif 00069 00070 #define MIN2(x,y) ( (x)<(y) ? (x) : (y) ) 00071 #define MIN3(x,y,z) MIN2( MIN2((x),(y)) , (z) ) 00072 #define MIN4(x,y,z,a) MIN2( MIN2((x),(y)) , MIN2((z),(a)) ) 00073 00074 #define MAX2(x,y) ( (x)>(y) ? (x) : (y) ) 00075 #define MAX3(x,y,z) MAX2( MAX2((x),(y)) , (z) ) 00076 #define MAX4(x,y,z,a) MAX2( MAX2((x),(y)) , MAX2((z),(a)) ) 00077 00078 #define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } 00079 00080 #define ABS(x) ((x) < 0 ? -(x) : (x)) 00081 #define FLOOR(x) ((int)(x) - ((x) < 0 && (x) != (int)(x))) 00082 #define CEIL(x) ((int)(x) + ((x) > 0 && (x) != (int)(x))) 00083 #define STEP(a,b) ( (a)>(b) ? (1) : (0) ) 00084 #define CLAMP(val, low, high) ((val>high)?high:((val<low)?low:val)) 00085 #define LERP(t,x0,x1) ((x0) + (t)*((x1)-(x0))) 00086 #define PULSE(a,b,x) (STEP((a),(x)) - STEP((b),(x))) 00087 #define BOXSTEP(a,b,x) CLAMP(((x)-(a))/((b)-(a)),0,1) 00088 00089 #define PRINT(d, var1) printf(# var1 ":%" # d "\n", var1) 00090 #define PRINT2(d, e, var1, var2) printf(# var1 ":%" # d " " # var2 ":%" # e "\n", var1, var2) 00091 #define PRINT3(d, e, f, var1, var2, var3) printf(# var1 ":%" # d " " # var2 ":%" # e " " # var3 ":%" # f "\n", var1, var2, var3) 00092 #define PRINT4(d, e, f, g, var1, var2, var3, var4) printf(# var1 ":%" # d " " # var2 ":%" # e " " # var3 ":%" # f " " # var4 ":%" # g "\n", var1, var2, var3, var4) 00093 00094 LIBEXPORT void *mallocN(int len, char *str); 00095 LIBEXPORT void *callocN(int len, char *str); 00096 LIBEXPORT short freeN(void *vmemh); 00097 00098 LIBEXPORT void *mallocT(int len, char *str); 00099 LIBEXPORT void *callocT(int len, char *str); 00100 LIBEXPORT void freeT(void *vmemh); 00101 00102 #endif /* UTIL_H */ 00103