proj home

Files   Classes   Functions   Hierarchy  

windowscaleD2 Class Reference

Support. More...

#include <windowscaleD2.h>

Collaboration diagram for windowscaleD2:

List of all members.

Public Member Functions

 windowscaleD2 ()
 Construct in a bad state.
 windowscaleD2 (doublec xmin_, doublec xmax_, doublec ymin_, doublec ymax_)
 Create the window.
void construct (doublec xmin_, doublec xmax_, doublec ymin_, doublec ymax_)
 Create the window.
doublec widthoverheight () const
 Get the width divided by height ratio.
doublec heightoverwidth () const
 Get the height divided by width ratio.
boolc isinside (doublec x, doublec y) const
 Is the point inside the box?
void update ()
 Recalculate after changes to window dimensions.
boolc convertfrom (double &x, double &y, windowscaleD2 const &w2) const
 Convert (x,y) from other window to this one.
boolc unitscale (double &x, double &y) const
 Converts to ratio point in S to S'.
void unitscaleInverse (double &x, double &y) const
 Converts the ratio point in S' to S.
void unitscaleInverse_x (double &x) const
 Convert from ratio in x-axis only.
void unitscaleInverse_y (double &y) const
 Convert from ratio in y-axis only.
void shiftx (doublec x)
 Translate the window in the X-axis.
void shifty (doublec y)
 Translate the window in the Y-axis.
void shiftxy (doublec x, doublec y)
 Translate the window in the X and Y axes.
void shiftquadrant1 ()
 Move the window so bottom left of the window is at the origin.
void shiftquadrant2 ()
 Move the window so bottom right of the window is at the origin.
void shiftquadrant3 ()
 Move the window so top right of the window is at the origin.
void shiftquadrant4 ()
 Move the window so top left of the window is at the origin.
void shiftcenterx ()
 Center the window in the X-axis.
void shiftcentery ()
 Center the window in the Y-axis.
void shiftcenterxy ()
 Center the window in the X and Y axes.
void scalex (doublec scale)
 Multiply xmin, xmax by scale.
void scaley (doublec scale)
 Multiply ymin, ymax by scale.
void scalexy (doublec scale)
 Multiply xmin, xmax, ymin, ymax by scale.
 operator stringc () const
 Serialize this object by writing it out as a string.
void serializeInverse (stringc &s)
 Construct object from a string.
void unitwindow ()
 (0,0) (1,1)

Public Attributes

double xmin
 x left
double ymin
 y bottom
double xmax
 x right
double ymax
 y top
double oneoverxlength
 1/(xmax-xmin)
double oneoverylength
 1/(ymax-ymin)

Static Public Attributes

static windowscaleD2 unit
 Unit window at 1st quadrant.
static windowscaleD2 unitcentered
 Unit window with center at origin.


Detailed Description

Support.

Let S be the coordinate space. Let S' be the same space scaled: (xmin,ymin) to (0,0). (xmax,ymax) to (1,1).

Definition at line 22 of file windowscaleD2.h.


Constructor & Destructor Documentation

windowscaleD2::windowscaleD2 (  ) 

Construct in a bad state.

Definition at line 13 of file windowscaleD2.cpp.

00014 {
00015 }

windowscaleD2::windowscaleD2 ( doublec  xmin_,
doublec  xmax_,
doublec  ymin_,
doublec  ymax_ 
)

Create the window.

Definition at line 34 of file windowscaleD2.cpp.

00040   : xmin(xmin_), ymin(ymin_), xmax(xmax_), ymax(ymax_)
00041 {
00042   update();
00043 }


Member Function Documentation

void windowscaleD2::construct ( doublec  xmin_,
doublec  xmax_,
doublec  ymin_,
doublec  ymax_ 
)

Create the window.

Definition at line 18 of file windowscaleD2.cpp.

00024 {
00025   xmin=xmin_;
00026   ymin=ymin_;
00027   xmax=xmax_;
00028   ymax=ymax_;
00029 
00030   update();
00031 }

boolc windowscaleD2::convertfrom ( double &  x,
double &  y,
windowscaleD2 const &  w2 
) const

Convert (x,y) from other window to this one.

Definition at line 271 of file windowscaleD2.cpp.

References unitscale().

Referenced by pointsgraph::draw(), and windowscaleD2test::test001().

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 }

doublec windowscaleD2::heightoverwidth (  )  const

Get the height divided by width ratio.

Definition at line 128 of file windowscaleD2.cpp.

References xmax, xmin, ymax, and ymin.

00129 {
00130   assert(xmax-xmin!=0);
00131   return (ymax-ymin)/(xmax-xmin);
00132 }

boolc windowscaleD2::isinside ( doublec  x,
doublec  y 
) const

Is the point inside the box?

Definition at line 104 of file windowscaleD2.cpp.

References xmax, xmin, ymax, and ymin.

Referenced by pointsgraph::draw(), and windowscaleD2test::test001().

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 }

windowscaleD2::operator stringc (  )  const

Serialize this object by writing it out as a string.

Definition at line 231 of file windowscaleD2.cpp.

References stringto(), xmax, xmin, ymax, and ymin.

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 }

void windowscaleD2::scalex ( doublec  scale  ) 

Multiply xmin, xmax by scale.

Definition at line 202 of file windowscaleD2.cpp.

References xmax, and xmin.

Referenced by scalexy().

00203 {
00204   xmin *= scale;
00205   xmax *= scale;
00206 }

void windowscaleD2::scalexy ( doublec  scale  ) 

Multiply xmin, xmax, ymin, ymax by scale.

Definition at line 214 of file windowscaleD2.cpp.

References scalex(), and scaley().

Referenced by windowscaleD2test::test001().

00215 {
00216   scalex(scale);
00217   scaley(scale);
00218 }

void windowscaleD2::scaley ( doublec  scale  ) 

Multiply ymin, ymax by scale.

Definition at line 208 of file windowscaleD2.cpp.

References ymax, and ymin.

Referenced by scalexy().

00209 {
00210   ymin *= scale;
00211   ymax *= scale;
00212 }

void windowscaleD2::serializeInverse ( stringc s  ) 

Construct object from a string.

Definition at line 254 of file windowscaleD2.cpp.

References update(), xmax, xmin, ymax, and ymin.

Referenced by windowscaleD2test::test001().

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 }

void windowscaleD2::shiftcenterx (  ) 

Center the window in the X-axis.

Definition at line 184 of file windowscaleD2.cpp.

References shiftx(), xmax, and xmin.

Referenced by shiftcenterxy().

00185 {
00186   double x = (xmax+xmin)*(double)0.5;
00187   shiftx(x);
00188 }

void windowscaleD2::shiftcenterxy (  ) 

Center the window in the X and Y axes.

Definition at line 196 of file windowscaleD2.cpp.

References shiftcenterx(), and shiftcentery().

00197 {
00198   shiftcenterx();
00199   shiftcentery();
00200 }

void windowscaleD2::shiftcentery (  ) 

Center the window in the Y-axis.

Definition at line 190 of file windowscaleD2.cpp.

References shifty(), ymax, and ymin.

Referenced by shiftcenterxy().

00191 {
00192   double y = (ymax+ymin)*(double)0.5;
00193   shifty(y);
00194 }

void windowscaleD2::shiftquadrant1 (  ) 

Move the window so bottom left of the window is at the origin.

Definition at line 164 of file windowscaleD2.cpp.

References shiftxy(), xmin, and ymin.

00165 {
00166   shiftxy(-xmin,-ymin);
00167 }

void windowscaleD2::shiftquadrant2 (  ) 

Move the window so bottom right of the window is at the origin.

Definition at line 169 of file windowscaleD2.cpp.

References shiftxy(), xmax, and ymin.

00170 {
00171   shiftxy(-xmax,-ymin);
00172 }

void windowscaleD2::shiftquadrant3 (  ) 

Move the window so top right of the window is at the origin.

Definition at line 174 of file windowscaleD2.cpp.

References shiftxy(), xmax, and ymax.

00175 {
00176   shiftxy(-xmax,-ymax);
00177 }

void windowscaleD2::shiftquadrant4 (  ) 

Move the window so top left of the window is at the origin.

Definition at line 179 of file windowscaleD2.cpp.

References shiftxy(), xmin, and ymax.

00180 {
00181   shiftxy(-xmin,-ymax);
00182 }

void windowscaleD2::shiftx ( doublec  x  ) 

Translate the window in the X-axis.

Definition at line 146 of file windowscaleD2.cpp.

References xmax, and xmin.

Referenced by shiftcenterx(), and shiftxy().

00147 {
00148   xmin += x;
00149   xmax += x;
00150 }

void windowscaleD2::shiftxy ( doublec  x,
doublec  y 
)

Translate the window in the X and Y axes.

Definition at line 158 of file windowscaleD2.cpp.

References shiftx(), and shifty().

Referenced by shiftquadrant1(), shiftquadrant2(), shiftquadrant3(), shiftquadrant4(), and windowscaleD2test::test002().

00159 {
00160   shiftx(x);
00161   shifty(y);
00162 }

void windowscaleD2::shifty ( doublec  y  ) 

Translate the window in the Y-axis.

Definition at line 152 of file windowscaleD2.cpp.

References ymax, and ymin.

Referenced by shiftcentery(), and shiftxy().

00153 {
00154   ymin += x;
00155   ymax += x;
00156 }

boolc windowscaleD2::unitscale ( double &  x,
double &  y 
) const

Converts to ratio point in S to S'.

Definition at line 47 of file windowscaleD2.cpp.

References oneoverxlength, oneoverylength, xmin, and ymin.

Referenced by convertfrom().

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 }

void windowscaleD2::unitscaleInverse ( double &  x,
double &  y 
) const

Converts the ratio point in S' to S.

Definition at line 87 of file windowscaleD2.cpp.

References xmax, xmin, ymax, and ymin.

00088 {
00089   x = (xmax-xmin)*x + xmin;
00090   y = (ymax-ymin)*y + ymin;
00091 }

void windowscaleD2::unitscaleInverse_x ( double &  x  )  const

Convert from ratio in x-axis only.

Definition at line 93 of file windowscaleD2.cpp.

References xmax, and xmin.

Referenced by pointsgraph::samplefunction().

00094 {
00095   x = (xmax-xmin)*x + xmin;
00096 }

void windowscaleD2::unitscaleInverse_y ( double &  y  )  const

Convert from ratio in y-axis only.

Definition at line 98 of file windowscaleD2.cpp.

References ymax, and ymin.

00099 {
00100   y = (ymax-ymin)*y + ymin;
00101 }

void windowscaleD2::unitwindow (  ) 

(0,0) (1,1)

Definition at line 220 of file windowscaleD2.cpp.

References update(), xmax, xmin, ymax, and ymin.

Referenced by windowscaleD2test::test001().

00221 {
00222   xmin=0;
00223   xmax=1;
00224   ymin=0;
00225   ymax=1;
00226 
00227   update();
00228 }

void windowscaleD2::update (  ) 

Recalculate after changes to window dimensions.

Definition at line 135 of file windowscaleD2.cpp.

References oneoverxlength, oneoverylength, xmax, xmin, ymax, and ymin.

Referenced by pointsgraph::domain(), pointsgraph::screen_rescaley(), serializeInverse(), unitwindow(), and pointsgraph::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 }

doublec windowscaleD2::widthoverheight (  )  const

Get the width divided by height ratio.

Definition at line 122 of file windowscaleD2.cpp.

References xmax, xmin, ymax, and ymin.

00123 {
00124   assert(ymax-ymin!=0);
00125   return (xmax-xmin)/(ymax-ymin);
00126 }


Member Data Documentation

1/(xmax-xmin)

Definition at line 63 of file windowscaleD2.h.

Referenced by unitscale(), and update().

1/(ymax-ymin)

Definition at line 65 of file windowscaleD2.h.

Referenced by unitscale(), and update().

Unit window at 1st quadrant.

Definition at line 27 of file windowscaleD2.h.

Unit window with center at origin.

Definition at line 30 of file windowscaleD2.h.

Referenced by windowscaleD2test::test001().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:25 2011 for Chelton Evans Source by  doxygen 1.5.8