proj home

Files   Classes   Functions   Hierarchy  

windowscaleD2.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <string>
00004 using namespace std;
00005 
00006 #include <stringconvert.h>
00007 #include <windowscaleD2.h>
00008 #include <zero.h>
00009 
00010 windowscaleD2 windowscaleD2::unit(0,0,1,1);
00011 windowscaleD2 windowscaleD2::unitcentered(-0.5,-0.5,0.5,0.5);
00012 
00013 windowscaleD2::windowscaleD2()
00014 {
00015 }
00016 
00017 void windowscaleD2::construct
00018 (
00019   doublec xmin_, 
00020   doublec ymin_, 
00021   doublec xmax_, 
00022   doublec ymax_ 
00023 )
00024 {
00025   xmin=xmin_;
00026   ymin=ymin_;
00027   xmax=xmax_;
00028   ymax=ymax_;
00029 
00030   update();
00031 }
00032 
00033 windowscaleD2::windowscaleD2
00034 (
00035   doublec xmin_, 
00036   doublec ymin_, 
00037   doublec xmax_, 
00038   doublec ymax_ 
00039 )
00040   : xmin(xmin_), ymin(ymin_), xmax(xmax_), ymax(ymax_)
00041 {
00042   update();
00043 }
00044 
00045 
00046 
00047 boolc windowscaleD2::unitscale(double & x, double & y) const
00048 {
00049   bool res=true;
00050 
00051   assert(oneoverxlength!=0);
00052   assert(oneoverylength!=0);
00053   x = (x-xmin)*oneoverxlength;
00054   y -= ymin;
00055   y *= oneoverylength;
00056   //y = (y-ymin)*oneoverylength;
00057 
00058 /*
00059   if (unitscale_inside)
00060   {
00061     assert(x>=0.0);
00062     assert(y>=0.0);
00063     assert(x<=1.0);
00064     assert(y<=1.0);
00065   }
00066 */
00067 
00068 //TODO
00069   res &= (x+zero<double>::val>=0.0);
00070   res &= (y+zero<double>::val>=0.0);
00071   res &= (x<=(double)1.0+zero<double>::val);
00072   res &= (y<=(double)1.0+zero<double>::val);
00073 
00074 #ifndef NDEBUG
00075 //if (isinside(x,y)==false)
00076 //{
00077 //  cout << "*this=" << (stringc)(*this) << endl;
00078 //  cout << SHOW(x) << " " SHOW(y) << endl;
00079 //  cout << SHOW(ymax-y) << endl;
00080 //}
00081 #endif
00082 
00083   //assert( isinside(x,y) );
00084   return res;
00085 }
00086 
00087 void windowscaleD2::unitscaleInverse(double & x, double & y) const
00088 {
00089   x = (xmax-xmin)*x + xmin;
00090   y = (ymax-ymin)*y + ymin;
00091 }
00092 
00093 void windowscaleD2::unitscaleInverse_x(double & x) const
00094 {
00095   x = (xmax-xmin)*x + xmin;
00096 }
00097 
00098 void windowscaleD2::unitscaleInverse_y(double & y) const
00099 {
00100   y = (ymax-ymin)*y + ymin;
00101 }
00102 
00103 // Includes boundary.
00104 boolc windowscaleD2::isinside(doublec x, doublec y) const
00105 {
00106 //cout << "isinside" << SHOW(x) << " " << SHOW(y) << endl;
00107   if (x+zero<double>::val<xmin)
00108     return false;
00109 
00110   if (x>xmax+zero<double>::val)
00111     return false;
00112 
00113   if (y+zero<double>::val<ymin)
00114     return false;
00115 
00116   if (y>ymax+zero<double>::val)
00117     return false;
00118 
00119   return true;
00120 }
00121 
00122 doublec windowscaleD2::widthoverheight() const
00123 {
00124   assert(ymax-ymin!=0);
00125   return (xmax-xmin)/(ymax-ymin);
00126 }
00127 
00128 doublec windowscaleD2::heightoverwidth() const
00129 {
00130   assert(xmax-xmin!=0);
00131   return (ymax-ymin)/(xmax-xmin);
00132 }
00133 
00134 
00135 void windowscaleD2::update()
00136 {
00137   oneoverxlength = (double)1.0;
00138   oneoverxlength /= (double)(xmax-xmin);
00139   oneoverylength = (double)1.0;
00140   oneoverylength /= (double)(ymax-ymin);
00141 
00142   assert(oneoverxlength!=0);
00143   assert(oneoverylength!=0);
00144 }
00145 
00146 void windowscaleD2::shiftx(doublec x)
00147 {
00148   xmin += x;
00149   xmax += x;
00150 }
00151 
00152 void windowscaleD2::shifty(doublec x)
00153 {
00154   ymin += x;
00155   ymax += x;
00156 }
00157 
00158 void windowscaleD2::shiftxy(doublec x, doublec y)
00159 {
00160   shiftx(x);
00161   shifty(y);
00162 }
00163 
00164 void windowscaleD2::shiftquadrant1()
00165 {
00166   shiftxy(-xmin,-ymin);
00167 }
00168 
00169 void windowscaleD2::shiftquadrant2()
00170 {
00171   shiftxy(-xmax,-ymin);
00172 }
00173 
00174 void windowscaleD2::shiftquadrant3()
00175 {
00176   shiftxy(-xmax,-ymax);
00177 }
00178 
00179 void windowscaleD2::shiftquadrant4()
00180 {
00181   shiftxy(-xmin,-ymax);
00182 }
00183 
00184 void windowscaleD2::shiftcenterx()
00185 {
00186   double x = (xmax+xmin)*(double)0.5;
00187   shiftx(x);
00188 }
00189 
00190 void windowscaleD2::shiftcentery()
00191 {
00192   double y = (ymax+ymin)*(double)0.5;
00193   shifty(y);
00194 }
00195 
00196 void windowscaleD2::shiftcenterxy()
00197 {
00198   shiftcenterx();
00199   shiftcentery();
00200 }
00201 
00202 void windowscaleD2::scalex(doublec scale)
00203 {
00204   xmin *= scale;
00205   xmax *= scale;
00206 }
00207 
00208 void windowscaleD2::scaley(doublec scale)
00209 {
00210   ymin *= scale;
00211   ymax *= scale;
00212 }
00213 
00214 void windowscaleD2::scalexy(doublec scale)
00215 {
00216   scalex(scale);
00217   scaley(scale);
00218 }
00219 
00220 void windowscaleD2::unitwindow()
00221 {
00222   xmin=0;
00223   xmax=1;
00224   ymin=0;
00225   ymax=1;
00226 
00227   update();
00228 }
00229 
00230 
00231 windowscaleD2::operator stringc () const
00232 {
00233   string s;
00234   string s2;
00235 
00236   stringto(s2,xmin);
00237   s += s2;
00238   s += " ";
00239 
00240   stringto(s2,ymin);
00241   s += s2;
00242   s += " ";
00243 
00244   stringto(s2,xmax);
00245   s += s2;
00246   s += " ";
00247 
00248   stringto(s2,ymax);
00249   s += s2;
00250 
00251   return s;
00252 }
00253 
00254 void windowscaleD2::serializeInverse(stringc & s)
00255 {
00256   stringstream ss(s);
00257   ss >> xmin;
00258   ss >> ymin;
00259   ss >> xmax;
00260   ss >> ymax;
00261 
00262 //cout << SHOW(xmin) << endl;
00263 //cout << SHOW(ymin) << endl;
00264 //cout << SHOW(xmax) << endl;
00265 //cout << SHOW(ymax) << endl;
00266 
00267   update();
00268 }
00269 
00270 boolc windowscaleD2::convertfrom
00271 (
00272   double & x, 
00273   double & y, 
00274   windowscaleD2 const & w2
00275 ) const
00276 {
00277   bool res=true;
00278 
00279   //double x2(x);
00280   //double y2(y);
00281   res &= w2.unitscale(x,y);
00282   unitscaleInverse(x,y);
00283 
00284   return res;
00285 }
00286 

Generated on Fri Mar 4 00:49:27 2011 for Chelton Evans Source by  doxygen 1.5.8