00001
00012 #include "transforms/PeriodicBinaryTransform.h"
00013
00014 using namespace hippodraw;
00015
00021 PeriodicBinaryTransform::PeriodicBinaryTransform() :
00022 BinaryTransform(),
00023 m_x_limits ( -180.0, +180.0 ),
00024 m_y_limits ( - 90.0, + 90.0 ),
00025 m_x_offset ( 0.0 ),
00026 m_y_offset ( 0.0 )
00027 {
00028 }
00029
00030 PeriodicBinaryTransform::PeriodicBinaryTransform ( UnaryTransform * z,
00031 bool is_periodic,
00032 bool needs_grid,
00033 bool needs_x_ticks,
00034 bool needs_y_ticks,
00035 double xlo, double xhi,
00036 double ylo, double yhi) :
00037 BinaryTransform ( z, is_periodic, needs_grid, needs_x_ticks, needs_y_ticks ),
00038 m_x_limits ( xlo, xhi ),
00039 m_y_limits ( ylo, yhi ),
00040 m_x_offset ( 0.0 ),
00041 m_y_offset ( 0.0 )
00042 {
00043 }
00044
00045 PeriodicBinaryTransform::
00046 PeriodicBinaryTransform ( const PeriodicBinaryTransform & t ) :
00047 BinaryTransform ( t ),
00048 m_x_limits( t.limitX() ),
00049 m_y_limits( t.limitY() ),
00050 m_x_offset( t.xOffset() ),
00051 m_y_offset( t.yOffset() )
00052 {
00053 }
00054
00055 PeriodicBinaryTransform::~PeriodicBinaryTransform ()
00056 {
00057
00058 }
00059
00060 const Range & PeriodicBinaryTransform::limitX () const
00061 {
00062 return m_x_limits;
00063 }
00064
00065
00066 const Range & PeriodicBinaryTransform::limitY () const
00067 {
00068 return m_y_limits;
00069 }
00070
00071
00072 double PeriodicBinaryTransform::xOffset() const
00073 {
00074 return m_x_offset;
00075 }
00076
00077 void PeriodicBinaryTransform::setXOffset( double x_offset )
00078 {
00079 m_x_offset = x_offset;
00080 }
00081
00082 double PeriodicBinaryTransform::yOffset() const
00083 {
00084 return m_y_offset;
00085 }
00086
00087 void PeriodicBinaryTransform::setYOffset( double y_offset )
00088 {
00089
00090 m_y_offset = y_offset;
00091 }
00092
00093
00094 double
00095 PeriodicBinaryTransform::
00096 moduloAdd( double a1, double a2, hippodraw::Axes::Type axis ) const
00097 {
00098 if ( axis == Axes::X ) {
00099 return moduloAddX ( a1, a2);
00100 }
00101 else if ( axis == Axes::Y ) {
00102 return moduloAddY ( a1, a2);
00103 }
00104 else return a1 + a2;
00105 }
00106
00107 double
00108 PeriodicBinaryTransform::
00109 moduloSub( double s1, double s2, hippodraw::Axes::Type axis ) const
00110 {
00111 if ( axis == Axes::X ) {
00112 return moduloSubX ( s1, s2);
00113 }
00114 else if ( axis == Axes::Y ) {
00115 return moduloSubY ( s1, s2);
00116 }
00117 else return s1 - s2;
00118 }
00119
00120 double PeriodicBinaryTransform::moduloAddX( double x1, double x2 ) const
00121 {
00122 if ( x2 < -DBL_EPSILON )
00123 return moduloSubX ( x1, -x2 );
00124
00125 double overshoot = x1 + x2 - m_x_limits.high();
00126
00127 if ( overshoot > DBL_EPSILON ) {
00128 return m_x_limits.low() + overshoot;
00129 }
00130 else {
00131 return x1 + x2;
00132 }
00133 }
00134
00135 double PeriodicBinaryTransform::moduloSubX( double x1, double x2 ) const
00136 {
00137 if ( x2 < -DBL_EPSILON )
00138 return moduloAddX ( x1, -x2 );
00139
00140 double undershoot = m_x_limits.low() - ( x1 - x2 );
00141
00142 if ( undershoot > DBL_EPSILON)
00143 return m_x_limits.high() - undershoot;
00144 else
00145 return x1 - x2;
00146 }
00147
00148
00149 double PeriodicBinaryTransform::moduloAddY( double y1, double y2 ) const
00150 {
00151 if ( y2 < -DBL_EPSILON ) return moduloSubY ( y1, -y2 );
00152
00153 double overshoot = y1 + y2 - m_y_limits.high();
00154
00155 if ( overshoot > DBL_EPSILON ) {
00156 return m_y_limits.low() + overshoot;
00157 }
00158 else {
00159 return y1 + y2;
00160 }
00161
00162 }
00163
00164 double PeriodicBinaryTransform::moduloSubY( double y1, double y2 ) const
00165 {
00166 if ( y2 < -DBL_EPSILON ) return moduloAddY ( y1, -y2 );
00167
00168 double undershoot = m_y_limits.low() - ( y1 - y2 );
00169
00170 if ( undershoot > DBL_EPSILON ) return m_y_limits.high() - undershoot;
00171 else return y1 - y2;
00172 }
00173