summaryrefslogtreecommitdiff
path: root/include/common/geom.h
blob: b3564a5b3fe8c4d85304c6cc6bc35d510712dc6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef UPEM_MORPHING_GEOM
#define UPEM_MORPHING_GEOM

/**
 * File: geom.h
 */

#include <stdbool.h>
#include <inttypes.h>

/**
 * Type: IntVector
 * An abstract 1-D vector.
 */
typedef int32_t IntVector;

/**
 * Struct: CartesianVector
 * An abstract 2-D vector in cartesian coordinates.
 *
 * Fields:
 *   x - the horizontal component
 *   y - the vertical component
 */
typedef struct {
  IntVector x, y;
} CartesianVector;

/**
 * Struct: CartesianMapping
 * A tuple of cartesian vectors representing a mapping.
 *
 * Fields:
 *   origin - preimage vector
 *   target - image vector
 */
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.
 *
 * Parameters:
 *   v1 - the first vector
 *   v2 - the second vector
 *
 * Returns:
 *   T(v1 is equal to v2)
 */
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