/* -*- 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_planarequidistant.h" extern "C" PluginInfo* getmodules(int i) { if(i==0) { PluginInfo_Map* pi = new PluginInfo_Map(); pi->name = "Planar Equidistant"; pi->author = "Hugo Mills"; pi->copyright = "©2005 Hugo Mills"; pi->version = 0x10000; pi->parser = XfMap_PlanarEquidistant::parser; return pi; } else return NULL; } XfMap* XfMap_PlanarEquidistant::parser( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { if(type != "planar") return NULL; if(subtype != "equidistant") return NULL; double limit = 180.0; while(!lex->eos()) { if(!readkeyedvalue(lex, "limit", &limit)) throw(UnknownConfigToken(lex)); } return new XfMap_PlanarEquidistant(degrad(limit)); } bool XfMap_PlanarEquidistant::f(dvec2& result, const dvec3& pos) const { double r = acos(pos[2]); if(r > limit) return false; double xyr = sqrt(pos[0]*pos[0] + pos[1]*pos[1]); double m = r / xyr / M_PI; result[0] = m * pos[0]; result[1] = m * pos[1]; return true; } bool XfMap_PlanarEquidistant::g(dvec3& result, const dvec2& pos) const { double r = sqrt(pos[0]*pos[0] + pos[1]*pos[1]); if(r * M_PI > limit) return false; result[2] = cos(r * M_PI); double z2 = sqrt(1-result[2]*result[2]); double m; if(r == 0.0) m = 0; else m = z2 / r; result[0] = m * pos[0]; result[1] = m * pos[1]; return true; }