Files Classes Functions Hierarchy
00001 #ifndef LINECHOPPED_H 00002 #define LINECHOPPED_H 00003 00004 #include <cassert> 00005 #include <list> 00006 #include <sstream> 00007 using namespace std; 00008 00009 #include <line.h> 00010 #include <mathlib.h> 00011 #include <point.h> 00012 00016 template< typename PT, typename PD > 00017 class linechopped 00018 { 00019 public: 00020 00022 line<PT,PD> ln; 00023 00025 list< point2<PD> > chain; 00026 00028 linechopped 00029 ( 00030 line<PT,PD> const & ln_, 00031 point2<PD> const & seg 00032 ) 00033 : ln(ln_) 00034 { chain.push_back( seg ); } 00035 00036 typedef typename list< point2<PD> >::iterator listiter; 00037 00041 boolc split 00042 ( 00043 listiter & posnew, 00044 listiter pos, 00045 line<PT,PD> const & L2 00046 ); 00047 00048 }; 00049 00050 00054 template< typename PT, typename INDX > 00055 class pointindexed 00056 { 00057 public: 00058 00060 PT pt; 00062 INDX index; 00063 00065 pointindexed(PT const & pt_, INDX const index_) 00066 : pt(pt_), index(index_) {} 00067 00069 operator string () const 00070 { string s( (stringc)pt ); s += " "; stringstream ss; 00071 ss << index; return s + ss.str(); } 00072 00074 boolc operator == ( pointindexed<PT,INDX> const & p2 ) const 00075 { return (index==p2.index) && (pt==p2.pt); } 00076 }; 00077 00078 template< typename PT, typename INDX > 00079 ostream & operator << (ostream & os, pointindexed<PT,INDX> const & p) 00080 { return os << (stringc)p; } 00081 00082 00089 template< typename PT, typename PD, typename INDX > 00090 class linechoppedindexed 00091 { 00092 public: 00093 00095 line<PT,PD> ln; 00096 00098 list< pointindexed< point2<PD>, INDX> > chain; 00099 00101 linechoppedindexed 00102 ( 00103 line<PT,PD> const & ln_, 00104 pointindexed< point2<PD>, INDX > const & seg 00105 ) 00106 : ln(ln_) 00107 { chain.push_back( seg ); } 00108 00109 typedef typename list< pointindexed< point2<PD>, INDX > >::iterator 00110 listiter; 00111 00113 boolc split 00114 ( 00115 listiter & posnew, 00116 listiter pos, 00117 line<PT,PD> const & L2 00118 ); 00119 00120 00121 }; 00122 00123 00124 00125 //--------------------------------------------------------- 00126 // Implementation 00127 00128 00129 00130 template< typename PT, typename PD > 00131 boolc linechopped<PT,PD>::split 00132 ( 00133 listiter & posnew, 00134 listiter pos, 00135 line<PT,PD> const & L2 00136 ) 00137 { 00138 bool res; 00139 point2<PD> t; 00140 res = solver<PD>::d2linearequ 00141 (t,ln.nml,L2.nml*((PD)-1.0), L2.pos - ln.pos); 00142 00143 if (res==false) 00144 return false; 00145 00146 PD t0(t[0]); 00147 00148 if (t0<(*pos)[0]) 00149 return false; 00150 00151 if (t0>(*pos)[1]) 00152 return false; 00153 00154 // The line is being split. 00155 00156 PD k0((*pos)[0]); 00157 (*pos)[0] = t0; 00158 00159 posnew = chain.insert(pos,point2<PD>(k0,t0)); 00160 00161 return true; 00162 } 00163 00164 00165 00166 template< typename PT, typename PD, typename INDX > 00167 boolc linechoppedindexed<PT,PD,INDX>::split 00168 ( 00169 listiter & posnew, 00170 listiter pos, 00171 line<PT,PD> const & L2 00172 ) 00173 { 00174 bool res; 00175 point2<PD> t; 00176 res = solver<PD>::d2linearequ 00177 (t,ln.nml,L2.nml*((PD)-1.0), L2.pos - ln.pos); 00178 00179 if (res==false) 00180 return false; 00181 00182 PD t0(t[0]); 00183 00184 if (t0<(*pos).pt[0]) 00185 return false; 00186 00187 if (t0>(*pos).pt[1]) 00188 return false; 00189 00190 PD k0((*pos).pt[0]); 00191 (*pos).pt[0] = t0; 00192 00193 posnew = chain.insert(pos,pointindexed< point2<PD>, INDX >( point2<PD>(k0,t0),0)); 00194 00195 return true; 00196 } 00197 00198 00199 00200 00201 00202 00203 00204 #endif 00205 00206
1.5.8