triangle_math.h Source File - ClanLib SDK
Description: triangle_math.h Source File

triangle_math.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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
34namespace clan
35{
38
42 template<typename Type>
43 class Trianglex
44 {
45 public:
47 Vec2<Type> p;
48
49 // \brief Second triangle point
50 Vec2<Type> q;
51
52 // \brief Third triangle point
53 Vec2<Type> r;
54
55 Trianglex() : p(), q(), r() {}
56 Trianglex(const Trianglex<Type> &copy) = default;
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) = default;
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}
clan::Triangle::Triangle
Triangle()
Definition triangle_math.h:74
clan::Triangle::Triangle
Triangle(const Trianglex< int > &copy)
Definition triangle_math.h:75
clan::Triangle::Triangle
Triangle(const Vec2< int > &point_p, const Vec2< int > &point_q, const Vec2< int > &point_r)
Definition triangle_math.h:76
clan::Triangled::Triangled
Triangled(const Trianglex< double > &copy)
Definition triangle_math.h:93
clan::Triangled::Triangled
Triangled()
Definition triangle_math.h:92
clan::Triangled::Triangled
Triangled(const Vec2< double > &point_p, const Vec2< double > &point_q, const Vec2< double > &point_r)
Definition triangle_math.h:94
clan::Trianglef::Trianglef
Trianglef(const Vec2< float > &point_p, const Vec2< float > &point_q, const Vec2< float > &point_r)
Definition triangle_math.h:85
clan::Trianglef::Trianglef
Trianglef(const Trianglex< float > &copy)
Definition triangle_math.h:84
clan::Trianglef::Trianglef
Trianglef()
Definition triangle_math.h:83
clan::Trianglex::Trianglex
Trianglex(const Trianglex< Type > &copy)=default
clan::Trianglex::Trianglex
Trianglex(const Vec2< Type > &point_p, const Vec2< Type > &point_q, const Vec2< Type > &point_r)
Definition triangle_math.h:57
clan::Trianglex::Trianglex
Trianglex()
Definition triangle_math.h:55
clan::Trianglex::operator=
Trianglex< Type > & operator=(const Trianglex< Type > &copy)=default
clan::Trianglex::point_inside
bool point_inside(const Vec2< Type > &point) const
Return true if the point is inside the triangle.
clan::Trianglex::operator==
bool operator==(const Trianglex< Type > &triangle) const
Definition triangle_math.h:66
clan::Trianglex::operator!=
bool operator!=(const Trianglex< Type > &triangle) const
Definition triangle_math.h:67
clan::Trianglex::q
Vec2< Type > q
Definition triangle_math.h:50
clan::Trianglex::r
Vec2< Type > r
Definition triangle_math.h:53
clan::Trianglex::p
Vec2< Type > p
First triangle point.
Definition triangle_math.h:47
clan::Vec2
2D vector
Definition vec2.h:76
clan::FillMode::point
@ point
Definition graphic_context.h:78
clan
Definition clanapp.h:36