[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26191] trunk/blender/source/blender: Math Lib:

Brecht Van Lommel brecht at blender.org
Fri Jan 22 12:10:24 CET 2010


Revision: 26191
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26191
Author:   blendix
Date:     2010-01-22 12:10:24 +0100 (Fri, 22 Jan 2010)

Log Message:
-----------
Math Lib:

* inline some more functions, from math_base and math_vector
* also made some changes to the way inline is done so it can
  work for more than one file
* reflect_v3_v3v3 requires input vectors to be normalized now.
* added rgb_to_grayscale
* added zero_v4, copy_v4_v4, swap_v4_v4, is_one_v3
* added box_clip_bounds_m4 to clip a bounding box against a
  projection matrix

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_base.h
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/BLI_math_geom.h
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/gsqueue.c
    trunk/blender/source/blender/blenlib/intern/math_base.c
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/blenlib/intern/math_vector.c
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/python/generic/vector.c

Added Paths:
-----------
    trunk/blender/source/blender/blenlib/BLI_math_inline.h
    trunk/blender/source/blender/blenlib/intern/math_base_inline.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_base.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_base.h	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/BLI_math_base.h	2010-01-22 11:10:24 UTC (rev 26191)
@@ -37,6 +37,7 @@
 #endif
 
 #include <math.h>
+#include "BLI_math_inline.h"
 
 #ifndef M_PI
 #define M_PI        3.14159265358979323846
@@ -130,24 +131,31 @@
 #define CLAMP(a, b, c)		if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
 #endif
 
+#ifdef BLI_MATH_INLINE
+#include "intern/math_base_inline.c"
+#endif
+
 /******************************* Float ******************************/
 
-float sqrt3f(float f);
-double sqrt3d(double d);
+MINLINE float sqrt3f(float f);
+MINLINE double sqrt3d(double d);
 
-float saacosf(float f);
-float saasinf(float f);
-float sasqrtf(float f);
-float saacos(float fac);
-float saasin(float fac);
-float sasqrt(float fac);
+MINLINE float saacosf(float f);
+MINLINE float saasinf(float f);
+MINLINE float sasqrtf(float f);
+MINLINE float saacos(float fac);
+MINLINE float saasin(float fac);
+MINLINE float sasqrt(float fac);
 
-float interpf(float a, float b, float t);
+MINLINE float interpf(float a, float b, float t);
 
-float power_of_2(float f);
+MINLINE float minf(float a, float b);
+MINLINE float maxf(float a, float b);
 
-float shell_angle_to_dist(float angle);
+MINLINE float power_of_2(float f);
 
+MINLINE float shell_angle_to_dist(float angle);
+
 double double_round(double x, int ndigits);
 
 #ifdef __cplusplus

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-01-22 11:10:24 UTC (rev 26191)
@@ -59,6 +59,8 @@
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 
+float rgb_to_grayscale(float rgb[3]);
+
 /***************** Profile Transformations ********************/
 
 void gamma_correct(float *c, float gamma);

Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h	2010-01-22 11:10:24 UTC (rev 26191)
@@ -144,6 +144,9 @@
 void orthographic_m4(float mat[4][4], float left, float right,
 	float bottom, float top, float nearClip, float farClip);
 
+int box_clip_bounds_m4(float boundbox[2][3],
+	float bounds[4], float winmat[4][4]);
+
 /********************************** Mapping **********************************/
 
 void map_to_tube(float *u, float *v, float x, float y, float z);

Added: trunk/blender/source/blender/blenlib/BLI_math_inline.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_inline.h	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/BLI_math_inline.h	2010-01-22 11:10:24 UTC (rev 26191)
@@ -0,0 +1,53 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: some of this file.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * */
+
+#ifndef BLI_MATH_INLINE_H
+#define BLI_MATH_INLINE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* add platform/compiler checks here if it is not supported */
+#define BLI_MATH_INLINE
+
+#ifdef BLI_MATH_INLINE
+#ifdef _MSC_VER
+#define MINLINE static __inline
+#else
+#define MINLINE static inline
+#endif
+#else
+#define MINLINE
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BLI_MATH_INLINE_H */
+

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2010-01-22 11:10:24 UTC (rev 26191)
@@ -32,30 +32,23 @@
 extern "C" {
 #endif
 
-/* add platform/compiler checks here if it is not supported */
-#define BLI_MATH_INLINE
-
 #ifdef BLI_MATH_INLINE
-#ifdef _MSC_VER
-#define MINLINE static __inline
-#else
-#define MINLINE static inline
-#endif
 #include "intern/math_vector_inline.c"
-#else
-#define MINLINE
 #endif
 
 /************************************* Init ***********************************/
 
 MINLINE void zero_v2(float r[2]);
 MINLINE void zero_v3(float r[3]);
+MINLINE void zero_v4(float r[4]);
 
 MINLINE void copy_v2_v2(float r[2], const float a[2]);
 MINLINE void copy_v3_v3(float r[3], const float a[3]);
+MINLINE void copy_v4_v4(float r[4], float a[4]);
 
 MINLINE void swap_v2_v2(float a[2], float b[2]);
 MINLINE void swap_v3_v3(float a[3], float b[3]);
+MINLINE void swap_v4_v4(float a[4], float b[4]);
 
 /********************************* Arithmetic ********************************/
 
@@ -118,13 +111,15 @@
 
 /********************************* Comparison ********************************/
 
-int is_zero_v3(float a[3]);
-int equals_v3v3(float a[3], float b[3]);
-int compare_v3v3(float a[3], float b[3], float limit);
-int compare_len_v3v3(float a[3], float b[3], float limit);
+MINLINE int is_zero_v3(float a[3]);
+MINLINE int is_one_v3(float a[3]);
 
-int compare_v4v4(float a[4], float b[4], float limit);
+MINLINE int equals_v3v3(float a[3], float b[3]);
+MINLINE int compare_v3v3(float a[3], float b[3], float limit);
+MINLINE int compare_len_v3v3(float a[3], float b[3], float limit);
 
+MINLINE int compare_v4v4(float a[4], float b[4], float limit);
+
 /********************************** Angles ***********************************/
 /* - angle with 2 arguments is angle between vector                          */
 /* - angle with 3 arguments is angle between 3 points at the middle point    */

Modified: trunk/blender/source/blender/blenlib/intern/gsqueue.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/gsqueue.c	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/intern/gsqueue.c	2010-01-22 11:10:24 UTC (rev 26191)
@@ -60,6 +60,17 @@
 	return (gq->head==NULL);
 }
 
+int BLI_gsqueue_size(GSQueue *gq)
+{ 
+	GSQueueElem *elem;
+	int size= 0;
+
+	for(elem=gq->head; elem; elem=elem->next)
+		size++;
+	
+	return size;
+}
+
 void BLI_gsqueue_peek(GSQueue *gq, void *item_r)
 {
 	memcpy(item_r, &gq->head[1], gq->elem_size);

Modified: trunk/blender/source/blender/blenlib/intern/math_base.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_base.c	2010-01-22 11:06:57 UTC (rev 26190)
+++ trunk/blender/source/blender/blenlib/intern/math_base.c	2010-01-22 11:10:24 UTC (rev 26191)
@@ -32,84 +32,6 @@
 
 #include "BLI_math.h"
 
-/* A few small defines. Keep'em local! */
-#define SMALL_NUMBER	1.e-8
-
-float sqrt3f(float f)
-{
-	if(f==0.0) return 0;
-	if(f<0) return (float)(-exp(log(-f)/3));
-	else return (float)(exp(log(f)/3));
-}
-
-double sqrt3d(double d)
-{
-	if(d==0.0) return 0;
-	if(d<0) return -exp(log(-d)/3);
-	else return exp(log(d)/3);
-}
-
-float saacos(float fac)
-{
-	if(fac<= -1.0f) return (float)M_PI;
-	else if(fac>=1.0f) return 0.0;
-	else return (float)acos(fac);
-}
-
-float saasin(float fac)
-{
-	if(fac<= -1.0f) return (float)-M_PI/2.0f;
-	else if(fac>=1.0f) return (float)M_PI/2.0f;
-	else return (float)asin(fac);
-}
-
-float sasqrt(float fac)
-{
-	if(fac<=0.0) return 0.0;
-	return (float)sqrt(fac);
-}
-
-float saacosf(float fac)
-{
-	if(fac<= -1.0f) return (float)M_PI;
-	else if(fac>=1.0f) return 0.0f;
-	else return (float)acosf(fac);
-}
-
-float saasinf(float fac)
-{
-	if(fac<= -1.0f) return (float)-M_PI/2.0f;
-	else if(fac>=1.0f) return (float)M_PI/2.0f;
-	else return (float)asinf(fac);
-}
-
-float sasqrtf(float fac)
-{
-	if(fac<=0.0) return 0.0;
-	return (float)sqrtf(fac);
-}
-
-float interpf(float target, float origin, float fac)
-{
-	return (fac*target) + (1.0f-fac)*origin;
-}
-
-/* useful to calculate an even width shell, by taking the angle between 2 planes.
- * The return value is a scale on the offset.
- * no angle between planes is 1.0, as the angle between the 2 planes approches 180d
- * the distance gets very high, 180d would be inf, but this case isn't valid */
-float shell_angle_to_dist(const float angle)
-{
-	return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle));
-}
-
-/* used for zoom values*/
-float power_of_2(float val)
-{
-	return (float)pow(2, ceil(log(val) / log(2)));
-}
-
-
 /* WARNING: MSVC compiling hack for double_round() */
 #if (WIN32 || WIN64) && !(FREE_WINDOWS)
 
@@ -169,3 +91,4 @@
 	/* if computation resulted in overflow, raise OverflowError */
 	return z;
 }
+

Added: trunk/blender/source/blender/blenlib/intern/math_base_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_base_inline.c	                        (rev 0)
+++ trunk/blender/source/blender/blenlib/intern/math_base_inline.c	2010-01-22 11:10:24 UTC (rev 26191)
@@ -0,0 +1,127 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list