OSDN Git Service

fix io.write.
[meshio/meshio.git] / include / 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 #ifndef SWIG
57 inline std::ostream &operator<<(std::ostream &os, const Vector3 &rhs)
58 {
59         return os
60                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ']';
61 }
62 #endif
63
64
65 struct Vector4
66 {
67         float x;
68         float y;
69         float z;
70         float w;
71
72         Vector4()
73         {}
74
75         Vector4(float _x, float _y, float _z, float _w)
76                 : x(_x), y(_y), z(_z), w(_w)
77                 {}
78 };
79 #ifndef SWIG
80 inline std::ostream &operator<<(std::ostream &os, const Vector4 &rhs)
81 {
82         return os
83                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ',' << rhs.w << ']';
84 }
85 #endif
86
87
88 struct Quaternion
89 {
90         float x;
91         float y;
92         float z;
93         float w;
94
95         Quaternion()
96         {}
97
98         Quaternion(float _x, float _y, float _z, float _w)
99                 : x(_x), y(_y), z(_z), w(_w)
100                 {}
101
102         float dot(const Quaternion &rhs)
103         {
104                 return x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w;
105         }
106 };
107 #ifndef SWIG
108 inline std::ostream &operator<<(std::ostream &os, const Quaternion &rhs)
109 {
110         return os
111                 << '[' << rhs.x << ',' << rhs.y << ',' << rhs.z << ',' << rhs.w << ']';
112 }
113 #endif
114
115
116 }
117 }
118
119 #endif // MESH_IO_LA_H_INCLUDED