00001 // Wild Magic Source Code 00002 // David Eberly 00003 // http://www.geometrictools.com 00004 // Copyright (c) 1998-2007 00005 // 00006 // This library is free software; you can redistribute it and/or modify it 00007 // under the terms of the GNU Lesser General Public License as published by 00008 // the Free Software Foundation; either version 2.1 of the License, or (at 00009 // your option) any later version. The license is available for reading at 00010 // either of the locations: 00011 // http://www.gnu.org/copyleft/lgpl.html 00012 // http://www.geometrictools.com/License/WildMagicLicense.pdf 00013 // The license applies to versions 0 through 4 of Wild Magic. 00014 // 00015 // Version: 4.0.0 (2006/06/28) 00016 00017 namespace Wm4 00018 { 00019 //---------------------------------------------------------------------------- 00020 template <class Real> 00021 LinComp<Real>::LinComp () 00022 { 00023 m_iType = CT_EMPTY; 00024 m_fMin = Math<Real>::MAX_REAL; 00025 m_fMax = -Math<Real>::MAX_REAL; 00026 } 00027 //---------------------------------------------------------------------------- 00028 template <class Real> 00029 LinComp<Real>::~LinComp () 00030 { 00031 } 00032 //---------------------------------------------------------------------------- 00033 template <class Real> 00034 LinComp<Real>& LinComp<Real>::operator= (const LinComp& rkComponent) 00035 { 00036 m_iType = rkComponent.m_iType; 00037 m_fMin = rkComponent.m_fMin; 00038 m_fMax = rkComponent.m_fMax; 00039 return *this; 00040 } 00041 //---------------------------------------------------------------------------- 00042 template <class Real> 00043 int LinComp<Real>::GetType () const 00044 { 00045 return m_iType; 00046 } 00047 //---------------------------------------------------------------------------- 00048 template <class Real> 00049 Real LinComp<Real>::GetMin () const 00050 { 00051 return m_fMin; 00052 } 00053 //---------------------------------------------------------------------------- 00054 template <class Real> 00055 Real LinComp<Real>::GetMax () const 00056 { 00057 return m_fMax; 00058 } 00059 //---------------------------------------------------------------------------- 00060 template <class Real> 00061 bool LinComp<Real>::Contains (Real fParam) const 00062 { 00063 return m_fMin <= fParam && fParam <= m_fMax; 00064 } 00065 //---------------------------------------------------------------------------- 00066 template <class Real> 00067 void LinComp<Real>::SetInterval (Real fMin, Real fMax) 00068 { 00069 m_iType = GetTypeFromInterval(fMin,fMax); 00070 m_fMin = fMin; 00071 m_fMax = fMax; 00072 } 00073 //---------------------------------------------------------------------------- 00074 template <class Real> 00075 int LinComp<Real>::GetTypeFromInterval (Real fMin, Real fMax) 00076 { 00077 if (fMin < fMax) 00078 { 00079 if (fMax == Math<Real>::MAX_REAL) 00080 { 00081 if (fMin == -Math<Real>::MAX_REAL) 00082 { 00083 return CT_LINE; 00084 } 00085 else 00086 { 00087 return CT_RAY; 00088 } 00089 } 00090 else 00091 { 00092 if (fMin == -Math<Real>::MAX_REAL) 00093 { 00094 return CT_RAY; 00095 } 00096 else 00097 { 00098 return CT_SEGMENT; 00099 } 00100 } 00101 } 00102 else if (fMin == fMax) 00103 { 00104 if (fMin != -Math<Real>::MAX_REAL && fMax != Math<Real>::MAX_REAL) 00105 { 00106 return CT_POINT; 00107 } 00108 } 00109 00110 return CT_EMPTY; 00111 } 00112 //---------------------------------------------------------------------------- 00113 template <class Real> 00114 bool LinComp<Real>::IsCanonical () const 00115 { 00116 if (m_iType == CT_RAY) 00117 { 00118 return m_fMin == (Real)0.0 && m_fMax == Math<Real>::MAX_REAL; 00119 } 00120 00121 if (m_iType == CT_SEGMENT) 00122 { 00123 return m_fMin == -m_fMax; 00124 } 00125 00126 if (m_iType == CT_POINT) 00127 { 00128 return m_fMin == (Real)0.0; 00129 } 00130 00131 if (m_iType == CT_EMPTY) 00132 { 00133 return m_fMin == Math<Real>::MAX_REAL 00134 && m_fMax == -Math<Real>::MAX_REAL; 00135 } 00136 00137 // m_iType == CT_LINE 00138 return true; 00139 } 00140 //---------------------------------------------------------------------------- 00141 } //namespace Wm4