line.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 **    Mark Page
00027 */
00028 
00031 
00032 #pragma once
00033 
00034 #include "../api_core.h"
00035 
00036 template<typename Type>
00037 class CL_Line2x;
00038 
00039 template<typename Type>
00040 class CL_Line3x;
00041 
00042 template<typename Type>
00043 class CL_Rectx;
00044 
00045 template<typename Type>
00046 class CL_Vec2;
00047 
00048 class CL_Angle;
00049 
00054 template<typename Type>
00055 class CL_Line3x
00056 {
00057 public:
00058         CL_Vec3<Type> p;
00059         CL_Vec3<Type> q;
00060 
00061         CL_Line3x() { }
00062         CL_Line3x(const CL_Line3x<Type> &copy) { p = copy.p; q = copy.q;}
00063         CL_Line3x(const CL_Vec3<Type> &point_p, const CL_Vec3<Type> &point_q) { p = point_p; q = point_q; }
00064 
00067 public:
00074         CL_Vec3<Type> get_intersection( const CL_Line3x<Type> &second, bool &intersect, Type range = (Type) 0.5 ) const;
00075 
00079 public:
00081         CL_Line3x<Type> &operator = (const CL_Line3x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
00082 
00084         bool operator == (const CL_Line3x<Type>& line) const {return ((p == line.p) && (q == line.q));}
00085 
00087         bool operator != (const CL_Line3x<Type>& line) const {return ((p != line.p) || (q != line.q));}
00089 };
00090 
00095 template<typename Type>
00096 class CL_Line2x
00097 {
00098 public:
00100         CL_Vec2<Type> p;
00101 
00102         // \brief Another point on the line
00103         CL_Vec2<Type> q;
00104 
00105         CL_Line2x() { }
00106         CL_Line2x(const CL_Line2x<Type> &copy) { p = copy.p; q = copy.q;}
00107         CL_Line2x(const CL_Vec2<Type> &point_p, const CL_Vec2<Type> &point_q) { p = point_p; q = point_q; }
00108         CL_Line2x(const CL_Vec2<Type> &point_p, Type gradient) { p = point_p; q.x = (Type) 1; q.y = gradient; }
00109 
00112 public:
00118         CL_Vec2<Type> get_intersection( const CL_Line2x<Type> &second, bool &intersect ) const;
00119 
00124         Type point_right_of_line( CL_Vec2<Type> point ) const {return (q.x - p.x) * (point.y - p.y) - (point.x - p.x) * (q.y - p.y);}
00125 
00129 
00130 public:
00131 
00135 public:
00137         CL_Line2x<Type> &operator = (const CL_Line2x<Type>& copy) { p = copy.p; q = copy.q; return *this; }
00138 
00140         bool operator == (const CL_Line2x<Type>& line) const {return ((p == line.p) && (q == line.q));}
00141 
00143         bool operator != (const CL_Line2x<Type>& line) const {return ((p != line.p) || (q != line.q));}
00145 };
00146 
00150 class CL_Line2 : public CL_Line2x<int>
00151 {
00152 public:
00153         CL_Line2() : CL_Line2x<int>() { }
00154         CL_Line2(const CL_Line2x<int> &copy) : CL_Line2x<int>(copy) { }
00155         CL_Line2(const CL_Vec2<int> &point_p, const CL_Vec2<int> &point_q) : CL_Line2x<int>(point_p, point_q) { }
00156         CL_Line2(const CL_Vec2<int> &point_p, int gradient) : CL_Line2x<int>(point_p, gradient) { }
00157 };
00158 
00162 class CL_Line2f : public CL_Line2x<float>
00163 {
00164 public:
00165         CL_Line2f() : CL_Line2x<float>() { }
00166         CL_Line2f(const CL_Line2x<float> &copy) : CL_Line2x<float>(copy) { }
00167         CL_Line2f(const CL_Vec2<float> &point_p, const CL_Vec2<float> &point_q) : CL_Line2x<float>(point_p, point_q) { }
00168         CL_Line2f(const CL_Vec2<float> &point_p, float gradient) : CL_Line2x<float>(point_p, gradient) { }
00169 };
00170 
00174 class CL_Line2d : public CL_Line2x<double>
00175 {
00176 public:
00177         CL_Line2d() : CL_Line2x<double>() { }
00178         CL_Line2d(const CL_Line2x<double> &copy) : CL_Line2x<double>(copy) { }
00179         CL_Line2d(const CL_Vec2<double> &point_p, const CL_Vec2<double> &point_q) : CL_Line2x<double>(point_p, point_q) { }
00180         CL_Line2d(const CL_Vec2<double> &point_p, double gradient) : CL_Line2x<double>(point_p, gradient) { }
00181 };
00182 
00186 class CL_Line3 : public CL_Line3x<int>
00187 {
00188 public:
00189         CL_Line3() : CL_Line3x<int>() { }
00190         CL_Line3(const CL_Line3x<int> &copy) : CL_Line3x<int>(copy) { }
00191         CL_Line3(const CL_Vec3<int> &point_p, const CL_Vec3<int> &point_q) : CL_Line3x<int>(point_p, point_q) { }
00192 };
00193 
00197 class CL_Line3f : public CL_Line3x<float>
00198 {
00199 public:
00200         CL_Line3f() : CL_Line3x<float>() { }
00201         CL_Line3f(const CL_Line3x<float> &copy) : CL_Line3x<float>(copy) { }
00202         CL_Line3f(const CL_Vec3<float> &point_p, const CL_Vec3<float> &point_q) : CL_Line3x<float>(point_p, point_q) { }
00203 };
00204 
00208 class CL_Line3d : public CL_Line3x<double>
00209 {
00210 public:
00211         CL_Line3d() : CL_Line3x<double>() { }
00212         CL_Line3d(const CL_Line3x<double> &copy) : CL_Line3x<double>(copy) { }
00213         CL_Line3d(const CL_Vec3<double> &podouble_p, const CL_Vec3<double> &podouble_q) : CL_Line3x<double>(podouble_p, podouble_q) { }
00214 };
00215