## cd-math cd-math — Common maths functionality |

## Synopsis

                        CdMat3x3;
                        CdVec3;
    void                cd_mat33_clear                      (const CdMat3x3 *src);
    void                cd_mat33_copy                       (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);
    gdouble             cd_mat33_determinant                (const CdMat3x3 *src);
    gdouble *           cd_mat33_get_data                   (const CdMat3x3 *src);
    void                cd_mat33_matrix_multiply            (const CdMat3x3 *mat_src1,
                                                             const CdMat3x3 *mat_src2,
                                                             CdMat3x3 *mat_dest);
    void                cd_mat33_normalize                  (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);
    gboolean            cd_mat33_reciprocal                 (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);
    void                cd_mat33_scalar_multiply            (const CdMat3x3 *mat_src,
                                                             gdouble value,
                                                             CdMat3x3 *mat_dest);
    void                cd_mat33_set_identity               (CdMat3x3 *src);
    gchar *             cd_mat33_to_string                  (const CdMat3x3 *src);
    void                cd_mat33_vector_multiply            (const CdMat3x3 *mat_src,
                                                             const CdVec3 *vec_src,
                                                             CdVec3 *vec_dest);
    void                cd_vec3_add                         (const CdVec3 *src1,
                                                             const CdVec3 *src2,
                                                             CdVec3 *dest);
    void                cd_vec3_clear                       (CdVec3 *src);
    void                cd_vec3_copy                        (const CdVec3 *src,
                                                             CdVec3 *dest);
    gdouble *           cd_vec3_get_data                    (const CdVec3 *src);
    void                cd_vec3_init                        (CdVec3 *dest,
                                                             gdouble v0,
                                                             gdouble v1,
                                                             gdouble v2);
    void                cd_vec3_scalar_multiply             (const CdVec3 *src,
                                                             gdouble value,
                                                             CdVec3 *dest);
    gdouble             cd_vec3_squared_error               (const CdVec3 *src1,
                                                             const CdVec3 *src2);
    void                cd_vec3_subtract                    (const CdVec3 *src1,
                                                             const CdVec3 *src2,
                                                             CdVec3 *dest);
    gchar *             cd_vec3_to_string                   (const CdVec3 *src);

## Description

A GObject to use for common maths functionality like vectors and matrices.

## Details

### CdMat3x3

    typedef struct {
    	gdouble	 m00, m01, m02;
    	gdouble	 m10, m11, m12;
    	gdouble	 m20, m21, m22;
    	/* any addition fields go *after* the data */
    } CdMat3x3;

### CdVec3

    typedef struct {
    	double	 v0, v1, v2;
    	/* any addition fields go *after* the data */
    } CdVec3;

### cd_mat33_clear ()

    void                cd_mat33_clear                      (const CdMat3x3 *src);

Clears a matrix value, setting all it's values to zero.

`src` : | the source

### cd_mat33_copy ()

    void                cd_mat33_copy                       (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);

Copies the matrix. The arguments `src` and `dest` cannot be the same value.

`src` : | the source
`dest` : | the destination

### cd_mat33_determinant ()

    gdouble             cd_mat33_determinant                (const CdMat3x3 *src);

Gets the determinant of the matrix.

`src` : | the source

### cd_mat33_get_data ()

    gdouble *           cd_mat33_get_data                   (const CdMat3x3 *src);

Gets the raw data for the matrix.

`src` : | the matrix source
Returns : | the pointer to the data segment.

### cd_mat33_matrix_multiply ()

    void                cd_mat33_matrix_multiply            (const CdMat3x3 *mat_src1,
                                                             const CdMat3x3 *mat_src2,
                                                             CdMat3x3 *mat_dest);

Multiply (convolve) one matrix with another. The arguments `mat_src1` cannot be the same as `mat_dest`, and `mat_src2` cannot be the same as `mat_dest`.

`mat_src1` : | the matrix source
`mat_src2` : | the other matrix source
`mat_dest` : | the destination

### cd_mat33_normalize ()

    void                cd_mat33_normalize                  (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);

Normalizes a matrix

The arguments `src` and `dest` can be the same value.

`src` : | the source matrix
`dest` : | the destination matrix

### cd_mat33_reciprocal ()

    gboolean            cd_mat33_reciprocal                 (const CdMat3x3 *src,
                                                             CdMat3x3 *dest);

Inverts the matrix. The arguments `src` and `dest` cannot be the same value.

`src` : | the source
`dest` : | the destination
Returns : | `FALSE` if det is zero (singular).

### cd_mat33_scalar_multiply ()

    void                cd_mat33_scalar_multiply            (const CdMat3x3 *mat_src,
                                                             gdouble value,
                                                             CdMat3x3 *mat_dest);

Multiplies a matrix with a scalar. The arguments `vec_src` and `vec_dest` can be the same value.

`mat_src` : | the source
`value` : | the scalar
`mat_dest` : | the destination

### cd_mat33_set_identity ()

    void                cd_mat33_set_identity               (CdMat3x3 *src);

Sets the matrix to an identity value.

`src` : | the source

### cd_mat33_to_string ()

    gchar *             cd_mat33_to_string                  (const CdMat3x3 *src);

Obtains a string representaton of a matrix.

`src` : | the source
Returns : | the string. Free with `g_free()`

### cd_mat33_vector_multiply ()

    void                cd_mat33_vector_multiply            (const CdMat3x3 *mat_src,
                                                             const CdVec3 *vec_src,
                                                             CdVec3 *vec_dest);

Multiplies a matrix with a vector. The arguments `vec_src` and `vec_dest` cannot be the same value.

`mat_src` : | the matrix source
`vec_src` : | the vector source
`vec_dest` : | the destination vector

### cd_vec3_add ()

    void                cd_vec3_add                         (const CdVec3 *src1,
                                                             const CdVec3 *src2,
                                                             CdVec3 *dest);

Adds two vector quantaties The arguments `src` and `dest` can be the same value.

`src1` : | the source
`src2` : | the other source
`dest` : | the destination

### cd_vec3_clear ()

    void                cd_vec3_clear                       (CdVec3 *src);

Clears a vector, setting all it's values to zero.

`src` : | the source vector

### cd_vec3_copy ()

    void                cd_vec3_copy                        (const CdVec3 *src,
                                                             CdVec3 *dest);

Copies the vector into another vector. The arguments `src` and `dest` cannot be the same value.

`src` : | the source
`dest` : | the destination

### cd_vec3_get_data ()

    gdouble *           cd_vec3_get_data                    (const CdVec3 *src);

Gets the raw data for the vector.

`src` : | the vector source
Returns : | the pointer to the data segment.

### cd_vec3_init ()

    void                cd_vec3_init                        (CdVec3 *dest,
                                                             gdouble v0,
                                                             gdouble v1,
                                                             gdouble v2);

Initialises a vector.

`dest` : | the destination vector
`v0` : | component value
`v1` : | component value
`v2` : | component value

### cd_vec3_scalar_multiply ()

    void                cd_vec3_scalar_multiply             (const CdVec3 *src,
                                                             gdouble value,
                                                             CdVec3 *dest);

Multiplies a vector with a scalar. The arguments `src` and `dest` can be the same value.

`src` : | the source
`value` : | the scalar multiplier
`dest` : | the destination

### cd_vec3_squared_error ()

    gdouble             cd_vec3_squared_error               (const CdVec3 *src1,
                                                             const CdVec3 *src2);

Gets the mean squared error for a pair of vectors

`src1` : | the vector source
`src2` : | another vector source
Returns : | the floating point MSE.

### cd_vec3_subtract ()

    void                cd_vec3_subtract                    (const CdVec3 *src1,
                                                             const CdVec3 *src2,
                                                             CdVec3 *dest);

Subtracts one vector quantaty from another The arguments `src` and `dest` can be the same value.

`src1` : | the source
`src2` : | the other source
`dest` : | the destination

### cd_vec3_to_string ()

    gchar *             cd_vec3_to_string                   (const CdVec3 *src);

Obtains a string representaton of a vector.

`src` : | the source
Returns : | the string. Free with `g_free()`