MCPcopy Create free account
hub / github.com/blender/blender / Vector_project

Function Vector_project

source/blender/python/mathutils/mathutils_Vector.cc:1333–1361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1331 " :return: the parallel projection vector\n"
1332 " :rtype: :class:`Vector`\n");
1333static PyObject *Vector_project(VectorObject *self, PyObject *value)
1334{
1335 const int vec_num = self->vec_num;
1336 float *tvec;
1337 double dot = 0.0f, dot2 = 0.0f;
1338 int x;
1339
1340 if (BaseMath_ReadCallback(self) == -1) {
1341 return nullptr;
1342 }
1343
1344 if (mathutils_array_parse_alloc(
1345 &tvec, vec_num, value, "Vector.project(other), invalid 'other' arg") == -1)
1346 {
1347 return nullptr;
1348 }
1349
1350 /* get dot products */
1351 for (x = 0; x < vec_num; x++) {
1352 dot += double(self->vec[x] * tvec[x]);
1353 dot2 += double(tvec[x] * tvec[x]);
1354 }
1355 /* projection */
1356 dot /= dot2;
1357 for (x = 0; x < vec_num; x++) {
1358 tvec[x] *= float(dot);
1359 }
1360 return Vector_CreatePyObject_alloc(tvec, vec_num, Py_TYPE(self));
1361}
1362
1363/** \} */
1364

Callers

nothing calls this directly

Calls 2

Tested by

no test coverage detected