Пример #1
0
EAPI void
eina_matrix3_rotate(Eina_Matrix3 *m, double rad)
{
   double c, s;
#if 0
   c = cosf(rad);
   s = sinf(rad);
#else
   /* normalize the angle between -pi,pi */
   rad = fmod(rad + M_PI, 2 * M_PI) - M_PI;
   c = _cos(rad);
   s = _sin(rad);
#endif

   Eina_Matrix3 tmp;
   MATRIX_XX(&tmp) = c;
   MATRIX_XY(&tmp) = -s;
   MATRIX_XZ(&tmp) = 0;
   MATRIX_YX(&tmp) = s;
   MATRIX_YY(&tmp) = c;
   MATRIX_YZ(&tmp) = 0;
   MATRIX_ZX(&tmp) = 0;
   MATRIX_ZY(&tmp) = 0;
   MATRIX_ZZ(&tmp) = 1;
   eina_matrix3_compose(m, &tmp, m);
}
Пример #2
0
EAPI void
eina_matrix3_scale(Eina_Matrix3 *m, double sx, double sy)
{
   Eina_Matrix3 tmp;
   MATRIX_XX(&tmp) = sx;
   MATRIX_XY(&tmp) = 0;
   MATRIX_XZ(&tmp) = 0;
   MATRIX_YX(&tmp) = 0;
   MATRIX_YY(&tmp) = sy;
   MATRIX_YZ(&tmp) = 0;
   MATRIX_ZX(&tmp) = 0;
   MATRIX_ZY(&tmp) = 0;
   MATRIX_ZZ(&tmp) = 1;
   eina_matrix3_compose(m, &tmp, m);
}
Пример #3
0
EAPI void
eina_matrix3_translate(Eina_Matrix3 *m, double tx, double ty)
{
   Eina_Matrix3 tmp;
   MATRIX_XX(&tmp) = 1;
   MATRIX_XY(&tmp) = 0;
   MATRIX_XZ(&tmp) = tx;
   MATRIX_YX(&tmp) = 0;
   MATRIX_YY(&tmp) = 1;
   MATRIX_YZ(&tmp) = ty;
   MATRIX_ZX(&tmp) = 0;
   MATRIX_ZY(&tmp) = 0;
   MATRIX_ZZ(&tmp) = 1;
   eina_matrix3_compose(m, &tmp, m);
}
Пример #4
0
EAPI Eina_Bool
eina_matrix3_quad_quad_map(Eina_Matrix3 *m,
                           const Eina_Quad *src,
                           const Eina_Quad *dst)
{
   Eina_Matrix3 tmp;

   /* TODO check that both are actually quadrangles */
   if (!eina_matrix3_quad_square_map(m, src))
     return EINA_FALSE;
   if (!eina_matrix3_square_quad_map(&tmp, dst))
     return EINA_FALSE;
   eina_matrix3_compose(&tmp, m, m);

   return EINA_TRUE;
}
Пример #5
0
END_TEST

#define MATRIX3_CMP(XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ, AXX, AXY, AXZ, AYX, AYY, AYZ, AZX, AZY, AZZ) \
  (EINA_DBL_EQ(XX, AXX) && \
   EINA_DBL_EQ(XY, AXY) && \
   EINA_DBL_EQ(XZ, AXZ) && \
   EINA_DBL_EQ(YX, AYX) && \
   EINA_DBL_EQ(YY, AYY) && \
   EINA_DBL_EQ(YZ, AYZ) && \
   EINA_DBL_EQ(ZX, AZX) && \
   EINA_DBL_EQ(ZY, AZY) && \
   EINA_DBL_EQ(ZZ, AZZ))

START_TEST(eina_matrix3_operations)
{
   Eina_Matrix3 m1, m2, m3;
   double xx, xy, xz,
          yx, yy, yz,
          zx, zy, zz;
   double tx = 20, ty = 30, ret;
   const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1};

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);

   eina_matrix3_values_set(&m2,
                           1, 1, 1,
                           1, 1, 1,
                           1, 1, 1);


   eina_matrix3_compose(&m1, &m2, &m3);
   eina_matrix3_values_get(&m3,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (!EINA_DBL_EQ(xx, xy) ||
            !EINA_DBL_EQ(xy, xz) ||
            !EINA_DBL_EQ(yx, yy) ||
            !EINA_DBL_EQ(yy, yz) ||
            !EINA_DBL_EQ(zx, zy) ||
            !EINA_DBL_EQ(zy, zz) ||
            !EINA_DBL_EQ(zz, 1));

   eina_matrix3_translate(&m1, tx, ty);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        1, 0, tx,
                        0, 1, ty,
                        0, 0, 1));

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);

   eina_matrix3_scale(&m1, tx, ty);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                       yx, yy, yz,
                       zx, zy, zz,
                       tx, 0, 0,
                       0, ty, 0,
                       0, 0, 1));

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);
   eina_matrix3_rotate(&m1, M_PI/2);

   fail_if (!MATRIX3_CMP(round(m1.xx), round(m1.xy), round(m1.xz),
                         round(m1.yx), round(m1.yy), round(m1.yz),
                         round(m1.zx), round(m1.zy), round(m1.zz),
                         0, -1, 0,
                         1, 0, 0,
                         0, 0, 1));

   eina_matrix3_values_set(&m1,
                           1, 1, 1,
                           1, 1, 1,
                           1, 1, 1);
   eina_matrix3_identity(&m1);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!EINA_DBL_EQ(xx, yy) ||
           !EINA_DBL_EQ(yy, zz) ||
           !EINA_DBL_EQ(zz, 1));

   fail_if(!EINA_DBL_EQ(xy, xz) ||
           !EINA_DBL_EQ(yx, yz) ||
           !EINA_DBL_EQ(zx, zy) ||
           !EINA_DBL_EQ(zy, 0));

   eina_matrix3_values_set(&m1,
                           1, 2, 1,
                           2, 1, 1,
                           1, 2, 2);
   ret = eina_matrix3_determinant(&m1);
   fail_if(!EINA_DBL_EQ(ret, -3));

   eina_matrix3_values_set(&m1,
                           3, 3, 3,
                           3, 3, 3,
                           3, 3, 3);
   eina_matrix3_divide(&m1, 2);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (!EINA_DBL_EQ(xx, xy) ||
            !EINA_DBL_EQ(xy, xz) ||
            !EINA_DBL_EQ(yx, yy) ||
            !EINA_DBL_EQ(yy, yz) ||
            !EINA_DBL_EQ(zx, zy) ||
            !EINA_DBL_EQ(zy, zz) ||
            !EINA_DBL_EQ(zz, 1.5));

   eina_matrix3_values_set(&m1,
                           0, 2, 0,
                           2, 2, 0,
                           2, 1, 2);
   eina_matrix3_inverse(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        -0.5, 0.5, 0.0,
                        0.5, 0.0, 0.0,
                        0.25, -0.5, 0.5));

   eina_matrix3_values_set(&m1,
                           1, 2, 3,
                           4, 5, 6,
                           7, 8, 9);
   eina_matrix3_transpose(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        1, 4, 7,
                        2, 5, 8,
                        3, 6, 9));

   eina_matrix3_values_set(&m1,
                           1, 2, 3,
                           0, 4, 5,
                           1, 0, 6);
   eina_matrix3_cofactor(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        24, 5, -4,
                        -12, 3, 2,
                        -2, -5, 4));

   eina_matrix3_adjoint(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        24, -12, -2,
                        5, 3, -5,
                        -4, 2, 4));

   eina_matrix3_values_set(&m2,
                           2, 2, 2,
                           1, 1, 1,
                           3, 3, 3);
   eina_matrix3_values_set(&m3,
                           3, 3, 3,
                           2, 2, 2,
                           1, 1, 1);
   eina_matrix3_multiply_copy(&m1, &m2, &m3);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        12, 12, 12,
                        6, 6, 6,
                        18, 18, 18));

   eina_matrix3_values_set(&m2,
                           2, 2, 2,
                           1, 1, 1,
                           0, 0, 0);
   eina_matrix3_multiply(&m1, &m2, &m3);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        12, 12, 12,
                        6, 6, 6,
                        0, 0, 0));

   eina_matrix3_copy(&m1, &m2);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        2, 2, 2,
                        1, 1, 1,
                        0, 0, 0));

   eina_matrix3_array_set(&m1, arr);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(!MATRIX3_CMP(xx, xy, xz,
                        yx, yy, yz,
                        zx, zy, zz,
                        1, 1, 1,
                        1, 1, 1,
                        1, 1, 1));

   eina_matrix3_position_transform_set(&m3, 5, 3);
   eina_matrix3_values_get(&m3,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (!EINA_DBL_EQ(xz, 5) ||
            !EINA_DBL_EQ(yz, 3));

   eina_matrix3_scale_transform_set(&m2, 6, 7);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (!EINA_DBL_EQ(xx, 6) ||
            !EINA_DBL_EQ(yy, 7));
}
Пример #6
0
END_TEST

START_TEST(eina_matrix3_operations)
{
   Eina_Matrix3 m1, m2, m3;
   double xx, xy, xz,
          yx, yy, yz,
          zx, zy, zz;
   double tx = 20, ty = 30, ret;

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);

   eina_matrix3_values_set(&m2,
                           1, 1, 1,
                           1, 1, 1,
                           1, 1, 1);


   eina_matrix3_compose(&m1, &m2, &m3);
   eina_matrix3_values_get(&m3,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != xy ||
            xy != xz ||
            yx != yy ||
            yy != yz ||
            zx != zy ||
            zy != zz ||
            zz != 1);

   eina_matrix3_translate(&m1, tx, ty);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != 1 || xy != 0 || xz != tx ||
            yx != 0 || yy != 1 || yz != ty ||
            zx != 0 || zy != 0 || zz != 1);

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);

   eina_matrix3_scale(&m1, tx, ty);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != tx || xy != 0 || xz != 0 ||
            yx != 0 || yy != ty || yz != 0 ||
            zx != 0 || zy != 0 || zz != 1);

   eina_matrix3_values_set(&m1,
                           1, 0, 0,
                           0, 1, 0,
                           0, 0, 1);
   eina_matrix3_rotate(&m1, M_PI/2);

   fail_if (round(m1.xx) != 0 || round(m1.xy) != -1 ||
            round(m1.xz) != 0 || round(m1.yx) != 1 ||
            round(m1.yy) != 0 || round(m1.yz) !=0 ||
            round(m1.zx) != 0 || round(m1.zy) != 0||
            round(m1.zz) != 1);

   eina_matrix3_values_set(&m1,
                           1, 1, 1,
                           1, 1, 1,
                           1, 1, 1);
   eina_matrix3_identity(&m1);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if(xx != yy ||
           yy != zz ||
           zz != 1);

   fail_if(xy != xz ||
           yx != yz ||
           zx != zy ||
           zy != 0);


   eina_matrix3_values_set(&m1,
                           1, 2, 1,
                           2, 1, 1,
                           1, 2, 2);
   ret = eina_matrix3_determinant(&m1);
   fail_if(ret != -3);

   eina_matrix3_values_set(&m1,
                           3, 3, 3,
                           3, 3, 3,
                           3, 3, 3);
   eina_matrix3_divide(&m1, 2);
   eina_matrix3_values_get(&m1,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != xy ||
            xy != xz ||
            yx != yy ||
            yy != yz ||
            zx != zy ||
            zy != zz ||
            zz != 1.5);

   eina_matrix3_values_set(&m1,
                           0, 2, 0,
                           2, 2, 0,
                           2, 1, 2);
   eina_matrix3_inverse(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != -0.5 || xy != 0.5 || xz != 0 ||
            yx != 0.5 || yy != 0 || yz != 0 ||
            zx != 0.25 || zy != -0.5 || zz != 0.5);

   eina_matrix3_values_set(&m1,
                           1, 2, 3,
                           4, 5, 6,
                           7, 8, 9);
   eina_matrix3_transpose(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != 1 || xy != 4 || xz != 7 ||
            yx != 2 || yy != 5 || yz != 8 ||
            zx != 3 || zy != 6 || zz != 9);

   eina_matrix3_values_set(&m1,
                           1, 2, 3,
                           0, 4, 5,
                           1, 0, 6);
   eina_matrix3_cofactor(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != 24 || xy != 5 || xz != -4 ||
            yx != -12 || yy != 3 || yz != 2 ||
            zx != -2 || zy != -5 || zz != 4);

   eina_matrix3_adjoint(&m1, &m2);
   eina_matrix3_values_get(&m2,
                           &xx, &xy, &xz,
                           &yx, &yy, &yz,
                           &zx, &zy, &zz);
   fail_if (xx != 24 || xy != -12 || xz != -2 ||
            yx != 5 || yy != 3 || yz != -5 ||
            zx != -4 || zy != 2 || zz != 4);
}