#ifndef ELLIPSOID_H
#define ELLIPSOID_H

#include <cmath>
#include <QString>
#include <QMap>
#include <QDebug>

class Ellipsoid
{
public:
	Ellipsoid()
	  : _radius(NAN), _flattening(NAN), _es(NAN), _e2s(NAN), _b(NAN) {}
	Ellipsoid(double radius, double flattening);

	bool operator==(const Ellipsoid &other) const
	{
		return (fabs(_radius - other._radius) < 1e-3
		  && fabs(_flattening - other._flattening) < 1e-12);
	}

	double radius() const {return _radius;}
	double flattening() const {return _flattening;}
	double es() const {return _es;}
	double e2s() const {return _e2s;}
	double b() const {return _b;}

	bool isNull() const
	  {return (std::isnan(_radius) && std::isnan(_flattening));}
	bool isValid() const
	  {return !(std::isnan(_radius) || std::isnan(_flattening));}

	static const Ellipsoid &WGS84();
	static const Ellipsoid &GRS80();
	static const Ellipsoid &ellipsoid(int id);
	static bool loadList(const QString &path);

private:
	double _radius;
	double _flattening;
	double _es, _e2s, _b;

	static QMap<int, Ellipsoid> defaults();
	static QMap<int, Ellipsoid> _ellipsoids;
};

#ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Ellipsoid &ellipsoid);
#endif // QT_NO_DEBUG

#endif // ELLIPSOID_H
