triangle_math.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 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 "vec3.h"
34
35 namespace clan
36 {
39
43 template<typename Type>
44 class Trianglex
45 {
46 public:
48 Vec2<Type> p;
49
50 // \brief Second triangle point
51 Vec2<Type> q;
52
53 // \brief Third triangle point
54 Vec2<Type> r;
55
56 Trianglex() : p(), q(), r() {}
57 Trianglex(const Trianglex<Type> &copy) : p(copy.p), q(copy.q), r(copy.r) {}
58 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) {}
59
62
63 public:
64
69 bool point_inside(const Vec2<Type> &point) const;
70
74
75 public:
76
78 Trianglex<Type> &operator = (const Trianglex<Type>& copy) { p = copy.p; q = copy.q; r = copy.r; return *this; }
79
81 bool operator == (const Trianglex<Type>& triangle) const {return ((p == triangle.p) && (q == triangle.q) && (r == triangle.r));}
82
84 bool operator != (const Trianglex<Type>& triangle) const {return ((p != triangle.p) || (q != triangle.q) || (r != triangle.r));}
86 };
87
89 class Triangle : public Trianglex<int>
90 {
91 public:
92 Triangle() { }
93 Triangle(const Trianglex<int> &copy) : Trianglex<int>(copy) {}
94 Triangle(const Vec2<int> &point_p, const Vec2<int> &point_q, const Vec2<int> &point_r) : Trianglex<int>(point_p, point_q, point_r) {}
95 };
96
98 class Trianglef : public Trianglex<float>
99 {
100 public:
101 Trianglef() { }
102 Trianglef(const Trianglex<float> &copy) : Trianglex<float>(copy) {}
103 Trianglef(const Vec2<float> &point_p, const Vec2<float> &point_q, const Vec2<float> &point_r) : Trianglex<float>(point_p, point_q, point_r) {}
104 };
105
107 class Triangled : public Trianglex<double>
108 {
109 public:
110 Triangled() { }
111 Triangled(const Trianglex<double> &copy) : Trianglex<double>(copy) {}
112 Triangled(const Vec2<double> &point_p, const Vec2<double> &point_q, const Vec2<double> &point_r) : Trianglex<double>(point_p, point_q, point_r) {}
113 };
114
115 }
116
118
clan
Definition: clanapp.h:35
clan::Triangle::Triangle
Triangle(const Trianglex< int > &copy)
Definition: triangle_math.h:93
clan::Triangle
Triangles - Integer.
Definition: triangle_math.h:89
clan::Triangle::Triangle
Triangle(const Vec2< int > &point_p, const Vec2< int > &point_q, const Vec2< int > &point_r)
Definition: triangle_math.h:94
clan::Trianglex::operator==
bool operator==(const Trianglex< Type > &triangle) const
== operator.
Definition: triangle_math.h:81
clan::Trianglex::operator!=
bool operator!=(const Trianglex< Type > &triangle) const
!= operator.
Definition: triangle_math.h:84
clan::Trianglef
Triangles - Float.
Definition: triangle_math.h:98
clan::Trianglef::Trianglef
Trianglef()
Definition: triangle_math.h:101
clan::Trianglex::r
Vec2< Type > r
Definition: triangle_math.h:54
clan::Trianglex::Trianglex
Trianglex(const Trianglex< Type > &copy)
Definition: triangle_math.h:57
clan::Trianglex::p
Vec2< Type > p
First triangle point.
Definition: triangle_math.h:48
clan::Triangled::Triangled
Triangled(const Vec2< double > &point_p, const Vec2< double > &point_q, const Vec2< double > &point_r)
Definition: triangle_math.h:112
clan::Trianglex::Trianglex
Trianglex(const Vec2< Type > &point_p, const Vec2< Type > &point_q, const Vec2< Type > &point_r)
Definition: triangle_math.h:58
clan::Vec2
2D vector
Definition: line.h:48
clan::Trianglef::Trianglef
Trianglef(const Vec2< float > &point_p, const Vec2< float > &point_q, const Vec2< float > &point_r)
Definition: triangle_math.h:103
clan::Trianglef::Trianglef
Trianglef(const Trianglex< float > &copy)
Definition: triangle_math.h:102
clan::Triangled::Triangled
Triangled(const Trianglex< double > &copy)
Definition: triangle_math.h:111
clan::Trianglex::point_inside
bool point_inside(const Vec2< Type > &point) const
Return true if the point is inside the triangle.
clan::Trianglex::q
Vec2< Type > q
Definition: triangle_math.h:51
clan::Triangled::Triangled
Triangled()
Definition: triangle_math.h:110
clan::Triangle::Triangle
Triangle()
Definition: triangle_math.h:92
clan::Triangled
Triangles - Double.
Definition: triangle_math.h:107
clan::Trianglex
Triangles.
Definition: triangle_math.h:44
clan::Trianglex::operator=
Trianglex< Type > & operator=(const Trianglex< Type > &copy)
= operator.
Definition: triangle_math.h:78
clan::Trianglex::Trianglex
Trianglex()
Definition: triangle_math.h:56