/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
1
#ifndef __H_VEC__
2
#define __H_VEC__
3
4
#include <stdlib.h>
30 by Gustav Hartvigsson
* Made the code compile using CMake.
5
#include <stdint.h>
6
#include "defs.h"
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
7
8
/** @file
9
 * @defgroup Vectors Vectors
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
10
 * @addtogroup Vectors
11
 * @{
12
 * Vectors are multi value structures that can be used when doing some types of
13
 * maths.
14
 */
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
15
16
BEGIN_DECLS
17
18
/**
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
19
 * A Vector of three standard int values.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
20
 *
21
 * A Vec3 is considerer a primitive type and as such has no ref/unref memory
22
 * management and no vec_free function. You will have to do that yourself.
23
 *
24
 * @sa vec3_new
25
 * @sa Vec3_16
26
 */
27
typedef struct
61 by Gustav Hartvigsson
* Made the code more easy to read.
28
Vec3 {
29
  sint a;
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
30
  sint b;
31
  sint c;
32
} Vec3;
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
33
34
/**
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
35
 * A Vector of three 16 bit int values.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
36
 *
37
 * @sa vec3_16_new
38
 * @sa Vec3
39
 */
40
typedef struct
61 by Gustav Hartvigsson
* Made the code more easy to read.
41
Vec3_16 {
42
  sshort a;
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
43
  sshort b;
44
  sshort c;
45
} Vec3_16;
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
46
47
/**
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
48
 *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
49
 * A Vec3_f is a vector of three 32bit precision floating point values.
50
 */
51
typedef struct
52
Vec3_f {
53
  sfloat a;
54
  sfloat b;
55
  sfloat c;
56
} Vec3_f;
57
58
59
/**
60
 * Add Vectors together, resulting in a new vector.
61
 *
62
 * The type of vector that is returned depends on the types that were put in.
63
 *
64
 * Due to the reflective way of these operations, many may just be inverses of
65
 * others. IE: `vec3_add (Vec3 *, Vec3_16 *)` is the same as
66
 * `vec3_add (Vec3_16 *, Vec3 *)`.
67
 */
68
#define vec3_add(x, y) _Generic((x)\
69
                                 Vec3 *: _Generic((y)\
70
                                                 Vec3 *: vec3_add_vec3\
71
                                                 Vec3_16 *: vec3_add_vec3_16\
72
                                                 Vec3_f *: vec3_add_vec3_f\
73
                                                 )\
74
                                 Vec3_16 *: _Generic((y)\
75
                                                    Vec3 *: vec3_16_add_vec3\
76
                                                    Vec3_16 *: vec3_16_add_vec3_16\
77
                                                    Vec3_f *: vec3_16_add_vec3_f\
78
                                                    )\
79
                                 Vec3_f *: _Generic((y)\
80
                                                   Vec3 *: vec3_f_add_vec3\
81
                                                   Vec3_16 *: vec3_f_add_vec3_16\
82
                                                   Vec3_f *: vec3_f_add_vec3_f\
83
                                                   )\
84
                                 )(x,y)
85
86
#define vec_free(x) free (x)
87
88
89
90
/** @brief
91
 * allocates and initialises a Vec3 pointer.
92
 *
93
 * @sa Vec3
94
 */
95
Vec3 *
96
vec3_new (sint a, sint b, sint c);
97
98
/**
99
 * Add Vector a to Vector
100
 */
101
Vec3 *
102
vec3_add_vec3 (Vec3 * a, Vec3 * b);
103
104
Vec3 *
105
vec3_add_vec3_16 (Vec3 * a, Vec3_16 * b);
106
107
#define vec3_add_vec3_f(x, y) vec3_f_add_vec3(y,x)
108
109
110
/**
111
 * @brief
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
112
 * allocates and initialises a Vec3_16 pointer.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
113
 * 
114
 * @sa Vec3_16
115
 */
116
Vec3_16 *
61 by Gustav Hartvigsson
* Made the code more easy to read.
117
vec3_16_new (sshort a, sshort b, sshort c);
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
118
119
Vec3_16 *
120
vec3_16_add_vec3_16 (Vec3_16 * a, Vec3_16 * b);
121
122
#define vec3_16_add_vec3(x, y) vec3_add_vec3_16(y, x)
123
124
#define vec3_16_add_vec3_f(x,y) vec3_f_add_vec3_16(y, x)
125
126
127
128
/**
129
 * Allocates and initialises a Vec3_f pointer.
130
 */
131
Vec3_f *
132
vec3_f_new (sfloat a, sfloat b, sfloat c);
133
134
Vec3_f *
135
vec3_f_add_vec3_f (Vec3_f * a, Vec3_f * b);
136
137
Vec3_f *
138
vec3_f_add_vec3 (Vec3_f * a, Vec3 * b);
139
140
Vec3_f *
141
vec3_f_add_vec3_16 (Vec3_f * a, Vec3_16 * b);
142
143
144
/** @} */
145
146
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
147
END_DECLS
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
148
149
#endif /* __H_VEC__ */
150