diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-04 10:12:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-04 10:12:58 +0300 |
commit | 0d69a5aa3491501c4a556aec3978128c041d328e (patch) | |
tree | 1a26cc1730348fb1323408be28f73511d3723e8d /source | |
parent | 179358e6c479ee083dd70b56dc9206fd4a1e5206 (diff) | |
parent | 76b9eaf7a84ee2098c1ca1bf5cd4042c55ae76d7 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash_utils.c | 18 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 25 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_2d.c | 6 |
4 files changed, 30 insertions, 20 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index 9e7c9a2db38..9613847f28f 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -277,6 +277,7 @@ MINLINE bool compare_v4v4_relative(const float a[4], const float b[4], const flo MINLINE bool compare_len_v3v3(const float a[3], const float b[3], const float limit) ATTR_WARN_UNUSED_RESULT; MINLINE bool compare_len_squared_v3v3(const float a[3], const float b[3], const float limit) ATTR_WARN_UNUSED_RESULT; +MINLINE bool compare_len_squared_v4v4(const float a[4], const float b[4], const float limit) ATTR_WARN_UNUSED_RESULT; MINLINE float line_point_side_v2(const float l1[2], const float l2[2], const float pt[2]) ATTR_WARN_UNUSED_RESULT; diff --git a/source/blender/blenlib/intern/BLI_ghash_utils.c b/source/blender/blenlib/intern/BLI_ghash_utils.c index 6b8c9b5226c..a0d9fefe465 100644 --- a/source/blender/blenlib/intern/BLI_ghash_utils.c +++ b/source/blender/blenlib/intern/BLI_ghash_utils.c @@ -47,17 +47,25 @@ /** \name Generic Key Hash & Comparison Functions * \{ */ - -/* based python3.3's pointer hashing function */ +#if 0 +/* works but slower */ +uint BLI_ghashutil_ptrhash(const void *key) +{ + return (uint)(intptr_t)key; +} +#else +/* Based Python3.7's pointer hashing function. */ uint BLI_ghashutil_ptrhash(const void *key) { size_t y = (size_t)key; /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid * excessive hash collisions for dicts and sets */ - y = (y >> 4) | (y << (8 * sizeof(void *) - 4)); - return (uint)y; -} + /* Note: Unlike Python 'sizeof(uint)' is used instead of 'sizeof(void *)', + * Otherwise casting to 'uint' ignores the upper bits on 64bit platforms. */ + return (uint)(y >> 4) | ((uint)y << (8 * sizeof(uint) - 4)); +} +#endif bool BLI_ghashutil_ptrcmp(const void *a, const void *b) { return (a != b); diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index fcab001631e..dbb2339461f 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -1114,24 +1114,23 @@ MINLINE bool compare_v4v4_relative(const float v1[4], const float v2[4], const f MINLINE bool 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)); + float d[3]; + sub_v3_v3v3(d, v1, v2); + return (dot_v3v3(d, d) <= (limit * limit)); } MINLINE bool compare_len_squared_v3v3(const float v1[3], const float v2[3], const float limit_sq) { - float x, y, z; - - x = v1[0] - v2[0]; - y = v1[1] - v2[1]; - z = v1[2] - v2[2]; + float d[3]; + sub_v3_v3v3(d, v1, v2); + return (dot_v3v3(d, d) <= limit_sq); +} - return ((x * x + y * y + z * z) <= limit_sq); +MINLINE bool compare_len_squared_v4v4(const float v1[4], const float v2[4], const float limit_sq) +{ + float d[4]; + sub_v4_v4v4(d, v1, v2); + return (dot_v4v4(d, d) <= limit_sq); } /** diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index a6f367b3d46..6b2287290d1 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -1421,8 +1421,9 @@ static void paint_2d_fill_add_pixel_byte( float color_f[4]; unsigned char *color_b = (unsigned char *)(ibuf->rect + coordinate); rgba_uchar_to_float(color_f, color_b); + straight_to_premul_v4(color_f); - if (compare_len_squared_v3v3(color_f, color, threshold_sq)) { + if (compare_len_squared_v4v4(color_f, color, threshold_sq)) { BLI_stack_push(stack, &coordinate); } BLI_BITMAP_SET(touched, coordinate, true); @@ -1441,7 +1442,7 @@ static void paint_2d_fill_add_pixel_float( coordinate = ((size_t)y_px) * ibuf->x + x_px; if (!BLI_BITMAP_TEST(touched, coordinate)) { - if (compare_len_squared_v3v3(ibuf->rect_float + 4 * coordinate, color, threshold_sq)) { + if (compare_len_squared_v4v4(ibuf->rect_float + 4 * coordinate, color, threshold_sq)) { BLI_stack_push(stack, &coordinate); } BLI_BITMAP_SET(touched, coordinate, true); @@ -1548,6 +1549,7 @@ void paint_2d_bucket_fill( else { int pixel_color_b = *(ibuf->rect + coordinate); rgba_uchar_to_float(pixel_color, (unsigned char *)&pixel_color_b); + straight_to_premul_v4(pixel_color); } BLI_stack_push(stack, &coordinate); |