Page MenuHome

math-inline-headers.patch

math-inline-headers.patch

Index: source/blender/blenlib/BLI_math_base.h
===================================================================
--- source/blender/blenlib/BLI_math_base.h (revision 45655)
+++ source/blender/blenlib/BLI_math_base.h (working copy)
@@ -142,9 +142,7 @@
#define CLAMP(a, b, c) if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
#endif
-#ifdef __BLI_MATH_INLINE_H__
-#include "intern/math_base_inline.c"
-#endif
+#include "intern/math_base_inline.h"
/******************************* Float ******************************/
Index: source/blender/blenlib/BLI_math_color.h
===================================================================
--- source/blender/blenlib/BLI_math_color.h (revision 45655)
+++ source/blender/blenlib/BLI_math_color.h (working copy)
@@ -113,9 +113,7 @@
void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);
-#ifdef __BLI_MATH_INLINE_H__
-#include "intern/math_color_inline.c"
-#endif
+#include "intern/math_color_inline.h"
#ifdef __cplusplus
}
Index: source/blender/blenlib/BLI_math_geom.h
===================================================================
--- source/blender/blenlib/BLI_math_geom.h (revision 45655)
+++ source/blender/blenlib/BLI_math_geom.h (working copy)
@@ -36,9 +36,7 @@
#include "BLI_math_inline.h"
-#ifdef __BLI_MATH_INLINE_H__
-#include "intern/math_geom_inline.c"
-#endif
+#include "intern/math_geom_inline.h"
/********************************** Polygons *********************************/
Index: source/blender/blenlib/BLI_math_inline.h
===================================================================
--- source/blender/blenlib/BLI_math_inline.h (revision 45655)
+++ source/blender/blenlib/BLI_math_inline.h (working copy)
@@ -35,24 +35,17 @@
#endif
/* add platform/compiler checks here if it is not supported */
-#define __BLI_MATH_INLINE_H__
-
-#ifdef __BLI_MATH_INLINE_H__
-# ifdef _MSC_VER
-# define MINLINE static __forceinline
-# define MALWAYS_INLINE MINLINE
+#ifdef _MSC_VER
+# define MINLINE static __forceinline
+# define MALWAYS_INLINE MINLINE
+#else
+# define MINLINE static inline
+# if (defined(__APPLE__) && defined(__ppc__))
+ /* static inline __attribute__ here breaks osx ppc gcc42 build */
+# define MALWAYS_INLINE static __attribute__((always_inline))
# else
-# define MINLINE static inline
-# if (defined(__APPLE__) && defined(__ppc__))
- /* static inline __attribute__ here breaks osx ppc gcc42 build */
-# define MALWAYS_INLINE static __attribute__((always_inline))
-# else
-# define MALWAYS_INLINE static inline __attribute__((always_inline))
-# endif
+# define MALWAYS_INLINE static inline __attribute__((always_inline))
# endif
-#else
-# define MINLINE
-# define MALWAYS_INLINE
#endif
#ifdef __cplusplus
Index: source/blender/blenlib/BLI_math_vector.h
===================================================================
--- source/blender/blenlib/BLI_math_vector.h (revision 45655)
+++ source/blender/blenlib/BLI_math_vector.h (working copy)
@@ -36,9 +36,7 @@
#include "BLI_math_inline.h"
-#ifdef __BLI_MATH_INLINE_H__
-#include "intern/math_vector_inline.c"
-#endif
+#include "intern/math_vector_inline.h"
/************************************* Init ***********************************/
Index: source/blender/blenlib/CMakeLists.txt
===================================================================
--- source/blender/blenlib/CMakeLists.txt (revision 45655)
+++ source/blender/blenlib/CMakeLists.txt (working copy)
@@ -63,15 +63,11 @@
intern/jitter.c
intern/listbase.c
intern/math_base.c
- intern/math_base_inline.c
intern/math_color.c
- intern/math_color_inline.c
intern/math_geom.c
- intern/math_geom_inline.c
intern/math_matrix.c
intern/math_rotation.c
intern/math_vector.c
- intern/math_vector_inline.c
intern/md5.c
intern/noise.c
intern/path_util.c
@@ -143,6 +139,11 @@
BLI_voxel.h
BLI_winstuff.h
PIL_time.h
+
+ intern/math_base_inline.h
+ intern/math_color_inline.h
+ intern/math_geom_inline.h
+ intern/math_vector_inline.h
)
if(WITH_BINRELOC)
Index: source/blender/blenlib/intern/math_base_inline.c
===================================================================
--- source/blender/blenlib/intern/math_base_inline.c (revision 45655)
+++ source/blender/blenlib/intern/math_base_inline.c (working copy)
@@ -1,158 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
- * */
-
-/** \file blender/blenlib/intern/math_base_inline.c
- * \ingroup bli
- */
-
-
-#include <float.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "BLI_math.h"
-
-#ifndef __MATH_BASE_INLINE_C__
-#define __MATH_BASE_INLINE_C__
-
-/* A few small defines. Keep'em local! */
-#define SMALL_NUMBER 1.e-8f
-
-MINLINE float sqrt3f(float f)
-{
- if (f == 0.0f) return 0.0f;
- if (f < 0) return (float)(-exp(log(-f) / 3));
- else return (float)(exp(log(f) / 3));
-}
-
-MINLINE double sqrt3d(double d)
-{
- if (d == 0.0) return 0;
- if (d < 0) return -exp(log(-d) / 3);
- else return exp(log(d) / 3);
-}
-
-MINLINE 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);
-}
-
-MINLINE 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);
-}
-
-MINLINE float sasqrt(float fac)
-{
- if (fac <= 0.0f) return 0.0f;
- return (float)sqrt(fac);
-}
-
-MINLINE 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);
-}
-
-MINLINE 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);
-}
-
-MINLINE float sasqrtf(float fac)
-{
- if (fac <= 0.0f) return 0.0f;
- return (float)sqrtf(fac);
-}
-
-MINLINE 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 approaches 180d
- * the distance gets very high, 180d would be inf, but this case isn't valid */
-MINLINE float shell_angle_to_dist(const float angle)
-{
- return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle));
-}
-
-/* used for zoom values*/
-MINLINE float power_of_2(float val)
-{
- return (float)pow(2.0, ceil(log((double)val) / M_LN2));
-}
-
-MINLINE int is_power_of_2_i(int n)
-{
- return (n & (n - 1)) == 0;
-}
-
-MINLINE int power_of_2_max_i(int n)
-{
- if (is_power_of_2_i(n))
- return n;
-
- while (!is_power_of_2_i(n))
- n = n & (n - 1);
-
- return n * 2;
-}
-
-MINLINE int power_of_2_min_i(int n)
-{
- while (!is_power_of_2_i(n))
- n = n & (n - 1);
-
- return n;
-}
-
-MINLINE float minf(float a, float b)
-{
- return (a < b) ? a : b;
-}
-
-MINLINE float maxf(float a, float b)
-{
- return (a > b) ? a : b;
-}
-
-MINLINE float signf(float f)
-{
- return (f < 0.f) ? -1.f : 1.f;
-}
-
-
-#endif /* __MATH_BASE_INLINE_C__ */
Index: source/blender/blenlib/intern/math_base_inline.h
===================================================================
--- source/blender/blenlib/intern/math_base_inline.h (revision 0)
+++ source/blender/blenlib/intern/math_base_inline.h (working copy)
@@ -0,0 +1,158 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
+ * */
+
+/** \file blender/blenlib/intern/math_base_inline.c
+ * \ingroup bli
+ */
+
+
+#include <float.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "BLI_math.h"
+
+#ifndef __MATH_BASE_INLINE_C__
+#define __MATH_BASE_INLINE_C__
+
+/* A few small defines. Keep'em local! */
+#define SMALL_NUMBER 1.e-8f
+
+MINLINE float sqrt3f(float f)
+{
+ if (f == 0.0f) return 0.0f;
+ if (f < 0) return (float)(-exp(log(-f) / 3));
+ else return (float)(exp(log(f) / 3));
+}
+
+MINLINE double sqrt3d(double d)
+{
+ if (d == 0.0) return 0;
+ if (d < 0) return -exp(log(-d) / 3);
+ else return exp(log(d) / 3);
+}
+
+MINLINE 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);
+}
+
+MINLINE 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);
+}
+
+MINLINE float sasqrt(float fac)
+{
+ if (fac <= 0.0f) return 0.0f;
+ return (float)sqrt(fac);
+}
+
+MINLINE 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);
+}
+
+MINLINE 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);
+}
+
+MINLINE float sasqrtf(float fac)
+{
+ if (fac <= 0.0f) return 0.0f;
+ return (float)sqrtf(fac);
+}
+
+MINLINE 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 approaches 180d
+ * the distance gets very high, 180d would be inf, but this case isn't valid */
+MINLINE float shell_angle_to_dist(const float angle)
+{
+ return (angle < SMALL_NUMBER) ? 1.0f : fabsf(1.0f / cosf(angle));
+}
+
+/* used for zoom values*/
+MINLINE float power_of_2(float val)
+{
+ return (float)pow(2.0, ceil(log((double)val) / M_LN2));
+}
+
+MINLINE int is_power_of_2_i(int n)
+{
+ return (n & (n - 1)) == 0;
+}
+
+MINLINE int power_of_2_max_i(int n)
+{
+ if (is_power_of_2_i(n))
+ return n;
+
+ while (!is_power_of_2_i(n))
+ n = n & (n - 1);
+
+ return n * 2;
+}
+
+MINLINE int power_of_2_min_i(int n)
+{
+ while (!is_power_of_2_i(n))
+ n = n & (n - 1);
+
+ return n;
+}
+
+MINLINE float minf(float a, float b)
+{
+ return (a < b) ? a : b;
+}
+
+MINLINE float maxf(float a, float b)
+{
+ return (a > b) ? a : b;
+}
+
+MINLINE float signf(float f)
+{
+ return (f < 0.f) ? -1.f : 1.f;
+}
+
+
+#endif /* __MATH_BASE_INLINE_C__ */
Index: source/blender/blenlib/intern/math_base_inline.h
===================================================================
--- source/blender/blenlib/intern/math_base_inline.h (revision 45655)
+++ source/blender/blenlib/intern/math_base_inline.h (working copy)
Property changes on: source/blender/blenlib/intern/math_base_inline.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: source/blender/blenlib/intern/math_color_inline.c
===================================================================
--- source/blender/blenlib/intern/math_color_inline.c (revision 45655)
+++ source/blender/blenlib/intern/math_color_inline.c (working copy)
@@ -1,218 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
- * */
-
-/** \file blender/blenlib/intern/math_color_inline.c
- * \ingroup bli
- */
-
-
-#include "BLI_math_color.h"
-#include "BLI_utildefines.h"
-
-#ifndef __MATH_COLOR_INLINE_C__
-#define __MATH_COLOR_INLINE_C__
-
-/******************************** Color Space ********************************/
-
-MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
-{
- linear[0] = srgb_to_linearrgb(srgb[0]);
- linear[1] = srgb_to_linearrgb(srgb[1]);
- linear[2] = srgb_to_linearrgb(srgb[2]);
-}
-
-MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
-{
- srgb[0] = linearrgb_to_srgb(linear[0]);
- srgb[1] = linearrgb_to_srgb(linear[1]);
- srgb[2] = linearrgb_to_srgb(linear[2]);
-}
-
-MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
-{
- srgb_to_linearrgb_v3_v3(linear, srgb);
- linear[3] = srgb[3];
-}
-
-MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
-{
- linearrgb_to_srgb_v3_v3(srgb, linear);
- srgb[3] = linear[3];
-}
-
-MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
-{
- float srgb_f[3];
-
- linearrgb_to_srgb_v3_v3(srgb_f, linear);
- F3TOCHAR3(srgb_f, srgb);
-}
-
-MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
-{
- float srgb_f[4];
-
- linearrgb_to_srgb_v4(srgb_f, linear);
- F4TOCHAR4(srgb_f, srgb);
-}
-
-/* predivide versions to work on associated/premultipled alpha. if this should
- * be done or not depends on the background the image will be composited over,
- * ideally you would never do color space conversion on an image with alpha
- * because it is ill defined */
-
-MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4])
-{
- float alpha, inv_alpha;
-
- if (srgb[3] == 1.0f || srgb[3] == 0.0f) {
- alpha = 1.0f;
- inv_alpha = 1.0f;
- }
- else {
- alpha = srgb[3];
- inv_alpha = 1.0f / alpha;
- }
-
- linear[0] = srgb_to_linearrgb(srgb[0] * inv_alpha) * alpha;
- linear[1] = srgb_to_linearrgb(srgb[1] * inv_alpha) * alpha;
- linear[2] = srgb_to_linearrgb(srgb[2] * inv_alpha) * alpha;
- linear[3] = srgb[3];
-}
-
-MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4])
-{
- float alpha, inv_alpha;
-
- if (linear[3] == 1.0f || linear[3] == 0.0f) {
- alpha = 1.0f;
- inv_alpha = 1.0f;
- }
- else {
- alpha = linear[3];
- inv_alpha = 1.0f / alpha;
- }
-
- srgb[0] = linearrgb_to_srgb(linear[0] * inv_alpha) * alpha;
- srgb[1] = linearrgb_to_srgb(linear[1] * inv_alpha) * alpha;
- srgb[2] = linearrgb_to_srgb(linear[2] * inv_alpha) * alpha;
- srgb[3] = linear[3];
-}
-
-/* LUT accelerated conversions */
-
-extern float BLI_color_from_srgb_table[256];
-extern unsigned short BLI_color_to_srgb_table[0x10000];
-
-MINLINE unsigned short to_srgb_table_lookup(const float f)
-{
-
- union {
- float f;
- unsigned short us[2];
- } tmp;
- tmp.f = f;
-#ifdef __BIG_ENDIAN__
- return BLI_color_to_srgb_table[tmp.us[0]];
-#else
- return BLI_color_to_srgb_table[tmp.us[1]];
-#endif
-}
-
-MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4])
-{
- srgb[0] = to_srgb_table_lookup(linear[0]);
- srgb[1] = to_srgb_table_lookup(linear[1]);
- srgb[2] = to_srgb_table_lookup(linear[2]);
- srgb[3] = FTOUSHORT(linear[3]);
-}
-
-MINLINE void linearrgb_to_srgb_ushort4_predivide(unsigned short srgb[4], const float linear[4])
-{
- float alpha, inv_alpha, t;
- int i;
-
- if (linear[3] == 1.0f || linear[3] == 0.0f) {
- linearrgb_to_srgb_ushort4(srgb, linear);
- return;
- }
-
- alpha = linear[3];
- inv_alpha = 1.0f / alpha;
-
- for (i = 0; i < 3; ++i) {
- t = linear[i] * inv_alpha;
- srgb[i] = (t < 1.0f) ? (unsigned short) (to_srgb_table_lookup(t) * alpha) : FTOUSHORT(linearrgb_to_srgb(t) * alpha);
- }
-
- srgb[3] = FTOUSHORT(linear[3]);
-}
-
-MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
-{
- linear[0] = BLI_color_from_srgb_table[srgb[0]];
- linear[1] = BLI_color_from_srgb_table[srgb[1]];
- linear[2] = BLI_color_from_srgb_table[srgb[2]];
- linear[3] = srgb[3] * (1.0f / 255.0f);
-}
-
-MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
-{
- float fsrgb[4];
- int i;
-
- if (srgb[3] == 255 || srgb[3] == 0) {
- srgb_to_linearrgb_uchar4(linear, srgb);
- return;
- }
-
- for (i = 0; i < 4; i++)
- fsrgb[i] = srgb[i] * (1.0f / 255.0f);
-
- srgb_to_linearrgb_predivide_v4(linear, fsrgb);
-}
-
-/* color macros for themes */
-#define rgba_char_args_set_fl(col, r, g, b, a) rgba_char_args_set(col, r * 255, g * 255, b * 255, a * 255)
-
-MINLINE void rgba_char_args_set(char col[4], const char r, const char g, const char b, const char a)
-{
- col[0] = r;
- col[1] = g;
- col[2] = b;
- col[3] = a;
-}
-
-MINLINE void rgba_char_args_test_set(char col[4], const char r, const char g, const char b, const char a)
-{
- if (col[3] == 0) {
- col[0] = r;
- col[1] = g;
- col[2] = b;
- col[3] = a;
- }
-}
-
-#endif /* __MATH_COLOR_INLINE_C__ */
Index: source/blender/blenlib/intern/math_color_inline.h
===================================================================
--- source/blender/blenlib/intern/math_color_inline.h (revision 0)
+++ source/blender/blenlib/intern/math_color_inline.h (working copy)
@@ -0,0 +1,218 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
+ * */
+
+/** \file blender/blenlib/intern/math_color_inline.c
+ * \ingroup bli
+ */
+
+
+#include "BLI_math_color.h"
+#include "BLI_utildefines.h"
+
+#ifndef __MATH_COLOR_INLINE_C__
+#define __MATH_COLOR_INLINE_C__
+
+/******************************** Color Space ********************************/
+
+MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
+{
+ linear[0] = srgb_to_linearrgb(srgb[0]);
+ linear[1] = srgb_to_linearrgb(srgb[1]);
+ linear[2] = srgb_to_linearrgb(srgb[2]);
+}
+
+MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
+{
+ srgb[0] = linearrgb_to_srgb(linear[0]);
+ srgb[1] = linearrgb_to_srgb(linear[1]);
+ srgb[2] = linearrgb_to_srgb(linear[2]);
+}
+
+MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
+{
+ srgb_to_linearrgb_v3_v3(linear, srgb);
+ linear[3] = srgb[3];
+}
+
+MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
+{
+ linearrgb_to_srgb_v3_v3(srgb, linear);
+ srgb[3] = linear[3];
+}
+
+MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3])
+{
+ float srgb_f[3];
+
+ linearrgb_to_srgb_v3_v3(srgb_f, linear);
+ F3TOCHAR3(srgb_f, srgb);
+}
+
+MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
+{
+ float srgb_f[4];
+
+ linearrgb_to_srgb_v4(srgb_f, linear);
+ F4TOCHAR4(srgb_f, srgb);
+}
+
+/* predivide versions to work on associated/premultipled alpha. if this should
+ * be done or not depends on the background the image will be composited over,
+ * ideally you would never do color space conversion on an image with alpha
+ * because it is ill defined */
+
+MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4])
+{
+ float alpha, inv_alpha;
+
+ if (srgb[3] == 1.0f || srgb[3] == 0.0f) {
+ alpha = 1.0f;
+ inv_alpha = 1.0f;
+ }
+ else {
+ alpha = srgb[3];
+ inv_alpha = 1.0f / alpha;
+ }
+
+ linear[0] = srgb_to_linearrgb(srgb[0] * inv_alpha) * alpha;
+ linear[1] = srgb_to_linearrgb(srgb[1] * inv_alpha) * alpha;
+ linear[2] = srgb_to_linearrgb(srgb[2] * inv_alpha) * alpha;
+ linear[3] = srgb[3];
+}
+
+MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4])
+{
+ float alpha, inv_alpha;
+
+ if (linear[3] == 1.0f || linear[3] == 0.0f) {
+ alpha = 1.0f;
+ inv_alpha = 1.0f;
+ }
+ else {
+ alpha = linear[3];
+ inv_alpha = 1.0f / alpha;
+ }
+
+ srgb[0] = linearrgb_to_srgb(linear[0] * inv_alpha) * alpha;
+ srgb[1] = linearrgb_to_srgb(linear[1] * inv_alpha) * alpha;
+ srgb[2] = linearrgb_to_srgb(linear[2] * inv_alpha) * alpha;
+ srgb[3] = linear[3];
+}
+
+/* LUT accelerated conversions */
+
+extern float BLI_color_from_srgb_table[256];
+extern unsigned short BLI_color_to_srgb_table[0x10000];
+
+MINLINE unsigned short to_srgb_table_lookup(const float f)
+{
+
+ union {
+ float f;
+ unsigned short us[2];
+ } tmp;
+ tmp.f = f;
+#ifdef __BIG_ENDIAN__
+ return BLI_color_to_srgb_table[tmp.us[0]];
+#else
+ return BLI_color_to_srgb_table[tmp.us[1]];
+#endif
+}
+
+MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4])
+{
+ srgb[0] = to_srgb_table_lookup(linear[0]);
+ srgb[1] = to_srgb_table_lookup(linear[1]);
+ srgb[2] = to_srgb_table_lookup(linear[2]);
+ srgb[3] = FTOUSHORT(linear[3]);
+}
+
+MINLINE void linearrgb_to_srgb_ushort4_predivide(unsigned short srgb[4], const float linear[4])
+{
+ float alpha, inv_alpha, t;
+ int i;
+
+ if (linear[3] == 1.0f || linear[3] == 0.0f) {
+ linearrgb_to_srgb_ushort4(srgb, linear);
+ return;
+ }
+
+ alpha = linear[3];
+ inv_alpha = 1.0f / alpha;
+
+ for (i = 0; i < 3; ++i) {
+ t = linear[i] * inv_alpha;
+ srgb[i] = (t < 1.0f) ? (unsigned short) (to_srgb_table_lookup(t) * alpha) : FTOUSHORT(linearrgb_to_srgb(t) * alpha);
+ }
+
+ srgb[3] = FTOUSHORT(linear[3]);
+}
+
+MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
+{
+ linear[0] = BLI_color_from_srgb_table[srgb[0]];
+ linear[1] = BLI_color_from_srgb_table[srgb[1]];
+ linear[2] = BLI_color_from_srgb_table[srgb[2]];
+ linear[3] = srgb[3] * (1.0f / 255.0f);
+}
+
+MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4])
+{
+ float fsrgb[4];
+ int i;
+
+ if (srgb[3] == 255 || srgb[3] == 0) {
+ srgb_to_linearrgb_uchar4(linear, srgb);
+ return;
+ }
+
+ for (i = 0; i < 4; i++)
+ fsrgb[i] = srgb[i] * (1.0f / 255.0f);
+
+ srgb_to_linearrgb_predivide_v4(linear, fsrgb);
+}
+
+/* color macros for themes */
+#define rgba_char_args_set_fl(col, r, g, b, a) rgba_char_args_set(col, r * 255, g * 255, b * 255, a * 255)
+
+MINLINE void rgba_char_args_set(char col[4], const char r, const char g, const char b, const char a)
+{
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = a;
+}
+
+MINLINE void rgba_char_args_test_set(char col[4], const char r, const char g, const char b, const char a)
+{
+ if (col[3] == 0) {
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = a;
+ }
+}
+
+#endif /* __MATH_COLOR_INLINE_C__ */
Index: source/blender/blenlib/intern/math_color_inline.h
===================================================================
--- source/blender/blenlib/intern/math_color_inline.h (revision 45655)
+++ source/blender/blenlib/intern/math_color_inline.h (working copy)
Property changes on: source/blender/blenlib/intern/math_color_inline.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: source/blender/blenlib/intern/math_geom_inline.c
===================================================================
--- source/blender/blenlib/intern/math_geom_inline.c (revision 45655)
+++ source/blender/blenlib/intern/math_geom_inline.c (working copy)
@@ -1,140 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
- * */
-
-/** \file blender/blenlib/intern/math_geom_inline.c
- * \ingroup bli
- */
-
-
-#include "BLI_math.h"
-
-#ifndef __MATH_GEOM_INLINE_C__
-#define __MATH_GEOM_INLINE_C__
-
-/****************************** Spherical Harmonics **************************/
-
-MINLINE void zero_sh(float r[9])
-{
- memset(r, 0, sizeof(float) * 9);
-}
-
-MINLINE void copy_sh_sh(float r[9], const float a[9])
-{
- memcpy(r, a, sizeof(float) * 9);
-}
-
-MINLINE void mul_sh_fl(float r[9], const float f)
-{
- int i;
-
- for (i = 0; i < 9; i++)
- r[i] *= f;
-}
-
-MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9])
-{
- int i;
-
- for (i = 0; i < 9; i++)
- r[i] = a[i] + b[i];
-}
-
-MINLINE float dot_shsh(float a[9], float b[9])
-{
- float r = 0.0f;
- int i;
-
- for (i = 0; i < 9; i++)
- r += a[i] * b[i];
-
- return r;
-}
-
-MINLINE float diffuse_shv3(float sh[9], const float v[3])
-{
- /* See formula (13) in:
- * "An Efficient Representation for Irradiance Environment Maps" */
- static const float c1 = 0.429043f, c2 = 0.511664f, c3 = 0.743125f;
- static const float c4 = 0.886227f, c5 = 0.247708f;
- float x, y, z, sum;
-
- x = v[0];
- y = v[1];
- z = v[2];
-
- sum = c1 * sh[8] * (x * x - y * y);
- sum += c3 * sh[6] * z * z;
- sum += c4 * sh[0];
- sum += -c5 * sh[6];
- sum += 2.0f * c1 * (sh[4] * x * y + sh[7] * x * z + sh[5] * y * z);
- sum += 2.0f * c2 * (sh[3] * x + sh[1] * y + sh[2] * z);
-
- return sum;
-}
-
-MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f)
-{
- /* See formula (3) in:
- * "An Efficient Representation for Irradiance Environment Maps" */
- float sh[9], x, y, z;
-
- x = v[0];
- y = v[1];
- z = v[2];
-
- sh[0] = 0.282095f;
-
- sh[1] = 0.488603f * y;
- sh[2] = 0.488603f * z;
- sh[3] = 0.488603f * x;
-
- sh[4] = 1.092548f * x * y;
- sh[5] = 1.092548f * y * z;
- sh[6] = 0.315392f * (3.0f * z * z - 1.0f);
- sh[7] = 1.092548f * x * z;
- sh[8] = 0.546274f * (x * x - y * y);
-
- mul_sh_fl(sh, f);
- copy_sh_sh(r, sh);
-}
-
-MINLINE float eval_shv3(float sh[9], const float v[3])
-{
- float tmp[9];
-
- vec_fac_to_sh(tmp, v, 1.0f);
- return dot_shsh(tmp, sh);
-}
-
-MINLINE void madd_sh_shfl(float r[9], const float sh[9], const float f)
-{
- float tmp[9];
-
- copy_sh_sh(tmp, sh);
- mul_sh_fl(tmp, f);
- add_sh_shsh(r, r, tmp);
-}
-
-#endif /* __MATH_GEOM_INLINE_C__ */
Index: source/blender/blenlib/intern/math_geom_inline.h
===================================================================
--- source/blender/blenlib/intern/math_geom_inline.h (revision 0)
+++ source/blender/blenlib/intern/math_geom_inline.h (working copy)
@@ -0,0 +1,140 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
+ * */
+
+/** \file blender/blenlib/intern/math_geom_inline.c
+ * \ingroup bli
+ */
+
+
+#include "BLI_math.h"
+
+#ifndef __MATH_GEOM_INLINE_C__
+#define __MATH_GEOM_INLINE_C__
+
+/****************************** Spherical Harmonics **************************/
+
+MINLINE void zero_sh(float r[9])
+{
+ memset(r, 0, sizeof(float) * 9);
+}
+
+MINLINE void copy_sh_sh(float r[9], const float a[9])
+{
+ memcpy(r, a, sizeof(float) * 9);
+}
+
+MINLINE void mul_sh_fl(float r[9], const float f)
+{
+ int i;
+
+ for (i = 0; i < 9; i++)
+ r[i] *= f;
+}
+
+MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9])
+{
+ int i;
+
+ for (i = 0; i < 9; i++)
+ r[i] = a[i] + b[i];
+}
+
+MINLINE float dot_shsh(float a[9], float b[9])
+{
+ float r = 0.0f;
+ int i;
+
+ for (i = 0; i < 9; i++)
+ r += a[i] * b[i];
+
+ return r;
+}
+
+MINLINE float diffuse_shv3(float sh[9], const float v[3])
+{
+ /* See formula (13) in:
+ * "An Efficient Representation for Irradiance Environment Maps" */
+ static const float c1 = 0.429043f, c2 = 0.511664f, c3 = 0.743125f;
+ static const float c4 = 0.886227f, c5 = 0.247708f;
+ float x, y, z, sum;
+
+ x = v[0];
+ y = v[1];
+ z = v[2];
+
+ sum = c1 * sh[8] * (x * x - y * y);
+ sum += c3 * sh[6] * z * z;
+ sum += c4 * sh[0];
+ sum += -c5 * sh[6];
+ sum += 2.0f * c1 * (sh[4] * x * y + sh[7] * x * z + sh[5] * y * z);
+ sum += 2.0f * c2 * (sh[3] * x + sh[1] * y + sh[2] * z);
+
+ return sum;
+}
+
+MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f)
+{
+ /* See formula (3) in:
+ * "An Efficient Representation for Irradiance Environment Maps" */
+ float sh[9], x, y, z;
+
+ x = v[0];
+ y = v[1];
+ z = v[2];
+
+ sh[0] = 0.282095f;
+
+ sh[1] = 0.488603f * y;
+ sh[2] = 0.488603f * z;
+ sh[3] = 0.488603f * x;
+
+ sh[4] = 1.092548f * x * y;
+ sh[5] = 1.092548f * y * z;
+ sh[6] = 0.315392f * (3.0f * z * z - 1.0f);
+ sh[7] = 1.092548f * x * z;
+ sh[8] = 0.546274f * (x * x - y * y);
+
+ mul_sh_fl(sh, f);
+ copy_sh_sh(r, sh);
+}
+
+MINLINE float eval_shv3(float sh[9], const float v[3])
+{
+ float tmp[9];
+
+ vec_fac_to_sh(tmp, v, 1.0f);
+ return dot_shsh(tmp, sh);
+}
+
+MINLINE void madd_sh_shfl(float r[9], const float sh[9], const float f)
+{
+ float tmp[9];
+
+ copy_sh_sh(tmp, sh);
+ mul_sh_fl(tmp, f);
+ add_sh_shsh(r, r, tmp);
+}
+
+#endif /* __MATH_GEOM_INLINE_C__ */
Index: source/blender/blenlib/intern/math_geom_inline.h
===================================================================
--- source/blender/blenlib/intern/math_geom_inline.h (revision 45655)
+++ source/blender/blenlib/intern/math_geom_inline.h (working copy)
Property changes on: source/blender/blenlib/intern/math_geom_inline.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- source/blender/blenlib/intern/math_vector_inline.c (revision 45655)
+++ source/blender/blenlib/intern/math_vector_inline.c (working copy)
@@ -1,707 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
- * */
-
-/** \file blender/blenlib/intern/math_vector_inline.c
- * \ingroup bli
- */
-
-
-#include "BLI_math.h"
-
-#ifndef __MATH_VECTOR_INLINE_C__
-#define __MATH_VECTOR_INLINE_C__
-
-/********************************** Init *************************************/
-
-MINLINE void zero_v2(float r[2])
-{
- r[0] = 0.0f;
- r[1] = 0.0f;
-}
-
-MINLINE void zero_v3(float r[3])
-{
- r[0] = 0.0f;
- r[1] = 0.0f;
- r[2] = 0.0f;
-}
-
-MINLINE void zero_v4(float r[4])
-{
- r[0] = 0.0f;
- r[1] = 0.0f;
- r[2] = 0.0f;
- r[3] = 0.0f;
-}
-
-MINLINE void copy_v2_v2(float r[2], const float a[2])
-{
- r[0] = a[0];
- r[1] = a[1];
-}
-
-MINLINE void copy_v3_v3(float r[3], const float a[3])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
-}
-
-MINLINE void copy_v4_v4(float r[4], const float a[4])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
- r[3] = a[3];
-}
-
-MINLINE void copy_v2_fl(float r[2], float f)
-{
- r[0] = f;
- r[1] = f;
-}
-
-MINLINE void copy_v3_fl(float r[3], float f)
-{
- r[0] = f;
- r[1] = f;
- r[2] = f;
-}
-
-MINLINE void copy_v4_fl(float r[4], float f)
-{
- r[0] = f;
- r[1] = f;
- r[2] = f;
- r[3] = f;
-}
-
-/* short */
-MINLINE void copy_v2_v2_char(char r[2], const char a[2])
-{
- r[0] = a[0];
- r[1] = a[1];
-}
-
-MINLINE void copy_v3_v3_char(char r[3], const char a[3])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
-}
-
-MINLINE void copy_v4_v4_char(char r[4], const char a[4])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
- r[3] = a[3];
-}
-
-/* short */
-MINLINE void copy_v2_v2_short(short r[2], const short a[2])
-{
- r[0] = a[0];
- r[1] = a[1];
-}
-
-MINLINE void copy_v3_v3_short(short r[3], const short a[3])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
-}
-
-MINLINE void copy_v4_v4_short(short r[4], const short a[4])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
- r[3] = a[3];
-}
-
-/* int */
-MINLINE void copy_v2_v2_int(int r[2], const int a[2])
-{
- r[0] = a[0];
- r[1] = a[1];
-}
-
-MINLINE void copy_v3_v3_int(int r[3], const int a[3])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
-}
-
-MINLINE void copy_v4_v4_int(int r[4], const int a[4])
-{
- r[0] = a[0];
- r[1] = a[1];
- r[2] = a[2];
- r[3] = a[3];
-}
-
-/* double -> float */
-MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
-{
- r[0] = (float)a[0];
- r[1] = (float)a[1];
-}
-
-MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
-{
- r[0] = (float)a[0];
- r[1] = (float)a[1];
- r[2] = (float)a[2];
-}
-
-MINLINE void copy_v4fl_v4db(float r[4], const double a[4])
-{
- r[0] = (float)a[0];
- r[1] = (float)a[1];
- r[2] = (float)a[2];
- r[3] = (float)a[3];
-}
-
-/* float -> double */
-MINLINE void copy_v2db_v2fl(double r[2], const float a[2])
-{
- r[0] = (double)a[0];
- r[1] = (double)a[1];
-}
-
-MINLINE void copy_v3db_v3fl(double r[3], const float a[3])
-{
- r[0] = (double)a[0];
- r[1] = (double)a[1];
- r[2] = (double)a[2];
-}
-
-MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
-{
- r[0] = (double)a[0];
- r[1] = (double)a[1];
- r[2] = (double)a[2];
- r[3] = (double)a[3];
-}
-
-MINLINE void swap_v2_v2(float a[2], float b[2])
-{
- SWAP(float, a[0], b[0]);
- SWAP(float, a[1], b[1]);
-}
-
-MINLINE void swap_v3_v3(float a[3], float b[3])
-{
- SWAP(float, a[0], b[0]);
- SWAP(float, a[1], b[1]);
- SWAP(float, a[2], b[2]);
-}
-
-MINLINE void swap_v4_v4(float a[4], float b[4])
-{
- SWAP(float, a[0], b[0]);
- SWAP(float, a[1], b[1]);
- SWAP(float, a[2], b[2]);
- SWAP(float, a[3], b[3]);
-}
-
-/********************************* Arithmetic ********************************/
-
-MINLINE void add_v3_fl(float r[3], float f)
-{
- r[0] += f;
- r[1] += f;
- r[2] += f;
-}
-
-MINLINE void add_v4_fl(float r[4], float f)
-{
- r[0] += f;
- r[1] += f;
- r[2] += f;
- r[3] += f;
-}
-
-MINLINE void add_v2_v2(float r[2], const float a[2])
-{
- r[0] += a[0];
- r[1] += a[1];
-}
-
-MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
-{
- r[0] = a[0] + b[0];
- r[1] = a[1] + b[1];
-}
-
-MINLINE void add_v3_v3(float r[3], const float a[3])
-{
- r[0] += a[0];
- r[1] += a[1];
- r[2] += a[2];
-}
-
-MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
-{
- r[0] = a[0] + b[0];
- r[1] = a[1] + b[1];
- r[2] = a[2] + b[2];
-}
-
-MINLINE void sub_v2_v2(float r[2], const float a[2])
-{
- r[0] -= a[0];
- r[1] -= a[1];
-}
-
-MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
-{
- r[0] = a[0] - b[0];
- r[1] = a[1] - b[1];
-}
-
-MINLINE void sub_v3_v3(float r[3], const float a[3])
-{
- r[0] -= a[0];
- r[1] -= a[1];
- r[2] -= a[2];
-}
-
-MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
-{
- r[0] = a[0] - b[0];
- r[1] = a[1] - b[1];
- r[2] = a[2] - b[2];
-}
-
-MINLINE void sub_v4_v4(float r[4], const float a[4])
-{
- r[0] -= a[0];
- r[1] -= a[1];
- r[2] -= a[2];
- r[3] -= a[3];
-}
-
-MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
-{
- r[0] = a[0] - b[0];
- r[1] = a[1] - b[1];
- r[2] = a[2] - b[2];
- r[3] = a[3] - b[3];
-}
-
-MINLINE void mul_v2_fl(float r[2], float f)
-{
- r[0] *= f;
- r[1] *= f;
-}
-
-MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
-{
- r[0] = a[0] * f;
- r[1] = a[1] * f;
-}
-
-MINLINE void mul_v3_fl(float r[3], float f)
-{
- r[0] *= f;
- r[1] *= f;
- r[2] *= f;
-}
-
-MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
-{
- r[0] = a[0] * f;
- r[1] = a[1] * f;
- r[2] = a[2] * f;
-}
-
-MINLINE void mul_v2_v2(float r[2], const float a[2])
-{
- r[0] *= a[0];
- r[1] *= a[1];
-}
-
-MINLINE void mul_v3_v3(float r[3], const float a[3])
-{
- r[0] *= a[0];
- r[1] *= a[1];
- r[2] *= a[2];
-}
-
-MINLINE void mul_v4_fl(float r[4], float f)
-{
- r[0] *= f;
- r[1] *= f;
- r[2] *= f;
- r[3] *= f;
-}
-
-MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
-{
- r[0] += a[0] * f;
- r[1] += a[1] * f;
-}
-
-MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
-{
- r[0] += a[0] * f;
- r[1] += a[1] * f;
- r[2] += a[2] * f;
-}
-
-MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
-{
- r[0] += a[0] * b[0];
- r[1] += a[1] * b[1];
- r[2] += a[2] * b[2];
-}
-
-MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
-{
- r[0] = a[0] + b[0] * f;
- r[1] = a[1] + b[1] * f;
-}
-
-MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
-{
- r[0] = a[0] + b[0] * f;
- r[1] = a[1] + b[1] * f;
- r[2] = a[2] + b[2] * f;
-}
-
-MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
-{
- r[0] = a[0] + b[0] * c[0];
- r[1] = a[1] + b[1] * c[1];
- r[2] = a[2] + b[2] * c[2];
-}
-
-MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
-{
- r[0] += a[0] * f;
- r[1] += a[1] * f;
- r[2] += a[2] * f;
- r[3] += a[3] * f;
-}
-
-MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
-{
- r[0] = v1[0] * v2[0];
- r[1] = v1[1] * v2[1];
- r[2] = v1[2] * v2[2];
-}
-
-MINLINE void negate_v2(float r[3])
-{
- r[0] = -r[0];
- r[1] = -r[1];
-}
-
-MINLINE void negate_v2_v2(float r[2], const float a[2])
-{
- r[0] = -a[0];
- r[1] = -a[1];
-}
-
-MINLINE void negate_v3(float r[3])
-{
- r[0] = -r[0];
- r[1] = -r[1];
- r[2] = -r[2];
-}
-
-MINLINE void negate_v3_v3(float r[3], const float a[3])
-{
- r[0] = -a[0];
- r[1] = -a[1];
- r[2] = -a[2];
-}
-
-MINLINE void negate_v4(float r[4])
-{
- r[0] = -r[0];
- r[1] = -r[1];
- r[2] = -r[2];
- r[3] = -r[3];
-}
-
-MINLINE void negate_v4_v4(float r[4], const float a[4])
-{
- r[0] = -a[0];
- r[1] = -a[1];
- r[2] = -a[2];
- r[3] = -a[3];
-}
-
-MINLINE float dot_v2v2(const float a[2], const float b[2])
-{
- return a[0] * b[0] + a[1] * b[1];
-}
-
-MINLINE float dot_v3v3(const float a[3], const float b[3])
-{
- return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
-}
-
-MINLINE float cross_v2v2(const float a[2], const float b[2])
-{
- return a[0] * b[1] - a[1] * b[0];
-}
-
-MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
-{
- r[0] = a[1] * b[2] - a[2] * b[1];
- r[1] = a[2] * b[0] - a[0] * b[2];
- r[2] = a[0] * b[1] - a[1] * b[0];
-}
-
-MINLINE void star_m3_v3(float rmat[][3], float a[3])
-{
- rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
- rmat[0][1] = -a[2];
- rmat[0][2] = a[1];
- rmat[1][0] = a[2];
- rmat[1][2] = -a[0];
- rmat[2][0] = -a[1];
- rmat[2][1] = a[0];
-}
-
-/*********************************** Length **********************************/
-
-MINLINE float len_squared_v2(const float v[2])
-{
- return v[0] * v[0] + v[1] * v[1];
-}
-
-MINLINE float len_squared_v3(const float v[3])
-{
- return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
-}
-
-MINLINE float len_v2(const float v[2])
-{
- return (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
-}
-
-MINLINE float len_v2v2(const float v1[2], const float v2[2])
-{
- float x, y;
-
- x = v1[0] - v2[0];
- y = v1[1] - v2[1];
- return (float)sqrtf(x * x + y * y);
-}
-
-MINLINE float len_v3(const float a[3])
-{
- return sqrtf(dot_v3v3(a, a));
-}
-
-MINLINE float len_squared_v2v2(const float a[2], const float b[2])
-{
- float d[2];
-
- sub_v2_v2v2(d, b, a);
- return dot_v2v2(d, d);
-}
-
-MINLINE float len_v3v3(const float a[3], const float b[3])
-{
- float d[3];
-
- sub_v3_v3v3(d, b, a);
- return len_v3(d);
-}
-
-MINLINE float len_squared_v3v3(const float a[3], const float b[3])
-{
- float d[3];
-
- sub_v3_v3v3(d, b, a);
- return dot_v3v3(d, d);
-}
-
-MINLINE float normalize_v2_v2(float r[2], const float a[2])
-{
- float d = dot_v2v2(a, a);
-
- if (d > 1.0e-35f) {
- d = sqrtf(d);
- mul_v2_v2fl(r, a, 1.0f / d);
- }
- else {
- zero_v2(r);
- d = 0.0f;
- }
-
- return d;
-}
-
-MINLINE float normalize_v2(float n[2])
-{
- return normalize_v2_v2(n, n);
-}
-
-MINLINE float normalize_v3_v3(float r[3], const float a[3])
-{
- float d = dot_v3v3(a, a);
-
- /* a larger value causes normalize errors in a
- * scaled down models with camera xtreme close */
- if (d > 1.0e-35f) {
- d = sqrtf(d);
- mul_v3_v3fl(r, a, 1.0f / d);
- }
- else {
- zero_v3(r);
- d = 0.0f;
- }
-
- return d;
-}
-
-MINLINE double normalize_v3_d(double n[3])
-{
- double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
-
- /* a larger value causes normalize errors in a
- * scaled down models with camera xtreme close */
- if (d > 1.0e-35) {
- double mul;
-
- d = sqrt(d);
- mul = 1.0 / d;
-
- n[0] *= mul;
- n[1] *= mul;
- n[2] *= mul;
- }
- else {
- n[0] = n[1] = n[2] = 0;
- d = 0.0;
- }
-
- return d;
-}
-
-MINLINE float normalize_v3(float n[3])
-{
- return normalize_v3_v3(n, n);
-}
-
-MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
-{
- out[0] = in[0] * (1.0f / 32767.0f);
- out[1] = in[1] * (1.0f / 32767.0f);
- out[2] = in[2] * (1.0f / 32767.0f);
-}
-
-MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
-{
- out[0] = (short) (in[0] * 32767.0f);
- out[1] = (short) (in[1] * 32767.0f);
- out[2] = (short) (in[2] * 32767.0f);
-}
-
-/********************************* Comparison ********************************/
-
-
-MINLINE int is_zero_v2(const float v[3])
-{
- return (v[0] == 0 && v[1] == 0);
-}
-
-MINLINE int is_zero_v3(const float v[3])
-{
- return (v[0] == 0 && v[1] == 0 && v[2] == 0);
-}
-
-MINLINE int is_zero_v4(const float v[4])
-{
- return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
-}
-
-MINLINE int is_one_v3(const float v[3])
-{
- return (v[0] == 1 && v[1] == 1 && v[2] == 1);
-}
-
-MINLINE int equals_v2v2(const float v1[2], const float v2[2])
-{
- return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
-}
-
-MINLINE int equals_v3v3(const float v1[3], const float v2[3])
-{
- return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
-}
-
-MINLINE int equals_v4v4(const float v1[4], const float v2[4])
-{
- return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
-}
-
-MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit)
-{
- if (fabsf(v1[0] - v2[0]) < limit)
- if (fabsf(v1[1] - v2[1]) < limit)
- if (fabsf(v1[2] - v2[2]) < limit)
- return 1;
-
- return 0;
-}
-
-MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
-{
- float x, y, z;
-
- x = v1[0] - v2[0];
- y = v1[1] - v2[1];
- z = v1[2] - v2[2];
-
- return ((x * x + y * y + z * z) < (limit * limit));
-}
-
-MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit)
-{
- if (fabsf(v1[0] - v2[0]) < limit)
- if (fabsf(v1[1] - v2[1]) < limit)
- if (fabsf(v1[2] - v2[2]) < limit)
- if (fabsf(v1[3] - v2[3]) < limit)
- return 1;
-
- return 0;
-}
-
-MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
-{
- return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
- ((l2[0] - pt[0]) * (l1[1] - pt[1])));
-}
-
-#endif /* __MATH_VECTOR_INLINE_C__ */
Index: source/blender/blenlib/intern/math_vector_inline.h
===================================================================
--- source/blender/blenlib/intern/math_vector_inline.h (revision 0)
+++ source/blender/blenlib/intern/math_vector_inline.h (working copy)
@@ -0,0 +1,707 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
+ * */
+
+/** \file blender/blenlib/intern/math_vector_inline.c
+ * \ingroup bli
+ */
+
+
+#include "BLI_math.h"
+
+#ifndef __MATH_VECTOR_INLINE_C__
+#define __MATH_VECTOR_INLINE_C__
+
+/********************************** Init *************************************/
+
+MINLINE void zero_v2(float r[2])
+{
+ r[0] = 0.0f;
+ r[1] = 0.0f;
+}
+
+MINLINE void zero_v3(float r[3])
+{
+ r[0] = 0.0f;
+ r[1] = 0.0f;
+ r[2] = 0.0f;
+}
+
+MINLINE void zero_v4(float r[4])
+{
+ r[0] = 0.0f;
+ r[1] = 0.0f;
+ r[2] = 0.0f;
+ r[3] = 0.0f;
+}
+
+MINLINE void copy_v2_v2(float r[2], const float a[2])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+}
+
+MINLINE void copy_v3_v3(float r[3], const float a[3])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+}
+
+MINLINE void copy_v4_v4(float r[4], const float a[4])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+ r[3] = a[3];
+}
+
+MINLINE void copy_v2_fl(float r[2], float f)
+{
+ r[0] = f;
+ r[1] = f;
+}
+
+MINLINE void copy_v3_fl(float r[3], float f)
+{
+ r[0] = f;
+ r[1] = f;
+ r[2] = f;
+}
+
+MINLINE void copy_v4_fl(float r[4], float f)
+{
+ r[0] = f;
+ r[1] = f;
+ r[2] = f;
+ r[3] = f;
+}
+
+/* short */
+MINLINE void copy_v2_v2_char(char r[2], const char a[2])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+}
+
+MINLINE void copy_v3_v3_char(char r[3], const char a[3])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+}
+
+MINLINE void copy_v4_v4_char(char r[4], const char a[4])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+ r[3] = a[3];
+}
+
+/* short */
+MINLINE void copy_v2_v2_short(short r[2], const short a[2])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+}
+
+MINLINE void copy_v3_v3_short(short r[3], const short a[3])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+}
+
+MINLINE void copy_v4_v4_short(short r[4], const short a[4])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+ r[3] = a[3];
+}
+
+/* int */
+MINLINE void copy_v2_v2_int(int r[2], const int a[2])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+}
+
+MINLINE void copy_v3_v3_int(int r[3], const int a[3])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+}
+
+MINLINE void copy_v4_v4_int(int r[4], const int a[4])
+{
+ r[0] = a[0];
+ r[1] = a[1];
+ r[2] = a[2];
+ r[3] = a[3];
+}
+
+/* double -> float */
+MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
+{
+ r[0] = (float)a[0];
+ r[1] = (float)a[1];
+}
+
+MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
+{
+ r[0] = (float)a[0];
+ r[1] = (float)a[1];
+ r[2] = (float)a[2];
+}
+
+MINLINE void copy_v4fl_v4db(float r[4], const double a[4])
+{
+ r[0] = (float)a[0];
+ r[1] = (float)a[1];
+ r[2] = (float)a[2];
+ r[3] = (float)a[3];
+}
+
+/* float -> double */
+MINLINE void copy_v2db_v2fl(double r[2], const float a[2])
+{
+ r[0] = (double)a[0];
+ r[1] = (double)a[1];
+}
+
+MINLINE void copy_v3db_v3fl(double r[3], const float a[3])
+{
+ r[0] = (double)a[0];
+ r[1] = (double)a[1];
+ r[2] = (double)a[2];
+}
+
+MINLINE void copy_v4db_v4fl(double r[4], const float a[4])
+{
+ r[0] = (double)a[0];
+ r[1] = (double)a[1];
+ r[2] = (double)a[2];
+ r[3] = (double)a[3];
+}
+
+MINLINE void swap_v2_v2(float a[2], float b[2])
+{
+ SWAP(float, a[0], b[0]);
+ SWAP(float, a[1], b[1]);
+}
+
+MINLINE void swap_v3_v3(float a[3], float b[3])
+{
+ SWAP(float, a[0], b[0]);
+ SWAP(float, a[1], b[1]);
+ SWAP(float, a[2], b[2]);
+}
+
+MINLINE void swap_v4_v4(float a[4], float b[4])
+{
+ SWAP(float, a[0], b[0]);
+ SWAP(float, a[1], b[1]);
+ SWAP(float, a[2], b[2]);
+ SWAP(float, a[3], b[3]);
+}
+
+/********************************* Arithmetic ********************************/
+
+MINLINE void add_v3_fl(float r[3], float f)
+{
+ r[0] += f;
+ r[1] += f;
+ r[2] += f;
+}
+
+MINLINE void add_v4_fl(float r[4], float f)
+{
+ r[0] += f;
+ r[1] += f;
+ r[2] += f;
+ r[3] += f;
+}
+
+MINLINE void add_v2_v2(float r[2], const float a[2])
+{
+ r[0] += a[0];
+ r[1] += a[1];
+}
+
+MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
+{
+ r[0] = a[0] + b[0];
+ r[1] = a[1] + b[1];
+}
+
+MINLINE void add_v3_v3(float r[3], const float a[3])
+{
+ r[0] += a[0];
+ r[1] += a[1];
+ r[2] += a[2];
+}
+
+MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
+{
+ r[0] = a[0] + b[0];
+ r[1] = a[1] + b[1];
+ r[2] = a[2] + b[2];
+}
+
+MINLINE void sub_v2_v2(float r[2], const float a[2])
+{
+ r[0] -= a[0];
+ r[1] -= a[1];
+}
+
+MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
+{
+ r[0] = a[0] - b[0];
+ r[1] = a[1] - b[1];
+}
+
+MINLINE void sub_v3_v3(float r[3], const float a[3])
+{
+ r[0] -= a[0];
+ r[1] -= a[1];
+ r[2] -= a[2];
+}
+
+MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
+{
+ r[0] = a[0] - b[0];
+ r[1] = a[1] - b[1];
+ r[2] = a[2] - b[2];
+}
+
+MINLINE void sub_v4_v4(float r[4], const float a[4])
+{
+ r[0] -= a[0];
+ r[1] -= a[1];
+ r[2] -= a[2];
+ r[3] -= a[3];
+}
+
+MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
+{
+ r[0] = a[0] - b[0];
+ r[1] = a[1] - b[1];
+ r[2] = a[2] - b[2];
+ r[3] = a[3] - b[3];
+}
+
+MINLINE void mul_v2_fl(float r[2], float f)
+{
+ r[0] *= f;
+ r[1] *= f;
+}
+
+MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
+{
+ r[0] = a[0] * f;
+ r[1] = a[1] * f;
+}
+
+MINLINE void mul_v3_fl(float r[3], float f)
+{
+ r[0] *= f;
+ r[1] *= f;
+ r[2] *= f;
+}
+
+MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
+{
+ r[0] = a[0] * f;
+ r[1] = a[1] * f;
+ r[2] = a[2] * f;
+}
+
+MINLINE void mul_v2_v2(float r[2], const float a[2])
+{
+ r[0] *= a[0];
+ r[1] *= a[1];
+}
+
+MINLINE void mul_v3_v3(float r[3], const float a[3])
+{
+ r[0] *= a[0];
+ r[1] *= a[1];
+ r[2] *= a[2];
+}
+
+MINLINE void mul_v4_fl(float r[4], float f)
+{
+ r[0] *= f;
+ r[1] *= f;
+ r[2] *= f;
+ r[3] *= f;
+}
+
+MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
+{
+ r[0] += a[0] * f;
+ r[1] += a[1] * f;
+}
+
+MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
+{
+ r[0] += a[0] * f;
+ r[1] += a[1] * f;
+ r[2] += a[2] * f;
+}
+
+MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3])
+{
+ r[0] += a[0] * b[0];
+ r[1] += a[1] * b[1];
+ r[2] += a[2] * b[2];
+}
+
+MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f)
+{
+ r[0] = a[0] + b[0] * f;
+ r[1] = a[1] + b[1] * f;
+}
+
+MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
+{
+ r[0] = a[0] + b[0] * f;
+ r[1] = a[1] + b[1] * f;
+ r[2] = a[2] + b[2] * f;
+}
+
+MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
+{
+ r[0] = a[0] + b[0] * c[0];
+ r[1] = a[1] + b[1] * c[1];
+ r[2] = a[2] + b[2] * c[2];
+}
+
+MINLINE void madd_v4_v4fl(float r[4], const float a[4], float f)
+{
+ r[0] += a[0] * f;
+ r[1] += a[1] * f;
+ r[2] += a[2] * f;
+ r[3] += a[3] * f;
+}
+
+MINLINE void mul_v3_v3v3(float r[3], const float v1[3], const float v2[3])
+{
+ r[0] = v1[0] * v2[0];
+ r[1] = v1[1] * v2[1];
+ r[2] = v1[2] * v2[2];
+}
+
+MINLINE void negate_v2(float r[3])
+{
+ r[0] = -r[0];
+ r[1] = -r[1];
+}
+
+MINLINE void negate_v2_v2(float r[2], const float a[2])
+{
+ r[0] = -a[0];
+ r[1] = -a[1];
+}
+
+MINLINE void negate_v3(float r[3])
+{
+ r[0] = -r[0];
+ r[1] = -r[1];
+ r[2] = -r[2];
+}
+
+MINLINE void negate_v3_v3(float r[3], const float a[3])
+{
+ r[0] = -a[0];
+ r[1] = -a[1];
+ r[2] = -a[2];
+}
+
+MINLINE void negate_v4(float r[4])
+{
+ r[0] = -r[0];
+ r[1] = -r[1];
+ r[2] = -r[2];
+ r[3] = -r[3];
+}
+
+MINLINE void negate_v4_v4(float r[4], const float a[4])
+{
+ r[0] = -a[0];
+ r[1] = -a[1];
+ r[2] = -a[2];
+ r[3] = -a[3];
+}
+
+MINLINE float dot_v2v2(const float a[2], const float b[2])
+{
+ return a[0] * b[0] + a[1] * b[1];
+}
+
+MINLINE float dot_v3v3(const float a[3], const float b[3])
+{
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
+}
+
+MINLINE float cross_v2v2(const float a[2], const float b[2])
+{
+ return a[0] * b[1] - a[1] * b[0];
+}
+
+MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
+{
+ r[0] = a[1] * b[2] - a[2] * b[1];
+ r[1] = a[2] * b[0] - a[0] * b[2];
+ r[2] = a[0] * b[1] - a[1] * b[0];
+}
+
+MINLINE void star_m3_v3(float rmat[][3], float a[3])
+{
+ rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
+ rmat[0][1] = -a[2];
+ rmat[0][2] = a[1];
+ rmat[1][0] = a[2];
+ rmat[1][2] = -a[0];
+ rmat[2][0] = -a[1];
+ rmat[2][1] = a[0];
+}
+
+/*********************************** Length **********************************/
+
+MINLINE float len_squared_v2(const float v[2])
+{
+ return v[0] * v[0] + v[1] * v[1];
+}
+
+MINLINE float len_squared_v3(const float v[3])
+{
+ return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
+}
+
+MINLINE float len_v2(const float v[2])
+{
+ return (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
+}
+
+MINLINE float len_v2v2(const float v1[2], const float v2[2])
+{
+ float x, y;
+
+ x = v1[0] - v2[0];
+ y = v1[1] - v2[1];
+ return (float)sqrtf(x * x + y * y);
+}
+
+MINLINE float len_v3(const float a[3])
+{
+ return sqrtf(dot_v3v3(a, a));
+}
+
+MINLINE float len_squared_v2v2(const float a[2], const float b[2])
+{
+ float d[2];
+
+ sub_v2_v2v2(d, b, a);
+ return dot_v2v2(d, d);
+}
+
+MINLINE float len_v3v3(const float a[3], const float b[3])
+{
+ float d[3];
+
+ sub_v3_v3v3(d, b, a);
+ return len_v3(d);
+}
+
+MINLINE float len_squared_v3v3(const float a[3], const float b[3])
+{
+ float d[3];
+
+ sub_v3_v3v3(d, b, a);
+ return dot_v3v3(d, d);
+}
+
+MINLINE float normalize_v2_v2(float r[2], const float a[2])
+{
+ float d = dot_v2v2(a, a);
+
+ if (d > 1.0e-35f) {
+ d = sqrtf(d);
+ mul_v2_v2fl(r, a, 1.0f / d);
+ }
+ else {
+ zero_v2(r);
+ d = 0.0f;
+ }
+
+ return d;
+}
+
+MINLINE float normalize_v2(float n[2])
+{
+ return normalize_v2_v2(n, n);
+}
+
+MINLINE float normalize_v3_v3(float r[3], const float a[3])
+{
+ float d = dot_v3v3(a, a);
+
+ /* a larger value causes normalize errors in a
+ * scaled down models with camera xtreme close */
+ if (d > 1.0e-35f) {
+ d = sqrtf(d);
+ mul_v3_v3fl(r, a, 1.0f / d);
+ }
+ else {
+ zero_v3(r);
+ d = 0.0f;
+ }
+
+ return d;
+}
+
+MINLINE double normalize_v3_d(double n[3])
+{
+ double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
+
+ /* a larger value causes normalize errors in a
+ * scaled down models with camera xtreme close */
+ if (d > 1.0e-35) {
+ double mul;
+
+ d = sqrt(d);
+ mul = 1.0 / d;
+
+ n[0] *= mul;
+ n[1] *= mul;
+ n[2] *= mul;
+ }
+ else {
+ n[0] = n[1] = n[2] = 0;
+ d = 0.0;
+ }
+
+ return d;
+}
+
+MINLINE float normalize_v3(float n[3])
+{
+ return normalize_v3_v3(n, n);
+}
+
+MINLINE void normal_short_to_float_v3(float out[3], const short in[3])
+{
+ out[0] = in[0] * (1.0f / 32767.0f);
+ out[1] = in[1] * (1.0f / 32767.0f);
+ out[2] = in[2] * (1.0f / 32767.0f);
+}
+
+MINLINE void normal_float_to_short_v3(short out[3], const float in[3])
+{
+ out[0] = (short) (in[0] * 32767.0f);
+ out[1] = (short) (in[1] * 32767.0f);
+ out[2] = (short) (in[2] * 32767.0f);
+}
+
+/********************************* Comparison ********************************/
+
+
+MINLINE int is_zero_v2(const float v[3])
+{
+ return (v[0] == 0 && v[1] == 0);
+}
+
+MINLINE int is_zero_v3(const float v[3])
+{
+ return (v[0] == 0 && v[1] == 0 && v[2] == 0);
+}
+
+MINLINE int is_zero_v4(const float v[4])
+{
+ return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0);
+}
+
+MINLINE int is_one_v3(const float v[3])
+{
+ return (v[0] == 1 && v[1] == 1 && v[2] == 1);
+}
+
+MINLINE int equals_v2v2(const float v1[2], const float v2[2])
+{
+ return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
+}
+
+MINLINE int equals_v3v3(const float v1[3], const float v2[3])
+{
+ return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]));
+}
+
+MINLINE int equals_v4v4(const float v1[4], const float v2[4])
+{
+ return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && (v1[3] == v2[3]));
+}
+
+MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit)
+{
+ if (fabsf(v1[0] - v2[0]) < limit)
+ if (fabsf(v1[1] - v2[1]) < limit)
+ if (fabsf(v1[2] - v2[2]) < limit)
+ return 1;
+
+ return 0;
+}
+
+MINLINE int compare_len_v3v3(const float v1[3], const float v2[3], const float limit)
+{
+ float x, y, z;
+
+ x = v1[0] - v2[0];
+ y = v1[1] - v2[1];
+ z = v1[2] - v2[2];
+
+ return ((x * x + y * y + z * z) < (limit * limit));
+}
+
+MINLINE int compare_v4v4(const float v1[4], const float v2[4], const float limit)
+{
+ if (fabsf(v1[0] - v2[0]) < limit)
+ if (fabsf(v1[1] - v2[1]) < limit)
+ if (fabsf(v1[2] - v2[2]) < limit)
+ if (fabsf(v1[3] - v2[3]) < limit)
+ return 1;
+
+ return 0;
+}
+
+MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2])
+{
+ return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
+ ((l2[0] - pt[0]) * (l1[1] - pt[1])));
+}
+
+#endif /* __MATH_VECTOR_INLINE_C__ */
Index: source/blender/blenlib/intern/math_vector_inline.h
===================================================================
--- source/blender/blenlib/intern/math_vector_inline.h (revision 45655)
+++ source/blender/blenlib/intern/math_vector_inline.h (working copy)
Property changes on: source/blender/blenlib/intern/math_vector_inline.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9c/7f/210e79d43e09f90b6b3bdafd6e36

Event Timeline