/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
#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
Vec3 *
98
vec3_new (sint a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
99
          sint b,
100
          sint c);
101
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
102
/**
103
 * Add Vector a to Vector
104
 */
105
Vec3 *
106
vec3_add_vec3 (Vec3 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
107
               Vec3 * b);
108
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
109
Vec3 *
110
vec3_add_vec3_16 (Vec3 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
111
                  Vec3_16 * b);
112
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
113
114
/**
115
 * @brief
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
116
 * allocates and initialises a Vec3_16 pointer.
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
117
 * 
118
 * @sa Vec3_16
119
 */
120
Vec3_16 *
61 by Gustav Hartvigsson
* Made the code more easy to read.
121
vec3_16_new (sshort a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
122
             sshort b,
123
             sshort c);
124
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
125
Vec3_16 *
126
vec3_16_add_vec3_16 (Vec3_16 * a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
127
                     Vec3_16 * b);
128
129
Vec3 *
130
vec3_16_add_vec3(Vec3_16 * a,
131
                 Vec3 * b);
132
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
133
134
/**
135
 * Allocates and initialises a Vec3_f pointer.
136
 */
137
Vec3_f *
138
vec3_f_new (sfloat a,
102 by Gustav Hartvigsson
* Finnished the Vectors... For the moment.
139
            sfloat b,
140
            sfloat c);
141
142
Vec3_f *
143
vec3_f_add_vec3_f (Vec3_f * a,
144
                   Vec3_f * b);
145
146
Vec3_f *
147
vec3_f_add_vec3 (Vec3_f * a,
148
                 Vec3 * b);
149
150
Vec3_f *
151
vec3_f_add_vec3_16 (Vec3_f * a,
152
                    Vec3_16 * b);
153
154
Vec3_f *
155
vec3_add_vec3_f (Vec3 * a,
156
                 Vec3_f * b);
157
158
Vec3_f *
159
vec3_16_add_vec3_f (Vec3_16 * a,
160
                    Vec3_f * b);
161
83 by Gustav Hartvigsson
* vec.h:
162
/** @} */
72 by Gustav Hartvigsson
* Added our own types for stability and shit and giggles.
163
164
44 by Gustav Hartvigsson
* Started to structuce the dectumentation a little better.
165
END_DECLS
27 by Gustav Hartvigsson
* added skeleton for the SBox type.
166
167
#endif /* __H_VEC__ */
168