mathutils
Advanced tools
| /* | ||
| * ***** 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. | ||
| * | ||
| * ***** END GPL LICENSE BLOCK ***** | ||
| */ | ||
| #ifndef __BLI_SYSTEM_H__ | ||
| #define __BLI_SYSTEM_H__ | ||
| #include <stdio.h> | ||
| /** \file BLI_system.h | ||
| * \ingroup bli | ||
| */ | ||
| int BLI_cpu_support_sse2(void); | ||
| void BLI_system_backtrace(FILE *fp); | ||
| /* getpid */ | ||
| #ifdef WIN32 | ||
| # define BLI_SYSTEM_PID_H <process.h> | ||
| #else | ||
| # define BLI_SYSTEM_PID_H <unistd.h> | ||
| #endif | ||
| #endif /* __BLI_SYSTEM_H__ */ |
+2
-2
@@ -204,3 +204,3 @@ # This is the CMakeCache file. | ||
| //Minor version of cmake used to create the current loaded cache | ||
| CMAKE_CACHE_MINOR_VERSION:INTERNAL=5 | ||
| CMAKE_CACHE_MINOR_VERSION:INTERNAL=6 | ||
| //Patch version of cmake used to create the current loaded cache | ||
@@ -296,3 +296,3 @@ CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 | ||
| //Path to CMake installation. | ||
| CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.5 | ||
| CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.6 | ||
| //ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS | ||
@@ -299,0 +299,0 @@ CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 |
+8
-1
@@ -70,2 +70,6 @@ | ||
| # needed so we don't attempt to do clever back-trace | ||
| # (not included in stand-alone version). | ||
| add_definitions(-DWITH_ASSERT_ABORT) | ||
| set(SRC | ||
@@ -124,6 +128,9 @@ src/stubs/stubs.c | ||
| src/blenlib | ||
| ) | ||
| include_directories( | ||
| SYSTEM | ||
| ${PYTHON_INCLUDE_DIRS} | ||
| ) | ||
| add_library(blenlib_lib ${SRC}) | ||
@@ -130,0 +137,0 @@ |
| Metadata-Version: 1.0 | ||
| Name: mathutils | ||
| Version: 2.77 | ||
| Version: 2.78 | ||
| Summary: A general math utilities library providing Matrix, Vector, Quaternion, Euler and Color classes, written in C for speed. | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/ideasman42/blender-mathutils |
@@ -28,2 +28,3 @@ CMakeCache.txt | ||
| src/blenlib/BLI_sys_types.h | ||
| src/blenlib/BLI_system.h | ||
| src/blenlib/BLI_utildefines.h | ||
@@ -30,0 +31,0 @@ src/blenlib/intern/math_base.c |
+1
-1
| Metadata-Version: 1.0 | ||
| Name: mathutils | ||
| Version: 2.77 | ||
| Version: 2.78 | ||
| Summary: A general math utilities library providing Matrix, Vector, Quaternion, Euler and Color classes, written in C for speed. | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/ideasman42/blender-mathutils |
+2
-2
| [egg_info] | ||
| tag_build = | ||
| tag_date = 0 | ||
| tag_svn_revision = 0 | ||
| tag_date = 0 | ||
| tag_build = | ||
+27
-17
@@ -98,2 +98,3 @@ import distutils.ccompiler | ||
| "src/blenlib/BLI_sys_types.h", | ||
| "src/blenlib/BLI_system.h", | ||
| "src/blenlib/BLI_utildefines.h", | ||
@@ -129,18 +130,27 @@ | ||
| setup(name="mathutils", | ||
| version="2.77", | ||
| maintainer="Campbell Barton", | ||
| maintainer_email="ideasman42@gmail.com", | ||
| url="https://gitlab.com/ideasman42/blender-mathutils", | ||
| description=("A general math utilities library providing Matrix," | ||
| " Vector, Quaternion, Euler and Color classes, written in C for speed."), | ||
| license="GNU GPLv2+", | ||
| ext_modules=[Extension("mathutils", | ||
| source_files, | ||
| include_dirs=include_dirs, | ||
| define_macros=[("MATH_STANDALONE", None)], | ||
| depends=header_files, | ||
| extra_compile_args=options, | ||
| ) | ||
| ], | ||
| ) | ||
| setup( | ||
| name="mathutils", | ||
| version="2.78", | ||
| maintainer="Campbell Barton", | ||
| maintainer_email="ideasman42@gmail.com", | ||
| url="https://gitlab.com/ideasman42/blender-mathutils", | ||
| description=( | ||
| "A general math utilities library providing " | ||
| "Matrix, Vector, Quaternion, Euler and Color classes, " | ||
| "written in C for speed." | ||
| ), | ||
| license="GNU GPLv2+", | ||
| ext_modules=[ | ||
| Extension( | ||
| "mathutils", | ||
| source_files, | ||
| include_dirs=include_dirs, | ||
| define_macros=[ | ||
| ("MATH_STANDALONE", None), | ||
| ("WITH_ASSERT_ABORT", None), | ||
| ], | ||
| depends=header_files, | ||
| extra_compile_args=options, | ||
| ) | ||
| ], | ||
| ) |
@@ -40,6 +40,2 @@ /* | ||
| #ifdef __sun__ | ||
| #include <ieeefp.h> /* for finite() */ | ||
| #endif | ||
| #ifndef M_PI | ||
@@ -150,8 +146,2 @@ #define M_PI 3.14159265358979323846 /* pi */ | ||
| #ifdef WIN32 | ||
| # if defined(_MSC_VER) | ||
| # define finite(n) _finite(n) | ||
| # endif | ||
| #endif | ||
| #if BLI_MATH_DO_INLINE | ||
@@ -158,0 +148,0 @@ #include "intern/math_base_inline.c" |
@@ -118,2 +118,9 @@ /* | ||
| const float axis_ref[3]); | ||
| float dist_squared_to_ray_v3( | ||
| const float ray_origin[3], const float ray_direction[3], | ||
| const float co[3], float *r_depth); | ||
| float dist_squared_ray_to_seg_v3( | ||
| const float ray_origin[3], const float ray_direction[3], | ||
| const float v0[3], const float v1[3], | ||
| float r_point[3], float *r_depth); | ||
| float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]); | ||
@@ -322,7 +329,2 @@ float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3]); | ||
| void plot_line_v2v2i(const int p1[2], const int p2[2], bool (*callback)(int, int, void *), void *userData); | ||
| void fill_poly_v2i_n( | ||
| const int xmin, const int ymin, const int xmax, const int ymax, | ||
| const int polyXY[][2], const int polyCorners, | ||
| void (*callback)(int x, int x_end, int y, void *), void *userData); | ||
| /****************************** Interpolation ********************************/ | ||
@@ -475,2 +477,6 @@ | ||
| /********************************* Cubic (Bezier) *******************************/ | ||
| float cubic_tangent_factor_circle_v3(const float tan_l[3], const float tan_r[3]); | ||
| /**************************** Inline Definitions ******************************/ | ||
@@ -477,0 +483,0 @@ |
@@ -141,7 +141,11 @@ /* | ||
| /* double ariphmetics */ | ||
| /* double arithmetic (mixed float/double) */ | ||
| void mul_m4_v4d(float M[4][4], double r[4]); | ||
| void mul_v4d_m4v4d(double r[4], float M[4][4], double v[4]); | ||
| /* double matrix functions (no mixing types) */ | ||
| void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]); | ||
| void mul_m3_v3_db(double M[3][3], double r[3]); | ||
| /****************************** Linear Algebra *******************************/ | ||
@@ -250,2 +254,5 @@ | ||
| bool equals_m3m3(float mat1[3][3], float mat2[3][3]); | ||
| bool equals_m4m4(float mat1[4][4], float mat2[4][4]); | ||
| /* SpaceTransform helper */ | ||
@@ -271,3 +278,3 @@ typedef struct SpaceTransform { | ||
| void print_m3(const char *str, float M[3][3]); | ||
| void print_m4(const char *str, float M[3][4]); | ||
| void print_m4(const char *str, float M[4][4]); | ||
@@ -274,0 +281,0 @@ #define print_m3_id(M) print_m3(STRINGIFY(M), M) |
@@ -151,2 +151,3 @@ /* | ||
| MINLINE void negate_v3_short(short r[3]); | ||
| MINLINE void negate_v3_db(double r[3]); | ||
@@ -194,2 +195,8 @@ MINLINE void invert_v2(float r[2]); | ||
| MINLINE float normalize_v2_length(float r[2], const float unit_scale); | ||
| MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float unit_scale); | ||
| MINLINE float normalize_v3_length(float r[3], const float unit_scale); | ||
| MINLINE float normalize_v3_v3_length(float r[3], const float a[3], const float unit_scale); | ||
| MINLINE double normalize_v3_length_d(double n[3], const double unit_scale); | ||
| MINLINE float normalize_v2(float r[2]); | ||
@@ -219,2 +226,6 @@ MINLINE float normalize_v2_v2(float r[2], const float a[2]); | ||
| void interp_v2_v2v2v2v2_cubic( | ||
| float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], | ||
| const float u); | ||
| void interp_v3_v3v3_char(char target[3], const char a[3], const char b[3], const float t); | ||
@@ -237,2 +248,3 @@ void interp_v3_v3v3_uchar(unsigned char target[3], const unsigned char a[3], const unsigned char b[3], const float t); | ||
| /********************************* Comparison ********************************/ | ||
@@ -244,5 +256,5 @@ | ||
| MINLINE bool is_finite_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT; | ||
| MINLINE bool is_finite_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; | ||
| MINLINE bool is_finite_v4(const float a[4]) ATTR_WARN_UNUSED_RESULT; | ||
| bool is_finite_v2(const float a[3]) ATTR_WARN_UNUSED_RESULT; | ||
| bool is_finite_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; | ||
| bool is_finite_v4(const float a[4]) ATTR_WARN_UNUSED_RESULT; | ||
@@ -290,14 +302,14 @@ MINLINE bool is_one_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT; | ||
| void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]); | ||
| void project_v3_v3v3(float r[3], const float p[3], const float n[3]); | ||
| void project_plane_v3_v3v3(float c[3], const float v[3], const float v_plane[3]); | ||
| void project_plane_v2_v2v2(float c[2], const float v[2], const float v_plane[2]); | ||
| void project_v3_plane(float v[3], const float n[3], const float p[3]); | ||
| void reflect_v3_v3v3(float r[3], const float v[3], const float n[3]); | ||
| void project_v2_v2v2(float out[2], const float p[2], const float v_proj[2]); | ||
| void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3]); | ||
| void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3]); | ||
| void project_plane_v2_v2v2(float out[2], const float p[2], const float v_plane[2]); | ||
| void project_v3_plane(float out[3], const float plane_no[3], const float plane_co[3]); | ||
| void reflect_v3_v3v3(float out[3], const float vec[3], const float normal[3]); | ||
| void ortho_basis_v3v3_v3(float r_n1[3], float r_n2[3], const float n[3]); | ||
| void ortho_v3_v3(float p[3], const float v[3]); | ||
| void ortho_v2_v2(float p[2], const float v[2]); | ||
| void ortho_v3_v3(float out[3], const float v[3]); | ||
| void ortho_v2_v2(float out[2], const float v[2]); | ||
| void bisect_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3]); | ||
| void rotate_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); | ||
| void rotate_normalized_v3_v3v3fl(float v[3], const float p[3], const float axis[3], const float angle); | ||
| void rotate_normalized_v3_v3v3fl(float out[3], const float p[3], const float axis[3], const float angle); | ||
@@ -304,0 +316,0 @@ /*********************************** Other ***********************************/ |
@@ -636,3 +636,3 @@ /* | ||
| #ifndef NDEBUG | ||
| extern void BLI_system_backtrace(FILE *fp); | ||
| # include "BLI_system.h" | ||
| # ifdef WITH_ASSERT_ABORT | ||
@@ -639,0 +639,0 @@ # define _BLI_DUMMY_ABORT abort |
@@ -36,4 +36,7 @@ /* | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #ifdef __SSE2__ | ||
| # include <emmintrin.h> | ||
| #endif | ||
| #include "BLI_math_base.h" | ||
@@ -315,2 +318,96 @@ | ||
| /* Internal helpers for SSE2 implementation. | ||
| * | ||
| * NOTE: Are to be called ONLY from inside `#ifdef __SSE2__` !!! | ||
| */ | ||
| #ifdef __SSE2__ | ||
| /* Calculate initial guess for arg^exp based on float representation | ||
| * This method gives a constant bias, which can be easily compensated by | ||
| * multiplicating with bias_coeff. | ||
| * Gives better results for exponents near 1 (e. g. 4/5). | ||
| * exp = exponent, encoded as uint32_t | ||
| * e2coeff = 2^(127/exponent - 127) * bias_coeff^(1/exponent), encoded as | ||
| * uint32_t | ||
| * | ||
| * We hope that exp and e2coeff gets properly inlined | ||
| */ | ||
| MALWAYS_INLINE __m128 _bli_math_fastpow(const int exp, | ||
| const int e2coeff, | ||
| const __m128 arg) | ||
| { | ||
| __m128 ret; | ||
| ret = _mm_mul_ps(arg, _mm_castsi128_ps(_mm_set1_epi32(e2coeff))); | ||
| ret = _mm_cvtepi32_ps(_mm_castps_si128(ret)); | ||
| ret = _mm_mul_ps(ret, _mm_castsi128_ps(_mm_set1_epi32(exp))); | ||
| ret = _mm_castsi128_ps(_mm_cvtps_epi32(ret)); | ||
| return ret; | ||
| } | ||
| /* Improve x ^ 1.0f/5.0f solution with Newton-Raphson method */ | ||
| MALWAYS_INLINE __m128 _bli_math_improve_5throot_solution( | ||
| const __m128 old_result, | ||
| const __m128 x) | ||
| { | ||
| __m128 approx2 = _mm_mul_ps(old_result, old_result); | ||
| __m128 approx4 = _mm_mul_ps(approx2, approx2); | ||
| __m128 t = _mm_div_ps(x, approx4); | ||
| __m128 summ = _mm_add_ps(_mm_mul_ps(_mm_set1_ps(4.0f), old_result), t); /* fma */ | ||
| return _mm_mul_ps(summ, _mm_set1_ps(1.0f / 5.0f)); | ||
| } | ||
| /* Calculate powf(x, 2.4). Working domain: 1e-10 < x < 1e+10 */ | ||
| MALWAYS_INLINE __m128 _bli_math_fastpow24(const __m128 arg) | ||
| { | ||
| /* max, avg and |avg| errors were calculated in gcc without FMA instructions | ||
| * The final precision should be better than powf in glibc */ | ||
| /* Calculate x^4/5, coefficient 0.994 was constructed manually to minimize | ||
| * avg error. | ||
| */ | ||
| /* 0x3F4CCCCD = 4/5 */ | ||
| /* 0x4F55A7FB = 2^(127/(4/5) - 127) * 0.994^(1/(4/5)) */ | ||
| /* error max = 0.17 avg = 0.0018 |avg| = 0.05 */ | ||
| __m128 x = _bli_math_fastpow(0x3F4CCCCD, 0x4F55A7FB, arg); | ||
| __m128 arg2 = _mm_mul_ps(arg, arg); | ||
| __m128 arg4 = _mm_mul_ps(arg2, arg2); | ||
| /* error max = 0.018 avg = 0.0031 |avg| = 0.0031 */ | ||
| x = _bli_math_improve_5throot_solution(x, arg4); | ||
| /* error max = 0.00021 avg = 1.6e-05 |avg| = 1.6e-05 */ | ||
| x = _bli_math_improve_5throot_solution(x, arg4); | ||
| /* error max = 6.1e-07 avg = 5.2e-08 |avg| = 1.1e-07 */ | ||
| x = _bli_math_improve_5throot_solution(x, arg4); | ||
| return _mm_mul_ps(x, _mm_mul_ps(x, x)); | ||
| } | ||
| /* Calculate powf(x, 1.0f / 2.4) */ | ||
| MALWAYS_INLINE __m128 _bli_math_fastpow512(const __m128 arg) | ||
| { | ||
| /* 5/12 is too small, so compute the 4th root of 20/12 instead. | ||
| * 20/12 = 5/3 = 1 + 2/3 = 2 - 1/3. 2/3 is a suitable argument for fastpow. | ||
| * weighting coefficient: a^-1/2 = 2 a; a = 2^-2/3 | ||
| */ | ||
| __m128 xf = _bli_math_fastpow(0x3f2aaaab, 0x5eb504f3, arg); | ||
| __m128 xover = _mm_mul_ps(arg, xf); | ||
| __m128 xfm1 = _mm_rsqrt_ps(xf); | ||
| __m128 x2 = _mm_mul_ps(arg, arg); | ||
| __m128 xunder = _mm_mul_ps(x2, xfm1); | ||
| /* sqrt2 * over + 2 * sqrt2 * under */ | ||
| __m128 xavg = _mm_mul_ps(_mm_set1_ps(1.0f / (3.0f * 0.629960524947437f) * 0.999852f), | ||
| _mm_add_ps(xover, xunder)); | ||
| xavg = _mm_mul_ps(xavg, _mm_rsqrt_ps(xavg)); | ||
| xavg = _mm_mul_ps(xavg, _mm_rsqrt_ps(xavg)); | ||
| return xavg; | ||
| } | ||
| MALWAYS_INLINE __m128 _bli_math_blend_sse(const __m128 mask, | ||
| const __m128 a, | ||
| const __m128 b) | ||
| { | ||
| return _mm_or_ps(_mm_and_ps(mask, a), _mm_andnot_ps(mask, b)); | ||
| } | ||
| #endif /* __SSE2__ */ | ||
| #endif /* __MATH_BASE_INLINE_C__ */ |
@@ -59,3 +59,3 @@ /* | ||
| /* if y overflows, then rounded value is exactly x */ | ||
| if (!finite(y)) | ||
| if (!isfinite(y)) | ||
| return x; | ||
@@ -62,0 +62,0 @@ } |
@@ -31,2 +31,3 @@ /* | ||
| #include "BLI_math_base.h" | ||
| #include "BLI_math_color.h" | ||
@@ -42,4 +43,50 @@ #include "BLI_utildefines.h" | ||
| #ifdef __SSE2__ | ||
| MALWAYS_INLINE __m128 srgb_to_linearrgb_v4_simd(const __m128 c) | ||
| { | ||
| __m128 cmp = _mm_cmplt_ps(c, _mm_set1_ps(0.04045f)); | ||
| __m128 lt = _mm_max_ps(_mm_mul_ps(c, _mm_set1_ps(1.0f / 12.92f)), | ||
| _mm_set1_ps(0.0f)); | ||
| __m128 gtebase = _mm_mul_ps(_mm_add_ps(c, _mm_set1_ps(0.055f)), | ||
| _mm_set1_ps(1.0f / 1.055f)); /* fma */ | ||
| __m128 gte = _bli_math_fastpow24(gtebase); | ||
| return _bli_math_blend_sse(cmp, lt, gte); | ||
| } | ||
| MALWAYS_INLINE __m128 linearrgb_to_srgb_v4_simd(const __m128 c) | ||
| { | ||
| __m128 cmp = _mm_cmplt_ps(c, _mm_set1_ps(0.0031308f)); | ||
| __m128 lt = _mm_max_ps(_mm_mul_ps(c, _mm_set1_ps(12.92f)), | ||
| _mm_set1_ps(0.0f)); | ||
| __m128 gte = _mm_add_ps(_mm_mul_ps(_mm_set1_ps(1.055f), | ||
| _bli_math_fastpow512(c)), | ||
| _mm_set1_ps(-0.055f)); | ||
| return _bli_math_blend_sse(cmp, lt, gte); | ||
| } | ||
| MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3]) | ||
| { | ||
| float r[4] = {srgb[0], srgb[1], srgb[2], 1.0f}; | ||
| __m128 *rv = (__m128 *)&r; | ||
| *rv = srgb_to_linearrgb_v4_simd(*rv); | ||
| linear[0] = r[0]; | ||
| linear[1] = r[1]; | ||
| linear[2] = r[2]; | ||
| } | ||
| MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3]) | ||
| { | ||
| float r[4] = {linear[0], linear[1], linear[2], 1.0f}; | ||
| __m128 *rv = (__m128 *)&r; | ||
| *rv = linearrgb_to_srgb_v4_simd(*rv); | ||
| srgb[0] = r[0]; | ||
| srgb[1] = r[1]; | ||
| srgb[2] = r[2]; | ||
| } | ||
| #else /* __SSE2__ */ | ||
| MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3]) | ||
| { | ||
| linear[0] = srgb_to_linearrgb(srgb[0]); | ||
@@ -56,2 +103,3 @@ linear[1] = srgb_to_linearrgb(srgb[1]); | ||
| } | ||
| #endif /* __SSE2__ */ | ||
@@ -104,6 +152,10 @@ MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4]) | ||
| 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[0] = srgb[0] * inv_alpha; | ||
| linear[1] = srgb[1] * inv_alpha; | ||
| linear[2] = srgb[2] * inv_alpha; | ||
| linear[3] = srgb[3]; | ||
| srgb_to_linearrgb_v3_v3(linear, linear); | ||
| linear[0] *= alpha; | ||
| linear[1] *= alpha; | ||
| linear[2] *= alpha; | ||
| } | ||
@@ -124,6 +176,10 @@ | ||
| 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[0] = linear[0] * inv_alpha; | ||
| srgb[1] = linear[1] * inv_alpha; | ||
| srgb[2] = linear[2] * inv_alpha; | ||
| srgb[3] = linear[3]; | ||
| linearrgb_to_srgb_v3_v3(srgb, srgb); | ||
| srgb[0] *= alpha; | ||
| srgb[1] *= alpha; | ||
| srgb[2] *= alpha; | ||
| } | ||
@@ -221,3 +277,3 @@ | ||
| * ITU-R BT.709 primaries | ||
| * http://en.wikipedia.org/wiki/Relative_luminance | ||
| * https://en.wikipedia.org/wiki/Relative_luminance | ||
| * | ||
@@ -224,0 +280,0 @@ * Real values are: |
@@ -590,2 +590,11 @@ /* | ||
| void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]) | ||
| { | ||
| BLI_assert(r != a); | ||
| r[0] = M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2]; | ||
| r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2]; | ||
| r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2]; | ||
| } | ||
| void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]) | ||
@@ -601,6 +610,8 @@ { | ||
| { | ||
| float tmp[3]; | ||
| mul_v3_m3v3(r, M, (const float[3]){UNPACK3(r)}); | ||
| } | ||
| mul_v3_m3v3(tmp, M, r); | ||
| copy_v3_v3(r, tmp); | ||
| void mul_m3_v3_db(double M[3][3], double r[3]) | ||
| { | ||
| mul_v3_m3v3_db(r, M, (const double[3]){UNPACK3(r)}); | ||
| } | ||
@@ -1833,2 +1844,17 @@ | ||
| bool equals_m3m3(float mat1[3][3], float mat2[3][3]) | ||
| { | ||
| return (equals_v3v3(mat1[0], mat2[0]) && | ||
| equals_v3v3(mat1[1], mat2[1]) && | ||
| equals_v3v3(mat1[2], mat2[2])); | ||
| } | ||
| bool equals_m4m4(float mat1[4][4], float mat2[4][4]) | ||
| { | ||
| return (equals_v4v4(mat1[0], mat2[0]) && | ||
| equals_v4v4(mat1[1], mat2[1]) && | ||
| equals_v4v4(mat1[2], mat2[2]) && | ||
| equals_v4v4(mat1[3], mat2[3])); | ||
| } | ||
| /* make a 4x4 matrix out of 3 transform components */ | ||
@@ -1835,0 +1861,0 @@ /* matrices are made in the order: scale * rot * loc */ |
@@ -203,4 +203,3 @@ /* | ||
| q[0] = co; | ||
| normalize_v3(q + 1); | ||
| mul_v3_fl(q + 1, si); | ||
| normalize_v3_length(q + 1, si); | ||
| } | ||
@@ -207,0 +206,0 @@ |
@@ -636,2 +636,9 @@ /* | ||
| MINLINE void negate_v3_db(double r[3]) | ||
| { | ||
| r[0] = -r[0]; | ||
| r[1] = -r[1]; | ||
| r[2] = -r[2]; | ||
| } | ||
| MINLINE void invert_v2(float r[2]) | ||
@@ -856,3 +863,3 @@ { | ||
| MINLINE float normalize_v2_v2(float r[2], const float a[2]) | ||
| MINLINE float normalize_v2_v2_length(float r[2], const float a[2], const float unit_length) | ||
| { | ||
@@ -863,3 +870,3 @@ float d = dot_v2v2(a, a); | ||
| d = sqrtf(d); | ||
| mul_v2_v2fl(r, a, 1.0f / d); | ||
| mul_v2_v2fl(r, a, unit_length / d); | ||
| } | ||
@@ -873,2 +880,6 @@ else { | ||
| } | ||
| MINLINE float normalize_v2_v2(float r[2], const float a[2]) | ||
| { | ||
| return normalize_v2_v2_length(r, a, 1.0f); | ||
| } | ||
@@ -880,4 +891,9 @@ MINLINE float normalize_v2(float n[2]) | ||
| MINLINE float normalize_v3_v3(float r[3], const float a[3]) | ||
| MINLINE float normalize_v2_length(float n[2], const float unit_length) | ||
| { | ||
| return normalize_v2_v2_length(n, n, unit_length); | ||
| } | ||
| MINLINE float normalize_v3_v3_length(float r[3], const float a[3], const float unit_length) | ||
| { | ||
| float d = dot_v3v3(a, a); | ||
@@ -889,3 +905,3 @@ | ||
| d = sqrtf(d); | ||
| mul_v3_v3fl(r, a, 1.0f / d); | ||
| mul_v3_v3fl(r, a, unit_length / d); | ||
| } | ||
@@ -899,4 +915,8 @@ else { | ||
| } | ||
| MINLINE float normalize_v3_v3(float r[3], const float a[3]) | ||
| { | ||
| return normalize_v3_v3_length(r, a, 1.0f); | ||
| } | ||
| MINLINE double normalize_v3_d(double n[3]) | ||
| MINLINE double normalize_v3_length_d(double n[3], const double unit_length) | ||
| { | ||
@@ -911,3 +931,3 @@ double d = n[0] * n[0] + n[1] * n[1] + n[2] * n[2]; | ||
| d = sqrt(d); | ||
| mul = 1.0 / d; | ||
| mul = unit_length / d; | ||
@@ -925,3 +945,12 @@ n[0] *= mul; | ||
| } | ||
| MINLINE double normalize_v3_d(double n[3]) | ||
| { | ||
| return normalize_v3_length_d(n, 1.0); | ||
| } | ||
| MINLINE float normalize_v3_length(float n[3], const float unit_length) | ||
| { | ||
| return normalize_v3_v3_length(n, n, unit_length); | ||
| } | ||
| MINLINE float normalize_v3(float n[3]) | ||
@@ -964,17 +993,2 @@ { | ||
| MINLINE bool is_finite_v2(const float v[2]) | ||
| { | ||
| return (finite(v[0]) && finite(v[1])); | ||
| } | ||
| MINLINE bool is_finite_v3(const float v[3]) | ||
| { | ||
| return (finite(v[0]) && finite(v[1]) && finite(v[2])); | ||
| } | ||
| MINLINE bool is_finite_v4(const float v[4]) | ||
| { | ||
| return (finite(v[0]) && finite(v[1]) && finite(v[2]) && finite(v[3])); | ||
| } | ||
| MINLINE bool is_one_v3(const float v[3]) | ||
@@ -981,0 +995,0 @@ { |
@@ -167,2 +167,23 @@ /* | ||
| /** \name Cubic curve interpolation (bezier spline). | ||
| * \{ */ | ||
| void interp_v2_v2v2v2v2_cubic( | ||
| float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], | ||
| const float u) | ||
| { | ||
| float q0[2], q1[2], q2[2], r0[2], r1[2]; | ||
| interp_v2_v2v2(q0, v1, v2, u); | ||
| interp_v2_v2v2(q1, v2, v3, u); | ||
| interp_v2_v2v2(q2, v3, v4, u); | ||
| interp_v2_v2v2(r0, q0, q1, u); | ||
| interp_v2_v2v2(r1, q1, q2, u); | ||
| interp_v2_v2v2(p, r0, r1, u); | ||
| } | ||
| /** \} */ | ||
| /* weight 3 vectors, | ||
@@ -340,2 +361,21 @@ * 'w' must be unit length but is not a vector, just 3 weights */ | ||
| /********************************* Comparison ********************************/ | ||
| bool is_finite_v2(const float v[2]) | ||
| { | ||
| return (isfinite(v[0]) && isfinite(v[1])); | ||
| } | ||
| bool is_finite_v3(const float v[3]) | ||
| { | ||
| return (isfinite(v[0]) && isfinite(v[1]) && isfinite(v[2])); | ||
| } | ||
| bool is_finite_v4(const float v[4]) | ||
| { | ||
| return (isfinite(v[0]) && isfinite(v[1]) && isfinite(v[2]) && isfinite(v[3])); | ||
| } | ||
| /********************************** Angles ***********************************/ | ||
@@ -571,19 +611,23 @@ | ||
| /* Project v1 on v2 */ | ||
| void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]) | ||
| /** | ||
| * Project \a p onto \a v_proj | ||
| */ | ||
| void project_v2_v2v2(float out[2], const float p[2], const float v_proj[2]) | ||
| { | ||
| const float mul = dot_v2v2(v1, v2) / dot_v2v2(v2, v2); | ||
| const float mul = dot_v2v2(p, v_proj) / dot_v2v2(v_proj, v_proj); | ||
| c[0] = mul * v2[0]; | ||
| c[1] = mul * v2[1]; | ||
| out[0] = mul * v_proj[0]; | ||
| out[1] = mul * v_proj[1]; | ||
| } | ||
| /* Project v1 on v2 */ | ||
| void project_v3_v3v3(float c[3], const float v1[3], const float v2[3]) | ||
| /** | ||
| * Project \a p onto \a v_proj | ||
| */ | ||
| void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3]) | ||
| { | ||
| const float mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2); | ||
| const float mul = dot_v3v3(p, v_proj) / dot_v3v3(v_proj, v_proj); | ||
| c[0] = mul * v2[0]; | ||
| c[1] = mul * v2[1]; | ||
| c[2] = mul * v2[2]; | ||
| out[0] = mul * v_proj[0]; | ||
| out[1] = mul * v_proj[1]; | ||
| out[2] = mul * v_proj[2]; | ||
| } | ||
@@ -597,19 +641,28 @@ | ||
| * \note If \a v is exactly perpendicular to \a v_plane, \a c will just be a copy of \a v. | ||
| * | ||
| * \note This function is a convenience to call: | ||
| * \code{.c} | ||
| * project_v3_v3v3(c, v, v_plane); | ||
| * sub_v3_v3v3(c, v, c); | ||
| * \endcode | ||
| */ | ||
| void project_plane_v3_v3v3(float c[3], const float v[3], const float v_plane[3]) | ||
| void project_plane_v3_v3v3(float out[3], const float p[3], const float v_plane[3]) | ||
| { | ||
| float delta[3]; | ||
| project_v3_v3v3(delta, v, v_plane); | ||
| sub_v3_v3v3(c, v, delta); | ||
| const float mul = dot_v3v3(p, v_plane) / dot_v3v3(v_plane, v_plane); | ||
| out[0] = p[0] - (mul * v_plane[0]); | ||
| out[1] = p[1] - (mul * v_plane[1]); | ||
| out[2] = p[2] - (mul * v_plane[2]); | ||
| } | ||
| void project_plane_v2_v2v2(float c[2], const float v[2], const float v_plane[2]) | ||
| void project_plane_v2_v2v2(float out[2], const float p[2], const float v_plane[2]) | ||
| { | ||
| float delta[2]; | ||
| project_v2_v2v2(delta, v, v_plane); | ||
| sub_v2_v2v2(c, v, delta); | ||
| const float mul = dot_v2v2(p, v_plane) / dot_v2v2(v_plane, v_plane); | ||
| out[0] = p[0] - (mul * v_plane[0]); | ||
| out[1] = p[1] - (mul * v_plane[1]); | ||
| } | ||
| /* project a vector on a plane defined by normal and a plane point p */ | ||
| void project_v3_plane(float v[3], const float n[3], const float p[3]) | ||
| void project_v3_plane(float out[3], const float plane_no[3], const float plane_co[3]) | ||
| { | ||
@@ -619,8 +672,8 @@ float vector[3]; | ||
| sub_v3_v3v3(vector, v, p); | ||
| mul = dot_v3v3(vector, n) / len_squared_v3(n); | ||
| sub_v3_v3v3(vector, out, plane_co); | ||
| mul = dot_v3v3(vector, plane_no) / len_squared_v3(plane_no); | ||
| mul_v3_v3fl(vector, n, mul); | ||
| mul_v3_v3fl(vector, plane_no, mul); | ||
| sub_v3_v3(v, vector); | ||
| sub_v3_v3(out, vector); | ||
| } | ||
@@ -644,11 +697,11 @@ | ||
| */ | ||
| void reflect_v3_v3v3(float out[3], const float vec[3], const float normal[3]) | ||
| void reflect_v3_v3v3(float out[3], const float v[3], const float normal[3]) | ||
| { | ||
| const float dot2 = 2.0f * dot_v3v3(vec, normal); | ||
| const float dot2 = 2.0f * dot_v3v3(v, normal); | ||
| BLI_ASSERT_UNIT_V3(normal); | ||
| out[0] = vec[0] - (dot2 * normal[0]); | ||
| out[1] = vec[1] - (dot2 * normal[1]); | ||
| out[2] = vec[2] - (dot2 * normal[2]); | ||
| out[0] = v[0] - (dot2 * normal[0]); | ||
| out[1] = v[1] - (dot2 * normal[1]); | ||
| out[2] = v[2] - (dot2 * normal[2]); | ||
| } | ||
@@ -669,3 +722,3 @@ | ||
| BLI_assert(finite(d)); | ||
| BLI_assert(isfinite(d)); | ||
@@ -692,23 +745,23 @@ r_n1[0] = n[1] * d; | ||
| */ | ||
| void ortho_v3_v3(float p[3], const float v[3]) | ||
| void ortho_v3_v3(float out[3], const float v[3]) | ||
| { | ||
| const int axis = axis_dominant_v3_single(v); | ||
| BLI_assert(p != v); | ||
| BLI_assert(out != v); | ||
| switch (axis) { | ||
| case 0: | ||
| p[0] = -v[1] - v[2]; | ||
| p[1] = v[0]; | ||
| p[2] = v[0]; | ||
| out[0] = -v[1] - v[2]; | ||
| out[1] = v[0]; | ||
| out[2] = v[0]; | ||
| break; | ||
| case 1: | ||
| p[0] = v[1]; | ||
| p[1] = -v[0] - v[2]; | ||
| p[2] = v[1]; | ||
| out[0] = v[1]; | ||
| out[1] = -v[0] - v[2]; | ||
| out[2] = v[1]; | ||
| break; | ||
| case 2: | ||
| p[0] = v[2]; | ||
| p[1] = v[2]; | ||
| p[2] = -v[0] - v[1]; | ||
| out[0] = v[2]; | ||
| out[1] = v[2]; | ||
| out[2] = -v[0] - v[1]; | ||
| break; | ||
@@ -721,14 +774,15 @@ } | ||
| */ | ||
| void ortho_v2_v2(float p[2], const float v[2]) | ||
| void ortho_v2_v2(float out[2], const float v[2]) | ||
| { | ||
| BLI_assert(p != v); | ||
| BLI_assert(out != v); | ||
| p[0] = -v[1]; | ||
| p[1] = v[0]; | ||
| out[0] = -v[1]; | ||
| out[1] = v[0]; | ||
| } | ||
| /* Rotate a point p by angle theta around an arbitrary axis r | ||
| /** | ||
| * Rotate a point \a p by \a angle around an arbitrary unit length \a axis. | ||
| * http://local.wasp.uwa.edu.au/~pbourke/geometry/ | ||
| */ | ||
| void rotate_normalized_v3_v3v3fl(float r[3], const float p[3], const float axis[3], const float angle) | ||
| void rotate_normalized_v3_v3v3fl(float out[3], const float p[3], const float axis[3], const float angle) | ||
| { | ||
@@ -741,13 +795,13 @@ const float costheta = cosf(angle); | ||
| r[0] = ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) + | ||
| (((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) + | ||
| (((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]); | ||
| out[0] = ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) + | ||
| (((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) + | ||
| (((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]); | ||
| r[1] = (((1 - costheta) * axis[0] * axis[1] + axis[2] * sintheta) * p[0]) + | ||
| ((costheta + (1 - costheta) * axis[1] * axis[1]) * p[1]) + | ||
| (((1 - costheta) * axis[1] * axis[2] - axis[0] * sintheta) * p[2]); | ||
| out[1] = (((1 - costheta) * axis[0] * axis[1] + axis[2] * sintheta) * p[0]) + | ||
| ((costheta + (1 - costheta) * axis[1] * axis[1]) * p[1]) + | ||
| (((1 - costheta) * axis[1] * axis[2] - axis[0] * sintheta) * p[2]); | ||
| r[2] = (((1 - costheta) * axis[0] * axis[2] - axis[1] * sintheta) * p[0]) + | ||
| (((1 - costheta) * axis[1] * axis[2] + axis[0] * sintheta) * p[1]) + | ||
| ((costheta + (1 - costheta) * axis[2] * axis[2]) * p[2]); | ||
| out[2] = (((1 - costheta) * axis[0] * axis[2] - axis[1] * sintheta) * p[0]) + | ||
| (((1 - costheta) * axis[1] * axis[2] + axis[0] * sintheta) * p[1]) + | ||
| ((costheta + (1 - costheta) * axis[2] * axis[2]) * p[2]); | ||
| } | ||
@@ -754,0 +808,0 @@ |
@@ -48,3 +48,3 @@ /* | ||
| #include "BLI_path_util.h" /* BLI_setenv() */ | ||
| #include "BLI_math_base.h" /* finite() */ | ||
| #include "BLI_math_base.h" /* isfinite() */ | ||
| #endif | ||
@@ -181,3 +181,3 @@ | ||
| * Caller needs to ensure tuple is uninitialized. | ||
| * Handy for filling a typle with None for eg. | ||
| * Handy for filling a tuple with None for eg. | ||
| */ | ||
@@ -372,7 +372,8 @@ void PyC_Tuple_Fill(PyObject *tuple, PyObject *value) | ||
| /* similar to PyErr_Format(), | ||
| /** | ||
| * Similar to #PyErr_Format(), | ||
| * | ||
| * implementation - we cant actually preprend the existing exception, | ||
| * Implementation - we cant actually prepend the existing exception, | ||
| * because it could have _any_ arguments given to it, so instead we get its | ||
| * __str__ output and raise our own exception including it. | ||
| * ``__str__`` output and raise our own exception including it. | ||
| */ | ||
@@ -545,2 +546,31 @@ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *format, ...) | ||
| /* string conversion, escape non-unicode chars, coerce must be set to NULL */ | ||
| const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce) | ||
| { | ||
| const char *result; | ||
| result = _PyUnicode_AsStringAndSize(py_str, size); | ||
| if (result) { | ||
| /* 99% of the time this is enough but we better support non unicode | ||
| * chars since blender doesnt limit this */ | ||
| return result; | ||
| } | ||
| else { | ||
| PyErr_Clear(); | ||
| if (PyBytes_Check(py_str)) { | ||
| *size = PyBytes_GET_SIZE(py_str); | ||
| return PyBytes_AS_STRING(py_str); | ||
| } | ||
| else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { | ||
| *size = PyBytes_GET_SIZE(*coerce); | ||
| return PyBytes_AS_STRING(*coerce); | ||
| } | ||
| else { | ||
| /* leave error raised from EncodeFS */ | ||
| return NULL; | ||
| } | ||
| } | ||
| } | ||
| const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) | ||
@@ -755,2 +785,3 @@ { | ||
| PyDict_SetItemString(py_dict, "values", values); | ||
| Py_DECREF(values); | ||
@@ -1034,3 +1065,3 @@ py_result = PyRun_File(fp, filepath, Py_file_input, py_dict, py_dict); | ||
| } | ||
| else if (!finite(val)) { | ||
| else if (!isfinite(val)) { | ||
| *value = 0.0; | ||
@@ -1037,0 +1068,0 @@ } |
@@ -56,2 +56,3 @@ /* | ||
| const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */ | ||
| const char * PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce); | ||
@@ -58,0 +59,0 @@ /* name namespace function for bpy & bge */ |
@@ -44,3 +44,3 @@ /* | ||
| #define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) ((_totrow * (_col)) + (_row)) | ||
| #define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row)) | ||
| #define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->num_row * (_col)) + (_row))) | ||
@@ -47,0 +47,0 @@ #define MATRIX_ITEM_PTR( _mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col)) |
@@ -1168,5 +1168,5 @@ /* | ||
| if (is_zero_v3(axis) || | ||
| !finite(axis[0]) || | ||
| !finite(axis[1]) || | ||
| !finite(axis[2])) | ||
| !isfinite(axis[0]) || | ||
| !isfinite(axis[1]) || | ||
| !isfinite(axis[2])) | ||
| { | ||
@@ -1186,3 +1186,3 @@ axis[0] = 1.0f; | ||
| if (angle) { | ||
| if (!finite(*angle)) { | ||
| if (!isfinite(*angle)) { | ||
| *angle = 0.0f; | ||
@@ -1189,0 +1189,0 @@ } |
@@ -641,3 +641,3 @@ /* | ||
| * ...fails without this. */ | ||
| PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); | ||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||
| Py_INCREF(submodule); | ||
@@ -649,3 +649,3 @@ | ||
| * ...fails without this. */ | ||
| PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); | ||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||
| Py_INCREF(submodule); | ||
@@ -656,3 +656,3 @@ | ||
| PyModule_AddObject(mod, "noise", (submodule = PyInit_mathutils_noise())); | ||
| PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); | ||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||
| Py_INCREF(submodule); | ||
@@ -662,3 +662,3 @@ | ||
| PyModule_AddObject(mod, "bvhtree", (submodule = PyInit_mathutils_bvhtree())); | ||
| PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); | ||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||
| Py_INCREF(submodule); | ||
@@ -668,3 +668,3 @@ | ||
| PyModule_AddObject(mod, "kdtree", (submodule = PyInit_mathutils_kdtree())); | ||
| PyDict_SetItemString(sys_modules, PyModule_GetName(submodule), submodule); | ||
| PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | ||
| Py_INCREF(submodule); | ||
@@ -671,0 +671,0 @@ #endif |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
65
1.56%130
8.33%1008194
-4.78%