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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#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;
/**
* Type: RealVector
* An abstract 1-D real vector.
*/
typedef double RealVector;
/**
* 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: BarycentricVector
* An abstract barycentric coordinate tuple relative to a triangle.
* The third barycentric coordinate is deduced from the first two ones.
*
* Fields:
* a - the first barycentric coordinate
* b - the second barycentric coordinate
*/
typedef struct {
RealVector a, b;
} BarycentricVector;
/**
* Struct: CartesianMapping
* A tuple of cartesian vectors representing a mapping.
*
* Fields:
* origin - preimage vector
* target - image vector
*/
typedef struct {
CartesianVector origin, target;
} CartesianMapping;
/**
* Struct: Triangle
* Represents a simple triangle with three vertices.
*
* Fields:
* v[] - array of vertices
*/
typedef struct {
CartesianVector v[3];
} Triangle;
/**
* 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: b
* Shorthand for a barycentric vector.
*
* Parameters:
* a - the a-coordinate
* b - the b-coordinate
*
* Returns:
* A barycentric vector
*/
BarycentricVector b(double a, double b);
/**
* 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: barycentric_vector_equals
* Compares two barycentric vectors.
*
* Parameters:
* v1 - the first vector
* v2 - the second vector
*
* Returns:
* T(v1 is equal to v2)
*/
bool barycentric_vector_equals(BarycentricVector b1, BarycentricVector b2);
/**
* Function: square_area
* Computes the area of a square spawned by three positively oriented vertices.
*
* Parameters:
* vi - vertices
*
* Returns:
* The area of the square
*/
IntVector square_area(CartesianVector v1, CartesianVector v2, CartesianVector v3);
/**
* Function: cartesian_to_barycentric
* Computes and returns the barycentric coordinates of a given point in the given reference triangle.
*
* Parameters:
* t - reference triangle
* p - the vector to convert
*
* Returns:
* The barycentric coordinates vector
*/
BarycentricVector cartesian_to_barycentric(Triangle t, CartesianVector p);
/**
* Function: barycentric_to_cartesian
* Computes and returns the cartesian coordinates of a given point in the given reference triangle.
*
* Parameters:
* t - reference triangle
* p - the vector to convert
*
* Returns:
* The cartesian coordinate vector
*/
CartesianVector barycentric_to_cartesian(Triangle t, BarycentricVector p);
#endif
|