/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
S_BEGIN_DECLS
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
17
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
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
#ifndef __MSC_VER
83 by Gustav Hartvigsson
* vec.h:
59
/**
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
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, y)\
84 by Gustav Hartvigsson
WOOPS!
69
                                 Vec3 *: _Generic((y)\
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
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
#endif /* __MSC_VER */
83 by Gustav Hartvigsson
* vec.h:
86
87
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
88
#define vec_free(x) free (x)
89
90
91
92
/** @brief
93
 * allocates and initialises a Vec3 pointer.
94
 *
95
 * @sa Vec3
96
 */
97
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
98
Vec3 *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
99
vec3_new (sint a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
100
          sint b,
101
          sint c);
102
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
103
/**
104
 * Add Vector a to Vector
105
 */
106
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
107
Vec3 *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
108
vec3_add_vec3 (Vec3 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
109
               Vec3 * b);
110
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
111
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
112
Vec3 *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
113
vec3_add_vec3_16 (Vec3 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
114
                  Vec3_16 * b);
115
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
116
117
/**
118
 * @brief
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
119
 * allocates and initialises a Vec3_16 pointer.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
120
 * 
121
 * @sa Vec3_16
122
 */
123
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
124
Vec3_16 *
61 by Gustav Hartvigsson
* Made the code more easy to read.
125
vec3_16_new (sshort a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
126
             sshort b,
127
             sshort c);
128
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
129
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
130
Vec3_16 *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
131
vec3_16_add_vec3_16 (Vec3_16 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
132
                     Vec3_16 * b);
133
134
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
135
Vec3 *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
136
vec3_16_add_vec3(Vec3_16 * a,
137
                 Vec3 * b);
138
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
139
140
/**
141
 * Allocates and initialises a Vec3_f pointer.
142
 */
143
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
144
Vec3_f *
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
145
vec3_f_new (sfloat a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
146
            sfloat b,
147
            sfloat c);
148
149
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
150
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
151
vec3_f_add_vec3_f (Vec3_f * a,
152
                   Vec3_f * b);
153
154
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
155
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
156
vec3_f_add_vec3 (Vec3_f * a,
157
                 Vec3 * b);
158
159
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
160
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
161
vec3_f_add_vec3_16 (Vec3_f * a,
162
                    Vec3_16 * b);
163
164
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
165
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
166
vec3_add_vec3_f (Vec3 * a,
167
                 Vec3_f * b);
168
169
S_EXPORTED
119 by Gustav Hartvigsson
* added S_EXPERTED to public functions.
170
Vec3_f *
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
171
vec3_16_add_vec3_f (Vec3_16 * a,
172
                    Vec3_f * b);
173
83 by Gustav Hartvigsson
* vec.h:
174
/** @} */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
175
176
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
177
S_END_DECLS
110 by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub.
178
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
179
#endif /* __H_VEC__ */
180