/***********************************************************************
**
**   mapcalc.h
**
**   This file is part of KFLog2.
**
************************************************************************
**
**   Copyright (c):  1999, 2000 by Heiner Lamprecht, Florian Ehinger
**
**   This file is distributed under the terms of the General Public
**   Licence. See the file COPYING for more information.
**
**   $Id: mapcalc.h,v 1.14 2004/02/29 16:24:31 hmueller Exp $
**
***********************************************************************/

#ifndef MAPCALC_H
#define MAPCALC_H

#include "wp.h"
#include <qrect.h>

#define PI2 M_PI*2

/**
 * The earth's radius used for calculation, given in Meter.
 * NOTE: We use the earth as a sphere, not as a spheroid!
 */
#define RADIUS 6370290 //6370289.509
#define RADIUS_kfl 0.02949208 // = RADIUS / 360 * 600000

/**
 * Calculates the distance between two given points (in km).
 */
double dist(double lat1, double lon1, double lat2, double lon2);

/**
 * Calculates the distance between two given points (in km).
 */
double dist(QPoint* p1, QPoint* p2);

/**
 * Calculates the distance between two given points (in km).
 */
double dist(wayPoint* wp1, wayPoint* wp2);

/**
 * Calculates the distance between two given points (in km).
 */
double dist(wayPoint* wp, flightPoint* fp);

/**
 * Calculates the distance between two given points (in km).
 */
double dist( flightPoint* fp1, flightPoint* fp2);

/**
 * Converts the given time (in sec.) into a readable string.
 * ( hh:mm:ss )
 */
QString printTime(int time, bool isZero = false, bool isSecond = true);

/**
 * Calculates the vario of a given point
 */
float getVario(flightPoint p);

/**
 * Calculates the speed of a given point
 */
float getSpeed(flightPoint p);

/**
 * Calculates the bearing to the previous point
 */
float getBearing(flightPoint p1, flightPoint p2);

/**
 * Calculates the bearing to the next point
 */
float getBearing(QPoint p1, QPoint p2);

/**
 * Converts a x/y position into a polar-coordinate.
 */
double polar(double y, double x);

/**
 * Calculates the direction of the vector pointing to the outside
 * of the area spanned by the two vectors.
 */
double outsideVector(QPoint center, QPoint p1, QPoint p2);

double normalize(double angle);

int normalize(int angle);

/**
  * Calculates the difference between two angles, returning the smallest
  * angle. It returns an angle between -180 and 180 in degrees. Positive
  * in clockwise direction.
  */
int angleDiff(int ang1, int ang2);

/**
  * Calculates the difference between two angles, returning the smallest
  * angle. It returns an angle between -Pi and Pi in rad.
  */
double angleDiff(double ang1, double ang2);

/**
 * Calculates a (crude) bounding box that contains the circle of radius @arg r
 * around point @arg center. @arg r is given in kilometers.
 */
QRect areaBox(QPoint center, double r);
#endif
