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

Function mathutils_array_parse

source/blender/python/mathutils/mathutils.cc:99–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99int mathutils_array_parse(
100 float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
101{
102 const uint flag = array_num_max;
103 int num;
104
105 array_num_max &= ~MU_ARRAY_FLAGS;
106
107#if 1 /* approx 6x speedup for mathutils types */
108
109 if ((num = VectorObject_Check(value) ? (reinterpret_cast<VectorObject *>(value))->vec_num : 0) ||
110 (num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) ||
111 (num = ColorObject_Check(value) ? 3 : 0))
112 {
113 if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
114 return -1;
115 }
116
117 if (flag & MU_ARRAY_SPILL) {
118 CLAMP_MAX(num, array_num_max);
119 }
120
121 if (num > array_num_max || num < array_num_min) {
122 if (array_num_max == array_num_min) {
123 PyErr_Format(PyExc_ValueError,
124 "%.200s: sequence length is %d, expected %d",
125 error_prefix,
126 num,
127 array_num_max);
128 }
129 else {
130 PyErr_Format(PyExc_ValueError,
131 "%.200s: sequence length is %d, expected [%d - %d]",
132 error_prefix,
133 num,
134 array_num_min,
135 array_num_max);
136 }
137 return -1;
138 }
139
140 memcpy(array, (reinterpret_cast<const BaseMathObject *>(value))->data, num * sizeof(float));
141 }
142 else
143#endif
144 {
145 PyObject *value_fast = nullptr;
146
147 /* non list/tuple cases */
148 if (!(value_fast = PySequence_Fast(value, error_prefix))) {
149 /* PySequence_Fast sets the error */
150 return -1;
151 }
152
153 num = PySequence_Fast_GET_SIZE(value_fast);
154
155 if (flag & MU_ARRAY_SPILL) {
156 CLAMP_MAX(num, array_num_max);

Callers 15

Vector_reflectFunction · 0.85
Vector_crossFunction · 0.85
Vector_angleFunction · 0.85
Vector_angle_signedFunction · 0.85
Vector_slerpFunction · 0.85
Vector_swizzle_setFunction · 0.85
py_bvhtree_ray_castFunction · 0.85
py_bvhtree_find_nearestFunction · 0.85
C_BVHTree_FromPolygonsFunction · 0.85
py_kdtree_insertFunction · 0.85

Calls 1

Tested by

no test coverage detected