## cd-math

cd-math — Common maths functionality

## Functions

void | cd_vec3_clear ()
void | cd_vec3_add ()
void | cd_vec3_subtract ()
void | cd_vec3_scalar_multiply ()
void | cd_vec3_copy ()
gdouble | cd_vec3_squared_error ()
gchar * | cd_vec3_to_string ()
gdouble * | cd_vec3_get_data ()
void | cd_vec3_init ()
void | cd_mat33_init ()
void | cd_mat33_clear ()
gchar * | cd_mat33_to_string ()
gdouble * | cd_mat33_get_data ()
void | cd_mat33_set_identity ()
void | cd_mat33_scalar_multiply ()
void | cd_mat33_vector_multiply ()
void | cd_mat33_matrix_multiply ()
gboolean | cd_mat33_reciprocal ()
gdouble | cd_mat33_determinant ()
void | cd_mat33_normalize ()
void | cd_mat33_copy ()
gboolean | cd_mat33_is_finite ()

## Types and Values

| CdMat3x3
| CdVec3

## Description

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

## Functions

### cd_vec3_clear ()

    void
    cd_vec3_clear (CdVec3 *src);

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

#### Parameters

src | the source 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.

#### Parameters

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

### cd_vec3_subtract ()

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

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

#### Parameters

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

### 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.

#### Parameters

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

### 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.

#### Parameters

src | the source |
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

#### Parameters

src1 | the vector source |
src2 | another vector source |

#### Returns

the floating point MSE.

### cd_vec3_to_string ()

    gchar *
    cd_vec3_to_string (const CdVec3 *src);

Obtains a string representaton of a vector.

#### Parameters

src | the source |

#### Returns

the string. Free with `g_free()`

### cd_vec3_get_data ()

    gdouble *
    cd_vec3_get_data (const CdVec3 *src);

Gets the raw data for the vector.

#### Parameters

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.

#### Parameters

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

### cd_mat33_init ()

    void
    cd_mat33_init (CdMat3x3 *dest,
                   gdouble m00,
                   gdouble m01,
                   gdouble m02,
                   gdouble m10,
                   gdouble m11,
                   gdouble m12,
                   gdouble m20,
                   gdouble m21,
                   gdouble m22);

Initialises a matrix.

#### Parameters

dest | the destination matrix |
m00 | component value |
m01 | component value |
m02 | component value |
m10 | component value |
m11 | component value |
m12 | component value |
m20 | component value |
m21 | component value |
m22 | component value |

### cd_mat33_clear ()

    void
    cd_mat33_clear (const CdMat3x3 *src);

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

#### Parameters

src | the source |

### cd_mat33_to_string ()

    gchar *
    cd_mat33_to_string (const CdMat3x3 *src);

Obtains a string representaton of a matrix.

#### Parameters

src | the source |

#### Returns

the string. Free with `g_free()`

### cd_mat33_get_data ()

    gdouble *
    cd_mat33_get_data (const CdMat3x3 *src);

Gets the raw data for the matrix.

#### Parameters

src | the matrix source |

#### Returns

the pointer to the data segment.

### cd_mat33_set_identity ()

    void
    cd_mat33_set_identity (CdMat3x3 *src);

Sets the matrix to an identity value.

#### Parameters

src | the source |

### 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.

#### Parameters

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

### 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.

#### Parameters

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

### 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` .

#### Parameters

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

### 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.

#### Parameters

src | the source |
dest | the destination |

#### Returns

`FALSE` if det is zero (singular).

### cd_mat33_determinant ()

    gdouble
    cd_mat33_determinant (const CdMat3x3 *src);

Gets the determinant of the matrix.

#### Parameters

src | the source |

### 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.

#### Parameters

src | the source matrix |
dest | the destination matrix |

### 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.

#### Parameters

src | the source |
dest | the destination |

### cd_mat33_is_finite ()

    gboolean
    cd_mat33_is_finite (const CdMat3x3 *mat,
                        GError **error);

Determine whether all entries in the specified matrix are finite and not NaNs.

#### Parameters

mat | the matrix to test |
error | A GError, or `NULL`. | [out]

#### Returns

`TRUE` if `isfinite()` returns `TRUE` for all values.

## Types and Values

### 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;