#include <eAxis.h>
Public Member Functions | |
eAxis (int number=4) | |
~eAxis () | |
int | WindingNumber () const |
int | NearestWinding (eCoord pos) |
eCoord | GetDirection (int winding) |
void | Turn (int ¤tWinding, int direction) |
void | TurnRight (int &direction) |
void | TurnLeft (int &direction) |
Protected Member Functions | |
void | Init (int number) |
void | Init (int number, eCoord predefinedAxis[], bool normalize=true) |
void | ComputeWinding () |
void | ComputeAngles () |
void | SnapWinding () |
push axes that are really close to coordinate directions to them | |
Protected Attributes | |
unsigned int | numberWinding |
eCoord * | windings |
float * | windingAngles |
Friends | |
class | eGrid |
Definition at line 14 of file eAxis.h.
eAxis::eAxis | ( | int | number = 4 |
) |
eAxis::~eAxis | ( | ) |
Definition at line 56 of file eAxis.cpp.
References windingAngles, and windings.
00057 { 00058 if (windings) 00059 delete [] windings; 00060 if (windingAngles) 00061 delete [] windingAngles; // [] not really required as we are dealing with floats, not objects. 00062 }
int eAxis::WindingNumber | ( | ) | const [inline] |
Definition at line 21 of file eAxis.h.
References numberWinding.
Referenced by eGrid::WindingNumber().
00021 {return numberWinding;}
int eAxis::NearestWinding | ( | eCoord | pos | ) |
Definition at line 135 of file eAxis.cpp.
References angledifff(), eCoordToRad, numberWinding, REAL, and windingAngles.
Referenced by eGrid::DirectionWinding().
00136 { 00137 REAL posAngle = eCoordToRad(pos); 00138 00139 REAL closestval = angledifff(windingAngles[0], posAngle); 00140 unsigned int i, closestid = 0; 00141 for(i=1; i<numberWinding; i++) { 00142 REAL diff = angledifff(windingAngles[i], posAngle); 00143 if(diff < closestval) { 00144 closestid = i; 00145 closestval = diff; 00146 } 00147 } 00148 return closestid; 00149 }
eCoord eAxis::GetDirection | ( | int | winding | ) |
Definition at line 151 of file eAxis.cpp.
References numberWinding, and windings.
Referenced by eGrid::GetDirection().
00152 { 00153 winding %= numberWinding; 00154 return windings[winding]; 00155 }
void eAxis::Turn | ( | int & | currentWinding, | |
int | direction | |||
) |
Definition at line 64 of file eAxis.cpp.
References numberWinding.
Referenced by eGrid::Turn().
00065 { 00066 if (direction > 1) direction = 1; 00067 if (direction < -1) direction = -1; 00068 currentWinding += direction + numberWinding; // + numberWinding to avoid any negative. They dont modulate well! 00069 currentWinding %= numberWinding; 00070 }
void eAxis::TurnRight | ( | int & | direction | ) |
Definition at line 72 of file eAxis.cpp.
References numberWinding.
00073 { 00074 windingDirection--; 00075 windingDirection += numberWinding; // + numberWinding to fix negative modulos 00076 windingDirection %= numberWinding; 00077 }
void eAxis::TurnLeft | ( | int & | direction | ) |
Definition at line 79 of file eAxis.cpp.
References numberWinding.
00080 { 00081 windingDirection++; 00082 windingDirection %= numberWinding; 00083 }
void eAxis::Init | ( | int | number | ) | [protected] |
Definition at line 10 of file eAxis.cpp.
References ComputeAngles(), ComputeWinding(), eCoord, numberWinding, REAL, SnapWinding(), windingAngles, and windings.
Referenced by eAxis(), Init(), and eGrid::SetWinding().
00011 { 00012 numberWinding = (number < 1) ? 4 : number; 00013 if (windings) 00014 delete [] windings; 00015 if (windingAngles) 00016 delete [] windingAngles; // [] not really required as we are dealing with floats, not objects. 00017 00018 windings = new eCoord[numberWinding](); 00019 windingAngles = new REAL[numberWinding]; 00020 00021 ComputeWinding(); 00022 SnapWinding(); 00023 ComputeAngles(); 00024 }
void eAxis::Init | ( | int | number, | |
eCoord | predefinedAxis[], | |||
bool | normalize = true | |||
) | [protected] |
Definition at line 26 of file eAxis.cpp.
References ComputeAngles(), eCoord, Init(), NULL, numberWinding, REAL, SnapWinding(), windingAngles, and windings.
00027 { 00028 if ( number < 1 || predefinedAxis == NULL) 00029 { 00030 Init(4); 00031 return; 00032 } 00033 00034 numberWinding = number; 00035 if (windings) 00036 delete [] windings; 00037 if (windingAngles) 00038 delete [] windingAngles; // [] not really required as we are dealing with floats, not objects. 00039 00040 windings = new eCoord[numberWinding](); 00041 windingAngles = new REAL[numberWinding]; 00042 00043 for(int i=0; i<number; i++) 00044 { 00045 windings[i] = predefinedAxis[i]; 00046 if (normalize) { 00047 windings[i].Normalize(); 00048 } 00049 } 00050 00051 SnapWinding(); 00052 ComputeAngles(); 00053 }
void eAxis::ComputeWinding | ( | ) | [protected] |
Definition at line 88 of file eAxis.cpp.
References cosf(), M_PI, numberWinding, REAL, sinf(), and windings.
Referenced by Init().
00089 { 00090 unsigned int i; 00091 REAL tetha; 00092 for(i=0; i<numberWinding; i++) 00093 { 00094 tetha = M_PI*2*(numberWinding - i - 1)/numberWinding; 00095 windings[i].x = (cosf(tetha)); 00096 windings[i].y = (sinf(tetha)); 00097 } 00098 }
void eAxis::ComputeAngles | ( | ) | [protected] |
Definition at line 113 of file eAxis.cpp.
References eCoordToRad, numberWinding, windingAngles, and windings.
Referenced by Init().
00114 { 00115 unsigned int i; 00116 for(i=0; i<numberWinding; i++) 00117 { 00118 windingAngles[i] = eCoordToRad(windings[i]); 00119 } 00120 }
void eAxis::SnapWinding | ( | ) | [protected] |
push axes that are really close to coordinate directions to them
Definition at line 100 of file eAxis.cpp.
References eCoord, EPS, numberWinding, and windings.
Referenced by Init().
00101 { 00102 unsigned int i; 00103 for(i=0; i<numberWinding; i++) 00104 { 00105 eCoord & winding = windings[i]; 00106 if ( fabs(winding.x) < EPS ) 00107 winding.x = 0; 00108 if ( fabs(winding.y) < EPS ) 00109 winding.y = 0; 00110 } 00111 }
unsigned int eAxis::numberWinding [protected] |
Definition at line 33 of file eAxis.h.
Referenced by ComputeAngles(), ComputeWinding(), GetDirection(), Init(), NearestWinding(), SnapWinding(), Turn(), TurnLeft(), TurnRight(), and WindingNumber().
eCoord* eAxis::windings [protected] |
Definition at line 34 of file eAxis.h.
Referenced by ComputeAngles(), ComputeWinding(), eAxis(), GetDirection(), Init(), SnapWinding(), and ~eAxis().
float* eAxis::windingAngles [protected] |
Definition at line 35 of file eAxis.h.
Referenced by ComputeAngles(), eAxis(), Init(), NearestWinding(), and ~eAxis().