-
Notifications
You must be signed in to change notification settings - Fork 0
/
vect.h
63 lines (47 loc) · 1.13 KB
/
vect.h
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
/*
* Naive 2D graphics vector and matrix implementation.
*
* Project: svg2ass
* File: vect.h
* Created: 2014-10-27
* Author: Urban Wallasch
*
* See LICENSE file for more details.
*/
#ifndef H_VECT_INCLUDED
#define H_VECT_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
double x;
double y;
} vec_t;
typedef struct {
// order matches SVG transform matrix!
double a, c, e;
double b, d, f;
// 0 0 1 implied!
} mtx_t;
#define VEC(X,Y) ((vec_t){(X),(Y)})
#define MTX(A,C,E,B,D,F) ((mtx_t){(A),(C),(E),(B),(D),(F)})
#define VEC_ZERO VEC( 0, 0 )
#define MTX_ZERO MTX( 0, 0, 0, \
0, 0, 0 )
#define MTX_UNI MTX( 1, 0, 0, \
0, 1, 0 )
vec_t vec_add( vec_t u, vec_t v );
vec_t vec_sub( vec_t u, vec_t v );
vec_t vec_scal( vec_t u, double f );
vec_t vec_mmul( mtx_t m, vec_t v );
vec_t vec_norm( vec_t v, int dir );
double vec_abs( vec_t v );
double vec_dot( vec_t u, vec_t v ); // vector dot (scalar) product
double vec_ang( vec_t u, vec_t v );
int vec_eq( vec_t u, vec_t v, double e );
mtx_t mtx_mmul( mtx_t m, mtx_t n );
#ifdef __cplusplus
}
#endif
#endif // H_VECT_INCLUDED
/* EOF */