1 /* vector.h: operations on vectors and points. */
2 
3 #ifndef VECTOR_H
4 #define VECTOR_H
5 
6 #include "types.h"
7 #include "exception.h"
8 
9 /* Our vectors are represented as displacements along the x and y axes.  */
10 
11 typedef struct {
12   gfloat dx, dy, dz;
13 } vector_type;
14 
15 /* Consider a point as a vector from the origin.  */
16 extern vector_type make_vector(const at_real_coord);
17 
18 /* And a vector as a point, i.e., a displacement from the origin.  */
19 extern at_real_coord vector_to_point(const vector_type);
20 
21 /* Definitions for these common operations can be found in any decent
22    linear algebra book, and most calculus books.  */
23 
24 extern gfloat magnitude(const vector_type);
25 extern vector_type normalize(const vector_type);
26 
27 extern vector_type Vadd(const vector_type, const vector_type);
28 extern gfloat Vdot(const vector_type, const vector_type);
29 extern vector_type Vmult_scalar(const vector_type, const gfloat);
30 extern gfloat Vangle(const vector_type in, const vector_type out, at_exception_type * exp);
31 
32 /* These operations could have been named `P..._vector' just as well as
33    V..._point, so we may as well allow both names.  */
34 #define Padd_vector Vadd_point
35 extern at_real_coord Vadd_point(const at_real_coord, const vector_type);
36 
37 #define Psubtract_vector Vsubtract_point
38 extern at_real_coord Vsubtract_point(const at_real_coord, const vector_type);
39 
40 /* This returns the rounded sum.  */
41 #define IPadd_vector Vadd_int_point
42 extern at_coord Vadd_int_point(const at_coord, const vector_type);
43 
44 /* Take the absolute value of both components.  */
45 extern vector_type Vabs(const vector_type);
46 
47 /* Operations on points with real coordinates.  It is not orthogonal,
48    but more convenient, to have the subtraction operator return a
49    vector, and the addition operator return a point.  */
50 extern vector_type Psubtract(const at_real_coord, const at_real_coord);
51 
52 /* These are heavily used in spline fitting.  */
53 extern at_real_coord Padd(const at_real_coord, const at_real_coord);
54 extern at_real_coord Pmult_scalar(const at_real_coord, const gfloat);
55 
56 /* Similarly, for points with integer coordinates; here, a subtraction
57    operator that does return another point is useful.  */
58 extern vector_type IPsubtract(const at_coord, const at_coord);
59 extern at_coord IPsubtractP(const at_coord, const at_coord);
60 extern at_coord IPadd(const at_coord, const at_coord);
61 extern at_coord IPmult_scalar(const at_coord, const int);
62 extern at_real_coord IPmult_real(const at_coord, const gfloat);
63 extern gboolean IPequal(const at_coord, const at_coord);
64 
65 #endif /* not VECTOR_H */
66