Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-02-15 02:46:14 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-02-15 06:02:08 +0300
commitfa2f7c69acc55fd1fe3db0610ad319d08d77d79e (patch)
tree004780e19ea70ec8ee5eb6b26cde8ace90558a70 /source/blender/python/mathutils/mathutils.h
parenta9d979c8ef2b6de25c1953da341dd5e207416540 (diff)
mathutils: Implement __hash__() functions
- all mathutils types - only works on frozen data (so vectors can be used in sets/dict keys) - uses same method as CPython, (matches hashing a tuple) D1104 by @juicyfruit with own modifications
Diffstat (limited to 'source/blender/python/mathutils/mathutils.h')
-rw-r--r--source/blender/python/mathutils/mathutils.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h
index 03ce9af3f49..e653b45389b 100644
--- a/source/blender/python/mathutils/mathutils.h
+++ b/source/blender/python/mathutils/mathutils.h
@@ -109,6 +109,7 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index);
int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index);
void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self);
+void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self);
/* since this is called so often avoid where possible */
#define BaseMath_ReadCallback(_self) \
@@ -133,12 +134,18 @@ void _BaseMathObject_RaiseFrozenExc(const BaseMathObject *self);
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : 0)
+#define BaseMathObject_Prepare_ForHash(_self) \
+ (UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
+ (_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : 0)
+
/* utility func */
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix);
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix);
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
+Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len);
+
/* zero remaining unused elements of the array */
#define MU_ARRAY_ZERO (1 << 30)
/* ignore larger py sequences than requested (just use first elements),