OSDN Git Service

0ef6ee8210432e27fd937acc843e620ac555fcde
[meshio/meshio.git] / src / la.h
1 #ifndef MESH_IO_LA_H_INCLUDED
2 #define MESH_IO_LA_H_INCLUDED
3
4 #include <ostream>
5
6 namespace meshio {
7 namespace la {
8 /**
9  * \e$B@~7ABe?t\e(B(Linear Algebra)
10  */
11
12 struct Vector2
13 {
14         float x;
15         float y;
16
17         Vector2()
18         {}
19
20         Vector2(float _x, float _y)
21                 : x(_x), y(_y)
22                 {}
23 };
24 #ifndef SWIG
25 inline std::ostream &operator<<(std::ostream &os, const Vector2 &rhs)
26 {
27         return os
28                 << '[' << rhs.x << ',' << rhs.y << ']';
29 }
30 #endif
31
32
33 struct Vector3
34 {
35         float x;
36         float y;
37         float z;
38
39         Vector3()
40         {}
41
42         Vector3(float _x, float _y, float _z)
43                 : x(_x), y(_y), z(_z)
44                 {}
45
46         bool operator==(const Vector3 &rhs)const
47         {
48                 return x==rhs.x && y==rhs.y && z==rhs.z;
49         }
50
51         Vector3 operator+(const Vector3 &rhs)
52         {
53                 return Vector3(x+rhs.x, y+rhs.y, z+rhs.z);
54         }
55
56         Vector3 operator-(const Vector3 &rhs)
57         {
58                 return Vector3(x-rhs.x, y-rhs.y, z-rhs.z);
59         }
60 };
61 #ifndef SWIG
62 inline std::ostream &operator<<(std::ostream &os, const Vector3 &rhs)
63 {
64         return os
65                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ']';
66 }
67 #endif
68
69
70 struct Vector4
71 {
72         float x;
73         float y;
74         float z;
75         float w;
76
77         Vector4()
78         {}
79
80         Vector4(float _x, float _y, float _z, float _w)
81                 : x(_x), y(_y), z(_z), w(_w)
82                 {}
83 };
84 #ifndef SWIG
85 inline std::ostream &operator<<(std::ostream &os, const Vector4 &rhs)
86 {
87         return os
88                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ',' << rhs.w << ']';
89 }
90 #endif
91
92
93 struct Quaternion
94 {
95         float x;
96         float y;
97         float z;
98         float w;
99
100         Quaternion()
101         {}
102
103         Quaternion(float _x, float _y, float _z, float _w)
104                 : x(_x), y(_y), z(_z), w(_w)
105                 {}
106
107         float dot(const Quaternion &rhs)
108         {
109                 return x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w;
110         }
111 };
112 #ifndef SWIG
113 inline std::ostream &operator<<(std::ostream &os, const Quaternion &rhs)
114 {
115         return os
116                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ',' << rhs.w << ']';
117 }
118 #endif
119
120
121 }
122 }
123
124 #endif // MESH_IO_LA_H_INCLUDED