}
//
-// conversion to/from raw float and double arrays.
+// conversion to/from raw float and double arrays; array-like access.
//
// load a vector from a double array.
static inline void vstoref(struct vec v, float *f) {
f[0] = v.x; f[1] = v.y; f[2] = v.z;
}
+// index a vector like a 3-element array.
+static inline float vindex(struct vec v, int i) {
+ return ((float const *)&v.x)[i];
+}
// ---------------------------- 3x3 matrices ------------------------------
// tests - when adding new tests, make sure to add to test_fns array
//
+void test_vec_basic()
+{
+ struct vec v = mkvec(1.0f, 2.0f, 3.0f);
+ assert(vindex(v, 0) == 1.0f);
+ assert(vindex(v, 1) == 2.0f);
+ assert(vindex(v, 2) == 3.0f);
+
+ printf("%s passed\n", __func__);
+}
+
void test_mat_axisangle()
{
srand(0); // deterministic
// micro test framework
typedef void (*voidvoid_fn)(void);
voidvoid_fn test_fns[] = {
+ test_vec_basic,
test_mat_axisangle,
test_quat_rpy_conversions,
test_quat_mat_conversions,