nux-1.14.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef LINE2D_H 00024 #define LINE2D_H 00025 00026 #include "Vector2.h" 00027 00028 namespace nux 00029 { 00030 00031 template<typename T> 00032 class Line2D 00033 { 00034 public: 00035 Line2D(); 00036 ~Line2D(); 00037 Line2D (const Line2D &line); 00038 Line2D (T lx_start, T ly_start, T lz_start, 00039 T lx_end, T ly_end, T lz_end); 00040 Line2D (const Vec2<T>& pt, Vec2<T> v); 00041 00042 const Line2D<T>& operator = (const Line2D<T>&); 00043 bool operator == (const Line2D<T>& line) const; 00044 00045 float Length() const; 00046 const Vec2<T> GetDirectionVector() const; 00047 const Vec2<T> GetStartPoint() const; 00048 const Vec2<T> GetEndPoint() const; 00049 00050 private: 00051 T x_start, y_start; 00052 T x_end, y_end; 00053 00054 }; 00055 00056 template<typename T> 00057 Line2D<T>::Line2D() 00058 { 00059 x_start = y_start = x_end = y_end = 0; 00060 } 00061 00062 template<typename T> 00063 Line2D<T>::~Line2D() 00064 { 00065 00066 } 00067 00068 template<typename T> 00069 Line2D<T>::Line2D (const Line2D &line) 00070 { 00071 x_start = line.x_start; 00072 x_end = line.x_end; 00073 y_start = line.y_start; 00074 y_end = line.y_end; 00075 } 00076 00077 template<typename T> 00078 Line2D<T>::Line2D (T lx_start, T ly_start, T lz_start, 00079 T lx_end, T ly_end, T lz_end) 00080 { 00081 x_start = lx_start; 00082 x_end = lx_end; 00083 y_start = ly_start; 00084 y_end = ly_end; 00085 } 00086 00087 template<typename T> 00088 Line2D<T>::Line2D (const Vec2<T>& pt, Vec2<T> v) 00089 { 00090 x_start = pt.x; 00091 y_start = pt.y; 00092 00093 x_end = x_start + v.x; 00094 y_end = y_start + v.y; 00095 } 00096 00097 template<typename T> 00098 const Line2D<T>& Line2D<T>::operator = (const Line2D<T>& Line) 00099 { 00100 x_start = Line.x_start; 00101 x_end = Line.x_end; 00102 y_start = Line.y_start; 00103 y_end = Line.y_end; 00104 } 00105 00106 template<typename T> 00107 bool Line2D<T>::operator == (const Line2D<T>& line) const 00108 { 00109 if ( (x_start == line.x_start) && 00110 (y_start == line.y_start) && 00111 (x_end == line.x_end) && 00112 (y_end == line.y_end) ) 00113 { 00114 return true; 00115 } 00116 else 00117 { 00118 return false; 00119 } 00120 } 00121 00122 template<typename T> 00123 float Line2D<T>::Length() const 00124 { 00125 float l; 00126 l = (float) std::sqrt ( (x_end - x_start) * (x_end - x_start) + (y_end - y_start) * (y_end - y_start) ); 00127 00128 return l; 00129 } 00130 00131 template<typename T> 00132 const Vec2<T> Line2D<T>::GetDirectionVector() const 00133 { 00134 return Vec2<T> (x_start - x_end, y_start - y_end); 00135 } 00136 00137 template<typename T> 00138 const Vec2<T> Line2D<T>::GetStartPoint() const 00139 { 00140 Vec2<T> p (x_start, y_start); 00141 return p; 00142 } 00143 00144 template<typename T> 00145 const Vec2<T> Line2D<T>::GetEndPoint() const 00146 { 00147 Vec2<T> p (x_end, y_end); 00148 return p; 00149 } 00150 00151 00152 }; 00153 00154 #endif // LINE2D_H