/******************************************************************************
 * Copyright 2020 The siasun Transport Authors. All Rights Reserved.
 * Author: madesheng
 * Licensed under the Apache License, Version 1.0 (the "License");
 *****************************************************************************/

/**
* @file
*/

#ifndef ROBOT_ROBOT_COORDCONVERTION_H_
#define ROBOT_ROBOT_COORDCONVERTION_H_

#include "localizationdata.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>

/**
* @namespace robot::localization
* @brief robot::localization
*/
namespace robot {
namespace localizationspace {


class CoordsConvertion
{
public:

    /**
     * Utility function to convert geodetic to UTM position
     *
     * Units in are floating point degrees (sign for east/west)
     *
     * Units out are meters
     */
    static void UTM(double lat, double lon, double *x, double *y);


    /**
     * Determine the correct UTM letter designator for the
     * given latitude
     *
     * @returns 'Z' if latitude is outside the UTM limits of 84N to 80S
     *
     */
    static char UTMLetterDesignator(double Lat);

    /**
     * Convert lat/long to UTM coords.  Equations from USGS Bulletin 1532
     *
     * East Longitudes are positive, West longitudes are negative.
     * North latitudes are positive, South latitudes are negative
     * Lat and Long are in fractional degrees
     *
     */
    static void LLtoUTM(const double Lat, const double Long,
                               double &UTMNorthing, double &UTMEasting,
                               char* UTMZone);


    static void LLtoUTM(const double Lat, const double Long,
                              double &UTMNorthing, double &UTMEasting,
                              std::string &UTMZone);

    /**
     * Converts UTM coords to lat/long.  Equations from USGS Bulletin 1532
     *
     * East Longitudes are positive, West longitudes are negative.
     * North latitudes are positive, South latitudes are negative
     * Lat and Long are in fractional degrees.
     *
     */
    static void UTMtoLL(const double UTMNorthing, const double UTMEasting,
                               const char* UTMZone, double& Lat,  double& Long );

    static void UTMtoLL(const double UTMNorthing, const double UTMEasting,
        std::string UTMZone, double& Lat, double& Long);

};

}  // namespace localization
}  // namespace robot


#endif  // ROBOT_ROBOT_COORDCONVERTION_H_
