Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Extras / HACD / hacdVector.h
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)\r
2  All rights reserved.\r
3  \r
4  \r
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\r
6  \r
7  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r
8  \r
9  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\r
10  \r
11  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.\r
12  \r
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
14  */\r
15 #pragma once\r
16 #ifndef HACD_VECTOR_H\r
17 #define HACD_VECTOR_H\r
18 #include<math.h>\r
19 #include<iostream>\r
20 #include "hacdVersion.h"\r
21 \r
22 namespace HACD\r
23 {\r
24     typedef double Real;\r
25         //!     Vector dim 3.\r
26         template < typename T > class Vec3\r
27         {\r
28         public:\r
29                 T &                                     X();\r
30                 T &                                     Y();\r
31                 T &                                     Z();\r
32                 const T &                       X() const;\r
33                 const T &                       Y() const;\r
34                 const T &                       Z() const;\r
35                 void                            Normalize();\r
36                 T                                       GetNorm() const;\r
37                 void                            operator= (const Vec3 & rhs);\r
38                 void                            operator+=(const Vec3 & rhs);\r
39                 void                            operator-=(const Vec3 & rhs);\r
40                 void                            operator-=(T a);\r
41                 void                            operator+=(T a);\r
42                 void                            operator/=(T a);\r
43                 void                            operator*=(T a);\r
44                 Vec3                            operator^ (const Vec3 & rhs) const;\r
45                 T                               operator* (const Vec3 & rhs) const;\r
46                 Vec3                            operator+ (const Vec3 & rhs) const;\r
47                 Vec3                            operator- (const Vec3 & rhs) const;\r
48                 Vec3                            operator- () const;\r
49                 Vec3                            operator* (T rhs) const;\r
50                 Vec3                            operator/ (T rhs) const;\r
51                                                         Vec3();\r
52                                                         Vec3(T a);\r
53                                                         Vec3(T x, T y, T z);\r
54                                                         Vec3(const Vec3 & rhs);\r
55                 /*virtual*/                     ~Vec3(void);\r
56 \r
57         private:\r
58                 T                                       m_data[3];\r
59         };\r
60     template<typename T>\r
61     const bool Colinear(const Vec3<T> & a, const Vec3<T> & b, const Vec3<T> & c);\r
62     template<typename T>\r
63     const T Volume(const Vec3<T> & a, const Vec3<T> & b, const Vec3<T> & c, const Vec3<T> & d);\r
64     \r
65 }\r
66 #include "hacdVector.inl"       // template implementation\r
67 #endif\r