triangle_math.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Harry Storbacka
00027 **    Mark Page
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_core.h"
00036 #include "vec3.h"
00037 
00042 template<typename Type>
00043 class CL_Trianglex
00044 {
00045 public:
00047         CL_Vec2<Type> p;
00048 
00049         // \brief Second triangle point
00050         CL_Vec2<Type> q;
00051 
00052         // \brief Third triangle point
00053         CL_Vec2<Type> r;
00054 
00055         CL_Trianglex() { }
00056         CL_Trianglex(const CL_Trianglex<Type> &copy) { p = copy.p; q = copy.q; r = copy.r;}
00057         CL_Trianglex(const CL_Vec2<Type> &point_p, const CL_Vec2<Type> &point_q, const CL_Vec2<Type> &point_r) { p = point_p; q = point_q; r = point_r;}
00058 
00061 
00062 public:
00063 
00068         bool point_inside(const CL_Vec2<Type> &point) const;
00069 
00073 
00074 public:
00075 
00077         CL_Trianglex<Type> &operator = (const CL_Trianglex<Type>& copy) { p = copy.p; q = copy.q; r = copy.r; return *this; }
00078 
00080         bool operator == (const CL_Trianglex<Type>& triangle) const {return ((p == triangle.p) && (q == triangle.q) && (r == triangle.r));}
00081 
00083         bool operator != (const CL_Trianglex<Type>& triangle) const {return ((p != triangle.p) || (q != triangle.q) || (r != triangle.r));}
00085 };
00086 
00090 class CL_Triangle : public CL_Trianglex<int>
00091 {
00092 public:
00093         CL_Triangle() { }
00094         CL_Triangle(const CL_Trianglex<int> &copy) : CL_Trianglex<int>(copy) {}
00095         CL_Triangle(const CL_Vec2<int> &point_p, const CL_Vec2<int> &point_q, const CL_Vec2<int> &point_r) : CL_Trianglex<int>(point_p, point_q, point_r) {}
00096 };
00097 
00101 class CL_Trianglef : public CL_Trianglex<float>
00102 {
00103 public:
00104         CL_Trianglef() { }
00105         CL_Trianglef(const CL_Trianglex<float> &copy) : CL_Trianglex<float>(copy) {}
00106         CL_Trianglef(const CL_Vec2<float> &point_p, const CL_Vec2<float> &point_q, const CL_Vec2<float> &point_r) : CL_Trianglex<float>(point_p, point_q, point_r) {}
00107 };
00108 
00112 class CL_Triangled : public CL_Trianglex<double>
00113 {
00114 public:
00115         CL_Triangled() { }
00116         CL_Triangled(const CL_Trianglex<double> &copy) : CL_Trianglex<double>(copy) {}
00117         CL_Triangled(const CL_Vec2<double> &point_p, const CL_Vec2<double> &point_q, const CL_Vec2<double> &point_r) : CL_Trianglex<double>(point_p, point_q, point_r) {}
00118 };
00119 
00121