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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-11-24 08:12:16 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-11-24 08:12:16 +0400
commitc62d33c540830188207bc32d5e3fc5a2134f5ab1 (patch)
tree5d996cc183651123d518ead7d9a3a6a951c77348 /source
parentf94614d791b1381bc4751ad5194680cec81a4b57 (diff)
patch: [#29382] Arbitrary Length Array Function Additions and Modifications
from Andrew Hale (trumanblending), with some edits to use these in mathutils.Vector added. Added Functions: - dot_vn_vn - Dot product of two arrays - normalize_vn_vn - Normalize an array and store the result in a second array - normalize_vn - Normalize an array inplace Renamed Functions: Some functions have been renamed to make them consistent with the naming conventions used by fixed length array functions. - fill_vni to fill_vn_i - fill_vn to fill_vn_fl
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c6
-rw-r--r--source/blender/blenlib/BLI_math_vector.h11
-rw-r--r--source/blender/blenlib/intern/math_vector.c36
-rw-r--r--source/blender/editors/space_logic/logic_window.c2
-rw-r--r--source/blender/makesrna/intern/rna_object.c2
-rw-r--r--source/blender/python/mathutils/mathutils_Matrix.c2
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c50
7 files changed, 55 insertions, 54 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 4400c895b78..d03e01ffca7 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -2129,9 +2129,9 @@ static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos
DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
DM_add_face_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
- range_vni(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0);
- range_vni(DM_get_edge_data_layer(dm, CD_ORIGINDEX), dm->numEdgeData, 0);
- range_vni(DM_get_face_data_layer(dm, CD_ORIGINDEX), dm->numFaceData, 0);
+ range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0);
+ range_vn_i(DM_get_edge_data_layer(dm, CD_ORIGINDEX), dm->numEdgeData, 0);
+ range_vn_i(DM_get_face_data_layer(dm, CD_ORIGINDEX), dm->numFaceData, 0);
}
}
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 2b9d6d2d6d6..d8e880a9dec 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -194,17 +194,20 @@ void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]);
/***************************** Array Functions *******************************/
/* attempted to follow fixed length vertex functions. names could be improved*/
-void range_vni(int *array, const int size, const int start);
+double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size);
+float normalize_vn_vn(float *array_tar, const float *array_src, const int size);
+float normalize_vn(float *array_tar, const int size);
+void range_vn_i(int *array_tar, const int size, const int start);
void negate_vn(float *array_tar, const int size);
void negate_vn_vn(float *array_tar, const float *array_src, const int size);
-void mul_vn_fl(float *array, const int size, const float f);
+void mul_vn_fl(float *array_tar, const int size, const float f);
void mul_vn_vn_fl(float *array_tar, const float *array_src, const int size, const float f);
void add_vn_vn(float *array_tar, const float *array_src, const int size);
void add_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
void sub_vn_vn(float *array_tar, const float *array_src, const int size);
void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_src_b, const int size);
-void fill_vni(int *array_tar, const int size, const int val);
-void fill_vn(float *array_tar, const int size, const float val);
+void fill_vn_i(int *array_tar, const int size, const int val);
+void fill_vn_fl(float *array_tar, const int size, const float val);
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 01c3e112cd8..a9ea90ef555 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -378,7 +378,37 @@ void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
/***************************** Array Functions *******************************/
-void range_vni(int *array_tar, const int size, const int start)
+double dot_vn_vn(const float *array_src_a, const float *array_src_b, const int size)
+{
+ double d= 0.0f;
+ const float *array_pt_a= array_src_a + (size-1);
+ const float *array_pt_b= array_src_b + (size-1);
+ int i= size;
+ while(i--) { d += *(array_pt_a--) * *(array_pt_b--); }
+ return d;
+}
+
+float normalize_vn_vn(float *array_tar, const float *array_src, const int size)
+{
+ double d= dot_vn_vn(array_tar, array_src, size);
+ float d_sqrt;
+ if (d > 1.0e-35) {
+ d_sqrt= (float)sqrt(d);
+ mul_vn_vn_fl(array_tar, array_src, size, 1.0f/d_sqrt);
+ }
+ else {
+ fill_vn_fl(array_tar, size, 0.0f);
+ d_sqrt= 0.0f;
+ }
+ return d_sqrt;
+}
+
+float normalize_vn(float *array_tar, const int size)
+{
+ return normalize_vn_vn(array_tar, array_tar, size);
+}
+
+void range_vn_i(int *array_tar, const int size, const int start)
{
int *array_pt= array_tar + (size-1);
int j= start + (size-1);
@@ -450,14 +480,14 @@ void sub_vn_vnvn(float *array_tar, const float *array_src_a, const float *array_
while(i--) { *(tar--) = *(src_a--) - *(src_b--); }
}
-void fill_vni(int *array_tar, const int size, const int val)
+void fill_vn_i(int *array_tar, const int size, const int val)
{
int *tar= array_tar + (size-1);
int i= size;
while(i--) { *(tar--) = val; }
}
-void fill_vn(float *array_tar, const int size, const float val)
+void fill_vn_fl(float *array_tar, const int size, const float val)
{
float *tar= array_tar + (size-1);
int i= size;
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
index a6e5506f98d..e5255448ae9 100644
--- a/source/blender/editors/space_logic/logic_window.c
+++ b/source/blender/editors/space_logic/logic_window.c
@@ -3701,7 +3701,7 @@ static void draw_actuator_action(uiLayout *layout, PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointerRNA settings_ptr;
- uiLayout *row, *sub, *col;
+ uiLayout *row, *sub;
RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 9dd6d2e8175..80563f66b17 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1193,7 +1193,7 @@ static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
memcpy(values, bb->vec, sizeof(bb->vec));
}
else {
- fill_vn(values, sizeof(bb->vec)/sizeof(float), 0.0f);
+ fill_vn_fl(values, sizeof(bb->vec)/sizeof(float), 0.0f);
}
}
diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c
index 1472b6886f6..409acdd5d5e 100644
--- a/source/blender/python/mathutils/mathutils_Matrix.c
+++ b/source/blender/python/mathutils/mathutils_Matrix.c
@@ -1223,7 +1223,7 @@ PyDoc_STRVAR(Matrix_zero_doc,
);
static PyObject *Matrix_zero(MatrixObject *self)
{
- fill_vn(self->contigPtr, self->row_size * self->col_size, 0.0f);
+ fill_vn_fl(self->contigPtr, self->row_size * self->col_size, 0.0f);
if (BaseMath_WriteCallback(self) == -1)
return NULL;
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index f70bd42e2b6..d9b86658bd9 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -95,7 +95,7 @@ PyDoc_STRVAR(Vector_zero_doc,
);
static PyObject *Vector_zero(VectorObject *self)
{
- fill_vn(self->vec, self->size, 0.0f);
+ fill_vn_fl(self->vec, self->size, 0.0f);
if (BaseMath_WriteCallback(self) == -1)
return NULL;
@@ -116,19 +116,10 @@ PyDoc_STRVAR(Vector_normalize_doc,
);
static PyObject *Vector_normalize(VectorObject *self)
{
- int i;
- float norm = 0.0f;
-
if (BaseMath_ReadCallback(self) == -1)
return NULL;
- for (i = 0; i < self->size; i++) {
- norm += self->vec[i] * self->vec[i];
- }
- norm = (float) sqrt(norm);
- for (i = 0; i < self->size; i++) {
- self->vec[i] /= norm;
- }
+ normalize_vn(self->vec, self->size);
(void)BaseMath_WriteCallback(self);
Py_RETURN_NONE;
@@ -571,8 +562,6 @@ PyDoc_STRVAR(Vector_dot_doc,
static PyObject *Vector_dot(VectorObject *self, PyObject *value)
{
float tvec[MAX_DIMENSIONS];
- double dot = 0.0;
- int x;
if (BaseMath_ReadCallback(self) == -1)
return NULL;
@@ -580,11 +569,7 @@ static PyObject *Vector_dot(VectorObject *self, PyObject *value)
if (mathutils_array_parse(tvec, self->size, self->size, value, "Vector.dot(other), invalid 'other' arg") == -1)
return NULL;
- for (x = 0; x < self->size; x++) {
- dot += (double)(self->vec[x] * tvec[x]);
- }
-
- return PyFloat_FromDouble(dot);
+ return PyFloat_FromDouble(dot_vn_vn(self->vec, tvec, self->size));
}
PyDoc_STRVAR(Vector_angle_doc,
@@ -1145,9 +1130,6 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
/* make sure v1 is always the vector */
if (vec1 && vec2) {
- int i;
- double dot = 0.0f;
-
if (vec1->size != vec2->size) {
PyErr_SetString(PyExc_ValueError,
"Vector multiplication: "
@@ -1156,10 +1138,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
}
/*dot product*/
- for (i = 0; i < vec1->size; i++) {
- dot += (double)(vec1->vec[i] * vec2->vec[i]);
- }
- return PyFloat_FromDouble(dot);
+ return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size));
}
else if (vec1) {
if (MatrixObject_Check(v2)) {
@@ -1644,7 +1623,6 @@ static PyObject *Vector_getLength(VectorObject *self, void *UNUSED(closure))
static int Vector_setLength(VectorObject *self, PyObject *value)
{
double dot = 0.0f, param;
- int i;
if (BaseMath_ReadCallback(self) == -1)
return -1;
@@ -1661,13 +1639,11 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
return -1;
}
if (param == 0.0) {
- fill_vn(self->vec, self->size, 0.0f);
+ fill_vn_fl(self->vec, self->size, 0.0f);
return 0;
}
- for (i = 0; i < self->size; i++) {
- dot += (double)(self->vec[i] * self->vec[i]);
- }
+ dot= dot_vn_vn(self->vec, self->vec, self->size);
if (!dot) /* cant sqrt zero */
return 0;
@@ -1679,9 +1655,7 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
dot= dot/param;
- for (i = 0; i < self->size; i++) {
- self->vec[i]= self->vec[i] / (float)dot;
- }
+ mul_vn_fl(self->vec, self->size, 1.0/dot);
(void)BaseMath_WriteCallback(self); /* checked already */
@@ -1691,16 +1665,10 @@ static int Vector_setLength(VectorObject *self, PyObject *value)
/* vector.length_squared */
static PyObject *Vector_getLengthSquared(VectorObject *self, void *UNUSED(closure))
{
- double dot = 0.0f;
- int i;
-
if (BaseMath_ReadCallback(self) == -1)
return NULL;
- for (i = 0; i < self->size; i++) {
- dot += (double)(self->vec[i] * self->vec[i]);
- }
- return PyFloat_FromDouble(dot);
+ return PyFloat_FromDouble(dot_vn_vn(self->vec, self->vec, self->size));
}
/* Get a new Vector according to the provided swizzle. This function has little
@@ -2432,7 +2400,7 @@ PyObject *newVectorObject(float *vec, const int size, const int type, PyTypeObje
memcpy(self->vec, vec, size * sizeof(float));
}
else { /* new empty */
- fill_vn(self->vec, size, 0.0f);
+ fill_vn_fl(self->vec, size, 0.0f);
if (size == 4) { /* do the homogenous thing */
self->vec[3] = 1.0f;
}