-
Notifications
You must be signed in to change notification settings - Fork 0
/
vect.h
69 lines (50 loc) · 1.71 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
64
65
66
67
68
69
#ifndef VECT_H
#define VECT_H
#include <stdlib.h>
#include <stdio.h>
struct yeetVec {
double x;
double y;
double z;
double w;
};
struct vec {
int dimension;
union {
double *elements;
struct yeetVec *e;
};
};
struct mat2 {
int num_rows;
int num_cols;
double **elements;
};
struct vec* new_vec(int num_dimensions);
struct vec* new_random_vec(int num_dimensions, double min, double max);
struct vec* new_vec_of(int num_dimensions, double value);
void free_vec(struct vec*);
struct vec* new_vec2(double x, double y);
struct vec* new_vec3(double x, double y, double z);
struct vec* new_vec4(double w, double x, double y, double z);
struct vec* add_vec(struct vec* a, struct vec* b);
struct vec* add_vec_ip(struct vec* a, struct vec* b);
struct vec* add_scaled_vec_ip(struct vec* a, struct vec* b, double scaleFactor);
struct vec* subtract_vec(struct vec* a, struct vec* b);
struct vec* subtract_vec_ip(struct vec* a, struct vec* b);
struct vec* normalise_vec(struct vec* a);
struct vec* normalise_vec_ip(struct vec* a);
double magnitude_vec(struct vec* a);
double distance_vec(struct vec* a, struct vec* b);
double dot_product_vec(struct vec* a, struct vec* b);
struct vec* scalar_multiply_vec(struct vec* a, double multiplier);
struct vec* scalar_multiply_vec_ip(struct vec* a, double multiplier);
struct vec* copy_vec(struct vec*);
struct vec* perpendicular_vec(int num_vectors, struct vec** vectors);
/* do something to every value in a vector */
struct vec* do_on_vec_ip(struct vec * v, double (*func)(double));
/* get the smallest value in the vector */
double vec_min(const struct vec *v);
/* get the largest value in the vector */
double vec_max(const struct vec *v);
#endif