triangle_math.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2016 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Harry Storbacka
27 ** Mark Page
28 */
29 
30 #pragma once
31 
32 #include "vec3.h"
33 
34 namespace clan
35 {
38 
42  template<typename Type>
43  class Trianglex
44  {
45  public:
48 
49  // \brief Second triangle point
51 
52  // \brief Third triangle point
54 
55  Trianglex() : p(), q(), r() {}
56  Trianglex(const Trianglex<Type> &copy) : p(copy.p), q(copy.q), r(copy.r) {}
57  Trianglex(const Vec2<Type> &point_p, const Vec2<Type> &point_q, const Vec2<Type> &point_r) : p(point_p), q(point_q), r(point_r) {}
58 
63  bool point_inside(const Vec2<Type> &point) const;
64 
65  Trianglex<Type> &operator = (const Trianglex<Type>& copy) { p = copy.p; q = copy.q; r = copy.r; return *this; }
66  bool operator == (const Trianglex<Type>& triangle) const { return ((p == triangle.p) && (q == triangle.q) && (r == triangle.r)); }
67  bool operator != (const Trianglex<Type>& triangle) const { return ((p != triangle.p) || (q != triangle.q) || (r != triangle.r)); }
68  };
69 
71  class Triangle : public Trianglex<int>
72  {
73  public:
74  Triangle() { }
75  Triangle(const Trianglex<int> &copy) : Trianglex<int>(copy) {}
76  Triangle(const Vec2<int> &point_p, const Vec2<int> &point_q, const Vec2<int> &point_r) : Trianglex<int>(point_p, point_q, point_r) {}
77  };
78 
80  class Trianglef : public Trianglex<float>
81  {
82  public:
83  Trianglef() { }
84  Trianglef(const Trianglex<float> &copy) : Trianglex<float>(copy) {}
85  Trianglef(const Vec2<float> &point_p, const Vec2<float> &point_q, const Vec2<float> &point_r) : Trianglex<float>(point_p, point_q, point_r) {}
86  };
87 
89  class Triangled : public Trianglex<double>
90  {
91  public:
92  Triangled() { }
93  Triangled(const Trianglex<double> &copy) : Trianglex<double>(copy) {}
94  Triangled(const Vec2<double> &point_p, const Vec2<double> &point_q, const Vec2<double> &point_r) : Trianglex<double>(point_p, point_q, point_r) {}
95  };
96 
98 }
Definition: clanapp.h:35
Triangles - Integer.
Definition: triangle_math.h:71
Trianglex(const Vec2< Type > &point_p, const Vec2< Type > &point_q, const Vec2< Type > &point_r)
Definition: triangle_math.h:57
2D vector
Definition: line.h:46
Triangle(const Trianglex< int > &copy)
Definition: triangle_math.h:75
Triangles - Float.
Definition: triangle_math.h:80
bool operator!=(const Trianglex< Type > &triangle) const
Definition: triangle_math.h:67
Trianglex< Type > & operator=(const Trianglex< Type > &copy)
Definition: triangle_math.h:65
Triangled()
Definition: triangle_math.h:92
Triangle()
Definition: triangle_math.h:74
bool point_inside(const Vec2< Type > &point) const
Return true if the point is inside the triangle.
bool operator==(const Trianglex< Type > &triangle) const
Definition: triangle_math.h:66
Trianglex()
Definition: triangle_math.h:55
Trianglef(const Trianglex< float > &copy)
Definition: triangle_math.h:84
Triangled(const Trianglex< double > &copy)
Definition: triangle_math.h:93
Trianglex(const Trianglex< Type > &copy)
Definition: triangle_math.h:56
Vec2< Type > r
Definition: triangle_math.h:53
Trianglef(const Vec2< float > &point_p, const Vec2< float > &point_q, const Vec2< float > &point_r)
Definition: triangle_math.h:85
Triangles - Double.
Definition: triangle_math.h:89
Triangled(const Vec2< double > &point_p, const Vec2< double > &point_q, const Vec2< double > &point_r)
Definition: triangle_math.h:94
Triangles.
Definition: triangle_math.h:43
Vec2< Type > p
First triangle point.
Definition: triangle_math.h:47
Trianglef()
Definition: triangle_math.h:83
Triangle(const Vec2< int > &point_p, const Vec2< int > &point_q, const Vec2< int > &point_r)
Definition: triangle_math.h:76
Vec2< Type > q
Definition: triangle_math.h:50