/***********************************************************************
**
**   projectioncylindric.cpp
**
**   This file is part of KFLog2.
**
************************************************************************
**
**   Copyright (c):  2002 by Heiner Lamprecht
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: projectioncylindric.cpp,v 1.12 2004/02/29 21:53:13 hmueller Exp $
**
***********************************************************************/
#include "targets.h"

#include <cmath>
#include "projectioncylindric.h"

// #define NUM_TO_RAD(num) ( ( M_PI * (double)(num) ) / 108000000.0 )
// this sequence is faster
#define NUM_TO_RAD(num) ( M_PI  / 108000000.0 * (double)(num) )

ProjectionCylindric::ProjectionCylindric(double v1_new)
{
  initProjection((int)v1_new);
}

ProjectionCylindric::~ProjectionCylindric()
{

}

bool ProjectionCylindric::initProjection(int v1_new)
{
  bool changed(false);

  if(v1_new > 54000000 || v1_new < -54000000)
    {
      changed = ( v1 != NUM_TO_RAD(27000000) );
      v1 = NUM_TO_RAD(27000000);
      i_v1=27000000;
    }
  else
    {
      changed = ( i_v1 != v1_new );
      v1 = NUM_TO_RAD(v1_new);
      i_v1=v1_new;
    }

  cos_v1=cos(v1);

  return changed;
}

 /**
 * Saves the parameters specific to this projection to a stream
 */
void ProjectionCylindric::saveParameters(QDataStream & s)
{
  s << Q_INT32(i_v1);
}

/**
 * Loads the parameters specific to this projection from a stream
 */
void ProjectionCylindric::loadParameters(QDataStream & s)
{
  Q_INT32 i=0;
  s >> i;
  initProjection(i);
}

/**
  * optimized inline
  *
  * double ProjectionCylindric::projectX(const double& , const double& longitude) const
  * {
  *   return longitude * cos_v1;
  * }
  *
  */


/**
  * optimized inline
  *
  * double ProjectionCylindric::projectY(const double& latitude, const double& ) const
  * {
  * return -latitude;
  * }
  */

/*
double ProjectionCylindric::invertLat(const double& , const double& y) const
{
  return -y;
}

double ProjectionCylindric::invertLon(const double& x, const double& ) const
{
  return x / cos_v1;
}
*/

// We do not rotate the map at all ...
// double ProjectionCylindric::getRotationArc(int , int ) const  {  return 0;  }

/*
int ProjectionCylindric::getTranslationX(const int width, const int x) const
{
  return width / 2 - x;
}

int ProjectionCylindric::getTranslationY(const int height, const int y) const
{
  return (height / 2) - y;
}
*/
