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>2011-12-19 07:12:10 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-19 07:12:10 +0400
commitc3675c0e9059831e2978500ae4f2651d6049b0ed (patch)
tree7246b2766259ff0e480ce4b39bae75e1ac964d6b /source/blender/python/mathutils/mathutils_Matrix.h
parentd0aa012b0a451f52409a5d4df33dcdcac2763562 (diff)
remove mathutils internal variable for storing pointers to each matrix row, instead use macros to access row/column's.
also add an assert so invalid index access will raise an error in debug mode, without this it was quite easy to access invalid memory without meaning to. no functional change.
Diffstat (limited to 'source/blender/python/mathutils/mathutils_Matrix.h')
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/source/blender/python/mathutils/mathutils_Matrix.h b/source/blender/python/mathutils/mathutils_Matrix.h
index 6dfcbb1faf9..98253bf7659 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.h
+++ b/source/blender/python/mathutils/mathutils_Matrix.h
@@ -38,9 +38,23 @@ extern PyTypeObject matrix_Type;
#define MatrixObject_Check(_v) PyObject_TypeCheck((_v), &matrix_Type)
#define MATRIX_MAX_DIM 4
+/* to remove pymat->matrix[row][col] */
+
+#ifdef DEBUG
+# define MATRIX_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->row_size && _col < (_mat)->col_size))
+#else
+# define MATRIX_ASSERT(_mat, _row, _col) (void)0
+#endif
+
+#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ASSERT(_mat, _row, _col), (((_mat)->col_size * (_row)) + (_col)))
+#define MATRIX_ITEM_PTR( _mat, _row, _col) ((_mat)->contigPtr + MATRIX_ITEM_INDEX(_mat, _row, _col))
+#define MATRIX_ITEM( _mat, _row, _col) ((_mat)->contigPtr [MATRIX_ITEM_INDEX(_mat, _row, _col)])
+
+#define MATRIX_ROW_INDEX(_mat, _row) (MATRIX_ITEM_INDEX(_mat, _row, 0))
+#define MATRIX_ROW_PTR( _mat, _row) ((_mat)->contigPtr + MATRIX_ROW_INDEX(_mat, _row))
+
typedef struct {
BASE_MATH_MEMBERS(contigPtr);
- float *matrix[MATRIX_MAX_DIM]; /* ptr to the contigPtr (accessor) */
unsigned short row_size;
unsigned short col_size;
} MatrixObject;