/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "xfmap_planarequalarea.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Map* pi = new PluginInfo_Map(); pi->name = "Lambert's Azimuthal Equal Area"; pi->author = "Hugo Mills"; pi->copyright = "©2005 Hugo Mills"; pi->version = 0x10000; pi->parser = XfMap_PlanarEqualArea::parser; return pi; } else return NULL; } XfMap* XfMap_PlanarEqualArea::parser(ConfigLexer* lex, const std::string& type, const std::string& subtype ) { if(type == "planar" && subtype == "equal-area" || type == "lambert-equal-area" && subtype == "" || type == "lambert" && subtype == "") { double limit = 180.0; while(!lex->eos()) { if(!readkeyedvalue(lex, "limit", &limit)) throw(UnknownConfigToken(lex)); } return new XfMap_PlanarEqualArea(degrad(limit)); } else return NULL; } bool XfMap_PlanarEqualArea::f(dvec2& result, const dvec3& pos) const { if(acos(pos[2]) > limit) return false; double m = sqrt(2*(1-pos[2]) / (pos[0]*pos[0] + pos[1]*pos[1])) / 2; result[0] = m * pos[0]; result[1] = m * pos[1]; return true; } bool XfMap_PlanarEqualArea::g(dvec3& result, const dvec2& pos) const { double r2 = pos[0]*pos[0] + pos[1]*pos[1]; result[2] = 1-r2*2; if(result[2] < -1 || result[2] > 1 || acos(result[2]) > limit) return false; double m = sqrt(1-r2) * 2; result[0] = m * pos[0]; result[1] = m * pos[1]; return true; }