From a767c658cb603de9ec9f0577627b9b32cbf82b2b Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 22 Dec 2017 01:53:55 +0100 Subject: Simplify and add geom. and matrix utility functions Signed-off-by: pacien --- include/common/geom.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ include/common/matrix.h | 51 --------------------------------------------- include/morpher/matrix.h | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 51 deletions(-) delete mode 100644 include/common/matrix.h create mode 100644 include/morpher/matrix.h (limited to 'include') diff --git a/include/common/geom.h b/include/common/geom.h index a843c76..b3564a5 100644 --- a/include/common/geom.h +++ b/include/common/geom.h @@ -38,6 +38,46 @@ typedef struct { CartesianVector origin, target; } CartesianMapping; + +/** + * Function: m + * Shorthand for an identity mapping. + * + * Parameters: + * x - the x-coordinate + * y - the y-coordinate + * + * Returns: + * A cartesian identity mapping + */ +CartesianMapping m(int x, int y); + +/** + * Function: v + * Shorthand for a vector. + * + * Parameters: + * x - the x-coordinate + * y - the y-coordinate + * + * Returns: + * An integer vector + */ +CartesianVector v(int x, int y); + +/** + * Function: mappings_equals + * Compares two cartesian mappings. + * + * Parameters: + * m1 - the first mapping + * m2 - the second mapping + * + * Returns: + * T(m1 is equal to m2) + */ +bool mappings_equals(CartesianMapping m1, CartesianMapping m2); + /** * Function: vector_equals * Compares two cartesian vectors. @@ -51,4 +91,18 @@ typedef struct { */ bool vector_equals(CartesianVector v1, CartesianVector v2); +/** + * Function: triangle_area + * Computes the area of a triangle. + * + * Parameters: + * v1 - first vertex + * v2 - second vertex + * v3 - third vertex + * + * Returns: + * The area of the triangle spawned by the three supplied vertices + */ +IntVector triangle_area(CartesianVector v1, CartesianVector v2, CartesianVector v3); + #endif diff --git a/include/common/matrix.h b/include/common/matrix.h deleted file mode 100644 index fe4a12a..0000000 --- a/include/common/matrix.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef UPEM_MORPHING_MATRIX -#define UPEM_MORPHING_MATRIX - -/** - * File: matrix.h - * Matrices representation and useful operations. - * - * See also: - * The film - */ - -#include "geom.h" - -/** - * Struct: IntSquareMatrix - * Represents a square integer matrix. - * - * Fields: - * **elements - NULL-terminated array of element pointers - * dim - dimension - */ -typedef struct { - IntVector **elements; - IntVector dim; -} IntSquareMatrix; - -/** - * Function: matrix_int_det - * Computes and returns the determinant of a square integer matrix. - * - * Parameters: - * *matrix - pointer to input matrix - * - * Returns: - * The integer determinant - */ -IntVector matrix_int_det(IntSquareMatrix *matrix); - -/** - * Function: matrix_reshape - * Reshapes a flat vector into a bi-dimensional row pointer array. - * - * Parameters: - * **bi_dim - pointer to the result row array - * *flat - flat vector - * width - number of elements per row - * height - number of rows - */ -void matrix_reshape(IntVector **bi_dim, IntVector *flat, int width, int height); - -#endif diff --git a/include/morpher/matrix.h b/include/morpher/matrix.h new file mode 100644 index 0000000..8118727 --- /dev/null +++ b/include/morpher/matrix.h @@ -0,0 +1,41 @@ +#ifndef UPEM_MORPHING_MATRIX +#define UPEM_MORPHING_MATRIX + +/** + * File: matrix.h + * Determinant operations. + * + * See also: + * The film + */ + +#include "common/geom.h" + +/** + * Function: matrix_int_det2 + * Computes and returns the determinant of a square integer matrix of size 2. + * + * Parameters: + * uij - element at the i-th row and j-th column, counting from 1 + * + * Returns: + * The integer determinant + */ +IntVector matrix_int_det2(IntVector u11, IntVector u12, + IntVector u21, IntVector u22); + +/** + * Function: matrix_int_det3 + * Computes and returns the determinant of a square integer matrix of size 3. + * + * Parameters: + * uij - element at the i-th row and j-th column, counting from 1 + * + * Returns: + * The integer determinant + */ +IntVector matrix_int_det3(IntVector u11, IntVector u12, IntVector u13, + IntVector u21, IntVector u22, IntVector u23, + IntVector u31, IntVector u32, IntVector u33); + +#endif -- cgit v1.2.3