diff options
Diffstat (limited to 'include/common')
-rw-r--r-- | include/common/geom.h | 93 | ||||
-rw-r--r-- | include/common/time.h | 4 |
2 files changed, 89 insertions, 8 deletions
diff --git a/include/common/geom.h b/include/common/geom.h index b3564a5..334e95c 100644 --- a/include/common/geom.h +++ b/include/common/geom.h | |||
@@ -15,6 +15,12 @@ | |||
15 | typedef int32_t IntVector; | 15 | typedef int32_t IntVector; |
16 | 16 | ||
17 | /** | 17 | /** |
18 | * Type: RealVector | ||
19 | * An abstract 1-D real vector. | ||
20 | */ | ||
21 | typedef double RealVector; | ||
22 | |||
23 | /** | ||
18 | * Struct: CartesianVector | 24 | * Struct: CartesianVector |
19 | * An abstract 2-D vector in cartesian coordinates. | 25 | * An abstract 2-D vector in cartesian coordinates. |
20 | * | 26 | * |
@@ -27,6 +33,19 @@ typedef struct { | |||
27 | } CartesianVector; | 33 | } CartesianVector; |
28 | 34 | ||
29 | /** | 35 | /** |
36 | * Struct: BarycentricVector | ||
37 | * An abstract barycentric coordinate tuple relative to a triangle. | ||
38 | * The third barycentric coordinate is deduced from the first two ones. | ||
39 | * | ||
40 | * Fields: | ||
41 | * a - the first barycentric coordinate | ||
42 | * b - the second barycentric coordinate | ||
43 | */ | ||
44 | typedef struct { | ||
45 | RealVector a, b; | ||
46 | } BarycentricVector; | ||
47 | |||
48 | /** | ||
30 | * Struct: CartesianMapping | 49 | * Struct: CartesianMapping |
31 | * A tuple of cartesian vectors representing a mapping. | 50 | * A tuple of cartesian vectors representing a mapping. |
32 | * | 51 | * |
@@ -38,6 +57,16 @@ typedef struct { | |||
38 | CartesianVector origin, target; | 57 | CartesianVector origin, target; |
39 | } CartesianMapping; | 58 | } CartesianMapping; |
40 | 59 | ||
60 | /** | ||
61 | * Struct: Triangle | ||
62 | * Represents a simple triangle with three vertices. | ||
63 | * | ||
64 | * Fields: | ||
65 | * v[] - array of vertices | ||
66 | */ | ||
67 | typedef struct { | ||
68 | CartesianVector v[3]; | ||
69 | } Triangle; | ||
41 | 70 | ||
42 | /** | 71 | /** |
43 | * Function: m | 72 | * Function: m |
@@ -66,6 +95,19 @@ CartesianMapping m(int x, int y); | |||
66 | CartesianVector v(int x, int y); | 95 | CartesianVector v(int x, int y); |
67 | 96 | ||
68 | /** | 97 | /** |
98 | * Function: b | ||
99 | * Shorthand for a barycentric vector. | ||
100 | * | ||
101 | * Parameters: | ||
102 | * a - the a-coordinate | ||
103 | * b - the b-coordinate | ||
104 | * | ||
105 | * Returns: | ||
106 | * A barycentric vector | ||
107 | */ | ||
108 | BarycentricVector b(double a, double b); | ||
109 | |||
110 | /** | ||
69 | * Function: mappings_equals | 111 | * Function: mappings_equals |
70 | * Compares two cartesian mappings. | 112 | * Compares two cartesian mappings. |
71 | * | 113 | * |
@@ -92,17 +134,54 @@ bool mappings_equals(CartesianMapping m1, CartesianMapping m2); | |||
92 | bool vector_equals(CartesianVector v1, CartesianVector v2); | 134 | bool vector_equals(CartesianVector v1, CartesianVector v2); |
93 | 135 | ||
94 | /** | 136 | /** |
95 | * Function: triangle_area | 137 | * Function: barycentric_vector_equals |
96 | * Computes the area of a triangle. | 138 | * Compares two barycentric vectors. |
139 | * | ||
140 | * Parameters: | ||
141 | * v1 - the first vector | ||
142 | * v2 - the second vector | ||
143 | * | ||
144 | * Returns: | ||
145 | * T(v1 is equal to v2) | ||
146 | */ | ||
147 | bool barycentric_vector_equals(BarycentricVector b1, BarycentricVector b2); | ||
148 | |||
149 | /** | ||
150 | * Function: square_area | ||
151 | * Computes the area of a square spawned by three positively oriented vertices. | ||
152 | * | ||
153 | * Parameters: | ||
154 | * vi - vertices | ||
155 | * | ||
156 | * Returns: | ||
157 | * The area of the square | ||
158 | */ | ||
159 | IntVector square_area(CartesianVector v1, CartesianVector v2, CartesianVector v3); | ||
160 | |||
161 | /** | ||
162 | * Function: cartesian_to_barycentric | ||
163 | * Computes and returns the barycentric coordinates of a given point in the given reference triangle. | ||
164 | * | ||
165 | * Parameters: | ||
166 | * t - reference triangle | ||
167 | * p - the vector to convert | ||
168 | * | ||
169 | * Returns: | ||
170 | * The barycentric coordinates vector | ||
171 | */ | ||
172 | BarycentricVector cartesian_to_barycentric(Triangle t, CartesianVector p); | ||
173 | |||
174 | /** | ||
175 | * Function: barycentric_to_cartesian | ||
176 | * Computes and returns the cartesian coordinates of a given point in the given reference triangle. | ||
97 | * | 177 | * |
98 | * Parameters: | 178 | * Parameters: |
99 | * v1 - first vertex | 179 | * t - reference triangle |
100 | * v2 - second vertex | 180 | * p - the vector to convert |
101 | * v3 - third vertex | ||
102 | * | 181 | * |
103 | * Returns: | 182 | * Returns: |
104 | * The area of the triangle spawned by the three supplied vertices | 183 | * The cartesian coordinate vector |
105 | */ | 184 | */ |
106 | IntVector triangle_area(CartesianVector v1, CartesianVector v2, CartesianVector v3); | 185 | CartesianVector barycentric_to_cartesian(Triangle t, BarycentricVector p); |
107 | 186 | ||
108 | #endif | 187 | #endif |
diff --git a/include/common/time.h b/include/common/time.h index 54a7bb2..e207ad7 100644 --- a/include/common/time.h +++ b/include/common/time.h | |||
@@ -5,6 +5,8 @@ | |||
5 | * File: time.h | 5 | * File: time.h |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include "geom.h" | ||
9 | |||
8 | /** | 10 | /** |
9 | * Constants: Time vectors | 11 | * Constants: Time vectors |
10 | * | 12 | * |
@@ -18,6 +20,6 @@ | |||
18 | * Type: TimeVector | 20 | * Type: TimeVector |
19 | * An abstract time vector. | 21 | * An abstract time vector. |
20 | */ | 22 | */ |
21 | typedef float TimeVector; | 23 | typedef RealVector TimeVector; |
22 | 24 | ||
23 | #endif | 25 | #endif |