diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 17:41:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:18:11 +0300 |
commit | d140e70c496122915eb5c05aba83153e2e0d7998 (patch) | |
tree | 1e589247d69da64aa7b0e7802319237ec050b5d6 /source/blender/blenlib/intern/quadric.c | |
parent | 147bd16ed1bb3415b30408b0eab110d0854eadd2 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-experimentstemp-ghash-experiments
Note that 'store hash' feature was removed for now - to complex to maintain (conflicts)
and relatively easy to re-add if we ever really want this one day.
Conflicts:
source/blender/blenlib/BLI_ghash.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/hash_mm2a.c
source/blender/bmesh/tools/bmesh_region_match.c
tests/gtests/blenlib/BLI_ghash_performance_test.cc
tests/gtests/blenlib/BLI_ghash_test.cc
tests/gtests/blenlib/CMakeLists.txt
Diffstat (limited to 'source/blender/blenlib/intern/quadric.c')
-rw-r--r-- | source/blender/blenlib/intern/quadric.c | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/source/blender/blenlib/intern/quadric.c b/source/blender/blenlib/intern/quadric.c index 814d05ca80e..588cd9c2cb5 100644 --- a/source/blender/blenlib/intern/quadric.c +++ b/source/blender/blenlib/intern/quadric.c @@ -29,20 +29,24 @@ * \note This isn't fully complete, * possible there are other useful functions to add here. * - * \note try to follow BLI_math naming convention here. + * \note follow BLI_math naming convention here. + * + * \note this uses doubles for internal calculations, + * even though input/output are floats in some cases. + * + * This is done because the cases quadrics are useful + * often need high precision, see T44780. */ -//#include <string.h> - #include "BLI_math.h" #include "BLI_strict_flags.h" #include "BLI_quadric.h" /* own include */ -#define QUADRIC_FLT_TOT (sizeof(Quadric) / sizeof(float)) +#define QUADRIC_FLT_TOT (sizeof(Quadric) / sizeof(double)) -void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset) +void BLI_quadric_from_plane(Quadric *q, const double v[4]) { q->a2 = v[0] * v[0]; q->b2 = v[1] * v[1]; @@ -52,33 +56,33 @@ void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset) q->ac = v[0] * v[2]; q->bc = v[1] * v[2]; - q->ad = v[0] * offset; - q->bd = v[1] * offset; - q->cd = v[2] * offset; + q->ad = v[0] * v[3]; + q->bd = v[1] * v[3]; + q->cd = v[2] * v[3]; - q->d2 = offset * offset; + q->d2 = v[3] * v[3]; } void BLI_quadric_to_tensor_m3(const Quadric *q, float m[3][3]) { - m[0][0] = q->a2; - m[0][1] = q->ab; - m[0][2] = q->ac; + m[0][0] = (float)q->a2; + m[0][1] = (float)q->ab; + m[0][2] = (float)q->ac; - m[1][0] = q->ab; - m[1][1] = q->b2; - m[1][2] = q->bc; + m[1][0] = (float)q->ab; + m[1][1] = (float)q->b2; + m[1][2] = (float)q->bc; - m[2][0] = q->ac; - m[2][1] = q->bc; - m[2][2] = q->c2; + m[2][0] = (float)q->ac; + m[2][1] = (float)q->bc; + m[2][2] = (float)q->c2; } void BLI_quadric_to_vector_v3(const Quadric *q, float v[3]) { - v[0] = q->ad; - v[1] = q->bd; - v[2] = q->cd; + v[0] = (float)q->ad; + v[1] = (float)q->bd; + v[2] = (float)q->cd; } void BLI_quadric_clear(Quadric *q) @@ -88,25 +92,26 @@ void BLI_quadric_clear(Quadric *q) void BLI_quadric_add_qu_qu(Quadric *a, const Quadric *b) { - add_vn_vn((float *)a, (float *)b, QUADRIC_FLT_TOT); + add_vn_vn_d((double *)a, (double *)b, QUADRIC_FLT_TOT); } void BLI_quadric_add_qu_ququ(Quadric *r, const Quadric *a, const Quadric *b) { - add_vn_vnvn((float *)r, (const float *)a, (const float *)b, QUADRIC_FLT_TOT); + add_vn_vnvn_d((double *)r, (const double *)a, (const double *)b, QUADRIC_FLT_TOT); } -void BLI_quadric_mul(Quadric *a, const float scalar) +void BLI_quadric_mul(Quadric *a, const double scalar) { - mul_vn_fl((float *)a, QUADRIC_FLT_TOT, scalar); + mul_vn_db((double *)a, QUADRIC_FLT_TOT, scalar); } -float BLI_quadric_evaluate(const Quadric *q, const float v[3]) +double BLI_quadric_evaluate(const Quadric *q, const float v_fl[3]) { - return (v[0] * v[0] * q->a2 + 2.0f * v[0] * v[1] * q->ab + 2.0f * v[0] * v[2] * q->ac + 2.0f * v[0] * q->ad + - v[1] * v[1] * q->b2 + 2.0f * v[1] * v[2] * q->bc + 2.0f * v[1] * q->bd + - v[2] * v[2] * q->c2 + 2.0f * v[2] * q->cd + - q->d2); + const double v[3] = {UNPACK3(v_fl)}; + return ((q->a2 * v[0] * v[0]) + (q->ab * 2 * v[0] * v[1]) + (q->ac * 2 * v[0] * v[2]) + (q->ad * 2 * v[0]) + + (q->b2 * v[1] * v[1]) + (q->bc * 2 * v[1] * v[2]) + (q->bd * 2 * v[1]) + + (q->c2 * v[2] * v[2]) + (q->cd * 2 * v[2]) + + (q->d2)); } bool BLI_quadric_optimize(const Quadric *q, float v[3], const float epsilon) |