triangle_math.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 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 
31 #pragma once
32 
33 #include "../api_core.h"
34 #include "vec3.h"
35 
36 namespace clan
37 {
40 
44 template<typename Type>
45 class Trianglex
46 {
47 public:
50 
51  // \brief Second triangle point
53 
54  // \brief Third triangle point
56 
57  Trianglex() { }
58  Trianglex(const Trianglex<Type> &copy) { p = copy.p; q = copy.q; r = copy.r;}
59  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;}
60 
63 
64 public:
65 
70  bool point_inside(const Vec2<Type> &point) const;
71 
75 
76 public:
77 
79  Trianglex<Type> &operator = (const Trianglex<Type>& copy) { p = copy.p; q = copy.q; r = copy.r; return *this; }
80 
82  bool operator == (const Trianglex<Type>& triangle) const {return ((p == triangle.p) && (q == triangle.q) && (r == triangle.r));}
83 
85  bool operator != (const Trianglex<Type>& triangle) const {return ((p != triangle.p) || (q != triangle.q) || (r != triangle.r));}
87 };
88 
90 class Triangle : public Trianglex<int>
91 {
92 public:
93  Triangle() { }
94  Triangle(const Trianglex<int> &copy) : Trianglex<int>(copy) {}
95  Triangle(const Vec2<int> &point_p, const Vec2<int> &point_q, const Vec2<int> &point_r) : Trianglex<int>(point_p, point_q, point_r) {}
96 };
97 
99 class Trianglef : public Trianglex<float>
100 {
101 public:
102  Trianglef() { }
103  Trianglef(const Trianglex<float> &copy) : Trianglex<float>(copy) {}
104  Trianglef(const Vec2<float> &point_p, const Vec2<float> &point_q, const Vec2<float> &point_r) : Trianglex<float>(point_p, point_q, point_r) {}
105 };
106 
108 class Triangled : public Trianglex<double>
109 {
110 public:
111  Triangled() { }
112  Triangled(const Trianglex<double> &copy) : Trianglex<double>(copy) {}
113  Triangled(const Vec2<double> &point_p, const Vec2<double> &point_q, const Vec2<double> &point_r) : Trianglex<double>(point_p, point_q, point_r) {}
114 };
115 
116 }
117 
119 
Triangle(const Trianglex< int > &copy)
Definition: triangle_math.h:94
Triangles - Integer.
Definition: triangle_math.h:90
Triangle(const Vec2< int > &point_p, const Vec2< int > &point_q, const Vec2< int > &point_r)
Definition: triangle_math.h:95
bool operator==(const Trianglex< Type > &triangle) const
== operator.
Definition: triangle_math.h:82
bool operator!=(const Trianglex< Type > &triangle) const
!= operator.
Definition: triangle_math.h:85
Triangles - Float.
Definition: triangle_math.h:99
Trianglef()
Definition: triangle_math.h:102
Vec2< Type > r
Definition: triangle_math.h:55
Trianglex(const Trianglex< Type > &copy)
Definition: triangle_math.h:58
Vec2< Type > p
First triangle point.
Definition: triangle_math.h:49
Triangled(const Vec2< double > &point_p, const Vec2< double > &point_q, const Vec2< double > &point_r)
Definition: triangle_math.h:113
Trianglex(const Vec2< Type > &point_p, const Vec2< Type > &point_q, const Vec2< Type > &point_r)
Definition: triangle_math.h:59
2D vector
Definition: line.h:49
Trianglef(const Vec2< float > &point_p, const Vec2< float > &point_q, const Vec2< float > &point_r)
Definition: triangle_math.h:104
Trianglef(const Trianglex< float > &copy)
Definition: triangle_math.h:103
Triangled(const Trianglex< double > &copy)
Definition: triangle_math.h:112
bool point_inside(const Vec2< Type > &point) const
Return true if the point is inside the triangle.
Vec2< Type > q
Definition: triangle_math.h:52
Triangled()
Definition: triangle_math.h:111
Triangle()
Definition: triangle_math.h:93
Triangles - Double.
Definition: triangle_math.h:108
Triangles.
Definition: triangle_math.h:45
Trianglex< Type > & operator=(const Trianglex< Type > &copy)
= operator.
Definition: triangle_math.h:79
Trianglex()
Definition: triangle_math.h:57